tokio-rs / tracing

Application level tracing for Rust.
https://tracing.rs
MIT License
5.53k stars 726 forks source link

tracing-subscriber: refactor timings #3038

Open joshka opened 4 months ago

joshka commented 4 months ago

Motivation

This makes the fmt::Subscriber code a bit simpler, and preps the Timing type for lifting elsewhere (e.g. to be made public and part of a timing layer instead of hidden within this Subscriber) (see https://github.com/tokio-rs/tracing/issues/2946)

Solution

This commit refactors the Timings struct to use Duration instead of u64 to store the idle and busy times of a span, and moves the logic to update the timings to the Timings struct itself. This commit also introduces a display method to the Timings struct that returns the idle and busy times as HumanReadableDuration instances (renamed from TimingDisplay).

Replaces: https://github.com/tokio-rs/tracing/pull/2944

joshka commented 4 months ago

What about renaming this to SpanTimings instead of Timings? It's currently private, so this isn't breaking.

Side note: My personal style would be to move this to its own small module, as it's a neatly self contained piece that doesn't depend on other parts of the library. I like using modules to reduce the cognitive load of reading larger source files, but I don't know how this squares with the library maintainers, and everyone has different preferences on what sizes matter.