@@ -53,12 +53,63 @@ pub trait EnteredTraceSpan {}
53
53
impl EnteredTraceSpan for ( ) { }
54
54
impl EnteredTraceSpan for tracing:: span:: EnteredSpan { }
55
55
56
- /// Shortand for calling [crate::interpret::Machine::enter_trace_span] on a [tracing::info_span].
56
+ /// Shortand for calling [crate::interpret::Machine::enter_trace_span] on a [tracing::info_span! ].
57
57
/// This is supposed to be compiled out when [crate::interpret::Machine::enter_trace_span] has the
58
58
/// default implementation (i.e. when it does not actually enter the span but instead returns `()`).
59
+ /// This macro takes a type implementing the [crate::interpret::Machine] trait as its first argument
60
+ /// and otherwise accepts the same syntax as [tracing::span!] (see some tips below).
59
61
/// Note: the result of this macro **must be used** because the span is exited when it's dropped.
62
+ ///
63
+ /// ### Syntax accepted by this macro
64
+ ///
65
+ /// The full documentation for the [tracing::span!] syntax can be found at [tracing] under "Using the
66
+ /// Macros". A few possibly confusing syntaxes are listed here:
67
+ /// ```rust
68
+ /// // logs a span named "hello" with a field named "arg" of value 42 (works only because
69
+ /// // 42 implements the tracing::Value trait, otherwise use one of the options below)
70
+ /// let _span = enter_trace_span!(M, "hello", arg = 42);
71
+ /// // logs a field called "my_display_var" using the Display implementation
72
+ /// let _span = enter_trace_span!(M, "hello", %my_display_var);
73
+ /// // logs a field called "my_debug_var" using the Debug implementation
74
+ /// let _span = enter_trace_span!(M, "hello", ?my_debug_var);
75
+ /// ```
76
+ ///
77
+ /// ### `NAME::SUBNAME` syntax
78
+ ///
79
+ /// In addition to the syntax accepted by [tracing::span!], this macro optionally allows passing
80
+ /// the span name (i.e. the first macro argument) in the form `NAME::SUBNAME` (without quotes) to
81
+ /// indicate that the span has name "NAME" (usually the name of the component) and has an additional
82
+ /// more specific name "SUBNAME" (usually the function name). The latter is passed to the [tracing]
83
+ /// infrastructure as a span field with the name "NAME". This allows not being distracted by
84
+ /// subnames when looking at the trace in <https://ui.perfetto.dev>, but when deeper introspection
85
+ /// is needed within a component, it's still possible to view the subnames directly in the UI by
86
+ /// selecting a span, clicking on the "NAME" argument on the right, and clicking on "Visualize
87
+ /// argument values".
88
+ /// ```rust
89
+ /// // for example, the first will expand to the second
90
+ /// let _span = enter_trace_span!(M, borrow_tracker::on_stack_pop, /* ... */)
91
+ /// let _span = enter_trace_span!(M, "borrow_tracker", borrow_tracker = "on_stack_pop", /* ... */)
92
+ /// ```
93
+ ///
94
+ /// ### `tracing_separate_thread` parameter
95
+ ///
96
+ /// This macro was introduced to obtain better traces of Miri without impacting release performance.
97
+ /// Miri saves traces using the the `tracing_chrome` [tracing::Layer] so that they can be visualized
98
+ /// in <https://ui.perfetto.dev>. To instruct `tracing_chrome` to put some spans on a separate trace
99
+ /// thread/line than other spans when viewed in <https://ui.perfetto.dev>, you can pass
100
+ /// `tracing_separate_thread = tracing::field::Empty` to the tracing macros. This is useful to
101
+ /// separate out spans which just indicate the current step or program frame being processed by the
102
+ /// interpreter. You should use a value of [tracing::field::Empty] so that other tracing layers
103
+ /// (e.g. the logger) will ignore the `tracing_separate_thread` field. For example:
104
+ /// ```rust
105
+ /// let _span = enter_trace_span!(M, step::eval_statement, tracing_separate_thread = tracing::field::Empty)
106
+ /// ```
60
107
#[ macro_export]
61
108
macro_rules! enter_trace_span {
109
+ ( $machine: ident, $name: ident :: $subname: ident $( $tt: tt) * ) => { {
110
+ $crate:: enter_trace_span!( $machine, stringify!( $name) , $name = %stringify!( $subname) $( $tt) * )
111
+ } } ;
112
+
62
113
( $machine: ident, $( $tt: tt) * ) => {
63
114
$machine:: enter_trace_span( || tracing:: info_span!( $( $tt) * ) )
64
115
}
0 commit comments