diff --git a/tracing-flame/src/lib.rs b/tracing-flame/src/lib.rs index cde6666eee..e307d09e9b 100644 --- a/tracing-flame/src/lib.rs +++ b/tracing-flame/src/lib.rs @@ -227,6 +227,12 @@ struct Config { /// Don't include thread_id threads_collapsed: bool, + + /// Don't display module_path + module_path: bool, + + /// Don't display file and line + file_and_line: bool, } impl Default for Config { @@ -234,6 +240,8 @@ impl Default for Config { Self { empty_samples: true, threads_collapsed: false, + module_path: true, + file_and_line: true, } } } @@ -311,6 +319,18 @@ where self.config.threads_collapsed = enabled; self } + + /// Configures whether or not module paths should be included in the output. + pub fn with_module_path(mut self, enabled: bool) -> Self { + self.config.module_path = enabled; + self + } + + /// Configures whether or not file and line should be included in the output. + pub fn with_file_and_line(mut self, enabled: bool) -> Self { + self.config.file_and_line = enabled; + self + } } impl FlushGuard @@ -394,7 +414,7 @@ where for parent in parents { stack += "; "; - write(&mut stack, parent).expect("expected: write to String never fails"); + write(&mut stack, parent, &self.config).expect("expected: write to String never fails"); } write!(&mut stack, " {}", samples.as_nanos()) @@ -436,14 +456,14 @@ where for parent in parents { expect!( - write(&mut stack, parent), + write(&mut stack, parent, &self.config), "expected: write to String never fails" ); stack += "; "; } expect!( - write(&mut stack, first), + write(&mut stack, first, &self.config), "expected: write to String never fails" ); expect!( @@ -473,22 +493,26 @@ where } } -fn write(dest: &mut String, span: SpanRef<'_, S>) -> fmt::Result +fn write(dest: &mut String, span: SpanRef<'_, S>, config: &Config) -> fmt::Result where S: Subscriber + for<'span> LookupSpan<'span>, { - if let Some(module_path) = span.metadata().module_path() { - write!(dest, "{}::", module_path)?; + if config.module_path { + if let Some(module_path) = span.metadata().module_path() { + write!(dest, "{}::", module_path)?; + } } write!(dest, "{}", span.name())?; - if let Some(file) = span.metadata().file() { - write!(dest, ":{}", file)?; - } + if config.file_and_line { + if let Some(file) = span.metadata().file() { + write!(dest, ":{}", file)?; + } - if let Some(line) = span.metadata().line() { - write!(dest, ":{}", line)?; + if let Some(line) = span.metadata().line() { + write!(dest, ":{}", line)?; + } } Ok(())