-
-
Notifications
You must be signed in to change notification settings - Fork 2.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Implement minimal (metrics-only) taskdumps. #5466
Conversation
This is the first commit in a series that will bring "task dumps" to Tokio. This commit adds the "taskdump" Cargo feature, important dependencies, and fixes inference issues introduced by the introduction of `serde_json` (see @rust-lang/rust#46257).
Introduces an API for dumping information about a runtime as JSON. This initial implementation does not yet include any information about tasks; only metrics.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think that some of the concepts here require further discussion before continuing. Probably worth continuing on the original issue and/or on Discord before adding too much more.
@@ -85,6 +85,10 @@ signal = [ | |||
"windows-sys/Win32_System_Console", | |||
] | |||
sync = [] | |||
taskdump = [ | |||
"serde", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Even allowing that this would be an opt-in feature, adding serde
and serde_json
seems like a fairly large addition to tokio's dependencies.
/// Display-formatting a `Handle` produces a JSON dump of the runtime's internal state. | ||
/// | ||
/// This feature is in very early development, and its API and output is subject to change. | ||
impl fmt::Display for Handle { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was already brought up on the feature proposal issue (#5457), but I'll add it here too.
I feel that performing excessive work inside the Display trait violates the consistency principal (principal of least surprise). My opinion (and so it is just that) is that most users would expect adding a Handle
to some println!()
call to be "harmless", and I don't think serializing the state of the runtime can be classed as such.
Is this a task dump API or a metrics API? IIRC tokio already has the ability to emit these metrics. |
@sfackler My goal with this initial PR is to pin down the taskdump API and to touch as little of Tokio's internals as possible. Indeed, the reason this only includes metrics now is because Tokio already has an API for metrics. Once we settle on a satisfactory API for task dumps, I'll submit follow-up PRs that include incrementally increasing information about tasks. |
But why would we want this API to report metrics in the first place? If you just want to add the method, it may as well just return an empty JSON object or something. |
My goal is to surface as much important information from Tokio's internals as is possible without introducing new runtime costs. Runtime metrics are readily (and cheaply) available already. They even might be helpful for debugging. I couldn't see a reason not to include them. Additionally, the goal of this PR is to lay the groundwork for future PRs. There are three components to it: the public API, the serialization mechanism, and the testing approach. Returning |
As discussed privately, the initial task dump PR will use a different implementation. I will close this. Go ahead and open a new PR when your changes are ready. |
This PR is the first in a series implementing the task dump feature proposal (#5457). This initial implementation includes only runtime metrics; e.g.:
Implementation Details
This PR internally uses
serde
to provide flexible serialization of runtime internals. For testing, theschemars
dev-dependency is used to generate a JSON schema against which task dumps can be validated (withjsonschema
).API
Before merging this PR, we should settle on an API for task dumps. Possibilities include:
or
or
or something else? Suggestions welcome! My hope is we provide a streamlined API that can be used for serializing JSON task dumps to stdout or files. This streamlined API should co-exist with a possible future, more expansive API that provides options to skip traversing certain runtime structures and the option to serialize into other formats.