Skip to content

Commit 7b27a2f

Browse files
committed
Make "frame" spans go on a separate trace line than others
"frame" spans indicate stack frames in the interpreted program
1 parent 6acaee8 commit 7b27a2f

File tree

1 file changed

+23
-18
lines changed

1 file changed

+23
-18
lines changed

src/bin/log/tracing_chrome.rs

Lines changed: 23 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// SPDX-License-Identifier: MIT
22
// SPDX-FileCopyrightText: Copyright (c) 2020 Thoren Paulson
3-
//! This file is taken unmodified from the following link, except for file attributes and
4-
//! `extern crate` at the top.
3+
//! This file was initially taken from the following link, the changes that were made to the
4+
//! original file can be found in git history (`git log -- path/to/tracing_chrome.rs`):
55
//! https://github.com/thoren-d/tracing-chrome/blob/7e2625ab4aeeef2f0ef9bde9d6258dd181c04472/src/lib.rs
66
//! Depending on the tracing-chrome crate from crates.io is unfortunately not possible, since it
77
//! depends on `tracing_core` which conflicts with rustc_private's `tracing_core` (meaning it would
@@ -497,31 +497,36 @@ where
497497
}
498498
}
499499

500-
fn get_root_id(span: SpanRef<S>) -> u64 {
501-
span.scope()
502-
.from_root()
503-
.take(1)
504-
.next()
505-
.unwrap_or(span)
506-
.id()
507-
.into_u64()
500+
fn get_root_id(&self, span: SpanRef<S>) -> Option<u64> {
501+
match self.trace_style {
502+
TraceStyle::Async => Some(
503+
span.scope()
504+
.from_root()
505+
.take(1)
506+
.next()
507+
.unwrap_or(span)
508+
.id()
509+
.into_u64()
510+
),
511+
_ => if span.metadata().name() == "frame" {
512+
// "frame" spans indicate stack frames in the interpreted program:
513+
// let's make them appear on a separate trace line than other spans.
514+
Some(1)
515+
} else {
516+
None
517+
},
518+
}
508519
}
509520

510521
fn enter_span(&self, span: SpanRef<S>, ts: f64) {
511522
let callsite = self.get_callsite(EventOrSpan::Span(&span));
512-
let root_id = match self.trace_style {
513-
TraceStyle::Async => Some(ChromeLayer::get_root_id(span)),
514-
_ => None,
515-
};
523+
let root_id = self.get_root_id(span);
516524
self.send_message(Message::Enter(ts, callsite, root_id));
517525
}
518526

519527
fn exit_span(&self, span: SpanRef<S>, ts: f64) {
520528
let callsite = self.get_callsite(EventOrSpan::Span(&span));
521-
let root_id = match self.trace_style {
522-
TraceStyle::Async => Some(ChromeLayer::get_root_id(span)),
523-
_ => None,
524-
};
529+
let root_id = self.get_root_id(span);
525530
self.send_message(Message::Exit(ts, callsite, root_id));
526531
}
527532

0 commit comments

Comments
 (0)