about summary refs log tree commit diff
diff options
context:
space:
mode:
authorRalf Jung <post@ralfj.de>2025-07-25 07:55:42 +0000
committerGitHub <noreply@github.com>2025-07-25 07:55:42 +0000
commit529564925bf67a69fb4a5ef4f87ba7ae4aaed84b (patch)
tree4fe4752c5e01a13982270c22630cd2cd1380cd8e
parentdd96ec6553596f8af3208693f7c9543367df3d34 (diff)
parentc7b81f38f8f5dee79be0fbddfba551eea3f98bf8 (diff)
downloadrust-529564925bf67a69fb4a5ef4f87ba7ae4aaed84b.tar.gz
rust-529564925bf67a69fb4a5ef4f87ba7ae4aaed84b.zip
Merge pull request #4489 from Stypox/misc-tracing-fixes
Miscellaneous fixes for tracing
-rw-r--r--src/tools/miri/src/bin/log/setup.rs2
-rw-r--r--src/tools/miri/src/bin/log/tracing_chrome.rs13
-rw-r--r--src/tools/miri/src/helpers.rs2
3 files changed, 11 insertions, 6 deletions
diff --git a/src/tools/miri/src/bin/log/setup.rs b/src/tools/miri/src/bin/log/setup.rs
index da0ba528b2c..a9392d010f8 100644
--- a/src/tools/miri/src/bin/log/setup.rs
+++ b/src/tools/miri/src/bin/log/setup.rs
@@ -60,7 +60,7 @@ fn init_logger_once(early_dcx: &EarlyDiagCtxt) {
             #[cfg(not(feature = "tracing"))]
             {
                 crate::fatal_error!(
-                    "fatal error: cannot enable MIRI_TRACING since Miri was not built with the \"tracing\" feature"
+                    "Cannot enable MIRI_TRACING since Miri was not built with the \"tracing\" feature"
                 );
             }
 
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
             ),
         }
     }
diff --git a/src/tools/miri/src/helpers.rs b/src/tools/miri/src/helpers.rs
index ccfff7fa94b..6e80bc5da9e 100644
--- a/src/tools/miri/src/helpers.rs
+++ b/src/tools/miri/src/helpers.rs
@@ -1465,7 +1465,7 @@ pub struct MaybeEnteredTraceSpan {
 #[macro_export]
 macro_rules! enter_trace_span {
     ($name:ident :: $subname:ident $($tt:tt)*) => {{
-        enter_trace_span!(stringify!($name), $name = %stringify!(subname) $($tt)*)
+        enter_trace_span!(stringify!($name), $name = %stringify!($subname) $($tt)*)
     }};
 
     ($($tt:tt)*) => {