diff options
| author | Stypox <stypox@pm.me> | 2025-07-22 13:43:30 +0200 |
|---|---|---|
| committer | Stypox <stypox@pm.me> | 2025-07-25 09:22:19 +0200 |
| commit | 2a81b4fad6bc5d089808d10cd880de040339cea6 (patch) | |
| tree | 66b44cc9cceae44d0d5033dcfd1e20c38d2023da | |
| parent | 7a8288bce479b12f489a2b66b5cee1dfc6ff2e07 (diff) | |
| download | rust-2a81b4fad6bc5d089808d10cd880de040339cea6.tar.gz rust-2a81b4fad6bc5d089808d10cd880de040339cea6.zip | |
Use i64 for tracing chrome "id"
Perfetto gives an error if an id does not fit in an 64-bit signed integer in 2's complement.
| -rw-r--r-- | src/tools/miri/src/bin/log/tracing_chrome.rs | 13 |
1 files changed, 9 insertions, 4 deletions
diff --git a/src/tools/miri/src/bin/log/tracing_chrome.rs b/src/tools/miri/src/bin/log/tracing_chrome.rs index 5a96633c99e..3379816550c 100644 --- a/src/tools/miri/src/bin/log/tracing_chrome.rs +++ b/src/tools/miri/src/bin/log/tracing_chrome.rs @@ -12,6 +12,7 @@ //! ```rust //! tracing::info_span!("my_span", tracing_separate_thread = tracing::field::Empty, /* ... */) //! ``` +//! - use i64 instead of u64 for the "id" in [ChromeLayer::get_root_id] to be compatible with Perfetto //! //! Depending on the tracing-chrome crate from crates.io is unfortunately not possible, since it //! depends on `tracing_core` which conflicts with rustc_private's `tracing_core` (meaning it would @@ -285,9 +286,9 @@ struct Callsite { } enum Message { - Enter(f64, Callsite, Option<u64>), + Enter(f64, Callsite, Option<i64>), Event(f64, Callsite), - Exit(f64, Callsite, Option<u64>), + Exit(f64, Callsite, Option<i64>), NewThread(usize, String), Flush, Drop, @@ -519,14 +520,17 @@ where } } - fn get_root_id(&self, span: SpanRef<S>) -> Option<u64> { + fn get_root_id(&self, span: SpanRef<S>) -> Option<i64> { + // Returns `Option<i64>` instead of `Option<u64>` because apparently Perfetto gives an + // error if an id does not fit in a 64-bit signed integer in 2's complement. We cast the + // span id from `u64` to `i64` with wraparound, since negative values are fine. match self.trace_style { TraceStyle::Threaded => { if span.fields().field("tracing_separate_thread").is_some() { // assign an independent "id" to spans with argument "tracing_separate_thread", // so they appear a separate trace line in trace visualization tools, see // https://docs.google.com/document/d/1CvAClvFfyA5R-PhYUmn5OOQtYMH4h6I0nSsKchNAySU/preview#heading=h.jh64i9l3vwa1 - Some(span.id().into_u64()) + Some(span.id().into_u64().cast_signed()) // the comment above explains the cast } else { None } @@ -539,6 +543,7 @@ where .unwrap_or(span) .id() .into_u64() + .cast_signed() // the comment above explains the cast ), } } |
