Commit 53111dd60132
tarball2 files changed+22-6
@@ -117,13 +117,16 @@ fn main() -> ExitCode {
117117
.with_ansi(std::io::IsTerminal::is_terminal(&std::io::stderr()))118118
.with_filter(filter);119119
#[cfg(feature = "spans")]120
- let spans =121
- Some(slow_spans::SlowSpans.with_filter(tracing_subscriber::filter::LevelFilter::TRACE));120
+ let slow = slow_spans::SlowSpans::from_env();121
+ #[cfg(feature = "spans")]122
+ let threshold_us = slow.threshold_us;123
+ #[cfg(feature = "spans")]124
+ let spans = Some(slow.with_filter(tracing_subscriber::filter::LevelFilter::TRACE));122125
#[cfg(not(feature = "spans"))]123126
let spans: Option<tracing_subscriber::layer::Identity> = None;124127
tracing_subscriber::registry().with(fmt).with(spans).init();125128
#[cfg(feature = "spans")]126
- tracing::info!("logging spans slower than 1 ms");129
+ tracing::info!("logging spans slower than {threshold_us} us");127130
let backend = match backend {128131
Backend::Auto if std::env::var_os("WAYLAND_DISPLAY").is_some() => Backend::Nested,129132
Backend::Auto => Backend::Drm,@@ -1,5 +1,6 @@
11
//! Prints every span that runs for a millisecond or more, for finding what2
-//! makes a frame late. Built only with the `spans` feature.2
+//! makes a frame late. `MONOLITH_SLOW_SPAN_US` lowers the bar when the slow3
+//! part is many small spans. Built only with the `spans` feature.34
45
use std::time::Instant;56
use tracing::span;@@ -7,7 +8,19 @@ use tracing_subscriber::Layer;
78
use tracing_subscriber::layer::Context;89
use tracing_subscriber::registry::LookupSpan;910
10
-pub struct SlowSpans;11
+pub struct SlowSpans {12
+ pub threshold_us: u128,13
+}14
+15
+impl SlowSpans {16
+ pub fn from_env() -> Self {17
+ let threshold_us = std::env::var("MONOLITH_SLOW_SPAN_US")18
+ .ok()19
+ .and_then(|v| v.parse().ok())20
+ .unwrap_or(1000);21
+ Self { threshold_us }22
+ }23
+}1124
1225
struct Entered(Instant);1326
@@ -27,7 +40,7 @@ where
2740
return;2841
};2942
let took = at.elapsed();30
- if took.as_micros() >= 1000 {43
+ if took.as_micros() >= self.threshold_us {3144
let path: Vec<&str> = span.scope().from_root().map(|s| s.name()).collect();3245
eprintln!("slow span {} took_us={}", path.join(">"), took.as_micros());3346
}