add config option tracing_flame_output_path

Hardcoding the output path to something in CWD is a pain if you're running
conduwuit through systemd or similar. Also made the error message when
it's unable to create the output file a little more friendly.
This commit is contained in:
Benjamin Lee 2024-04-26 18:49:58 -07:00 committed by June
parent 646b31d2bd
commit 56f1e905de
2 changed files with 13 additions and 1 deletions

View file

@ -178,6 +178,9 @@ pub(crate) struct Config {
#[serde(default = "default_tracing_flame_filter")] #[serde(default = "default_tracing_flame_filter")]
#[cfg(feature = "perf_measurements")] #[cfg(feature = "perf_measurements")]
pub(crate) tracing_flame_filter: String, pub(crate) tracing_flame_filter: String,
#[serde(default = "default_tracing_flame_output_path")]
#[cfg(feature = "perf_measurements")]
pub(crate) tracing_flame_output_path: String,
#[serde(default)] #[serde(default)]
pub(crate) proxy: ProxyConfig, pub(crate) proxy: ProxyConfig,
pub(crate) jwt_secret: Option<String>, pub(crate) jwt_secret: Option<String>,
@ -940,6 +943,9 @@ fn default_max_fetch_prev_events() -> u16 { 100_u16 }
#[cfg(feature = "perf_measurements")] #[cfg(feature = "perf_measurements")]
fn default_tracing_flame_filter() -> String { "trace,h2=off".to_owned() } fn default_tracing_flame_filter() -> String { "trace,h2=off".to_owned() }
#[cfg(feature = "perf_measurements")]
fn default_tracing_flame_output_path() -> String { "./tracing.folded".to_owned() }
fn default_trusted_servers() -> Vec<OwnedServerName> { vec![OwnedServerName::try_from("matrix.org").unwrap()] } fn default_trusted_servers() -> Vec<OwnedServerName> { vec![OwnedServerName::try_from("matrix.org").unwrap()] }
fn default_log() -> String { fn default_log() -> String {

View file

@ -630,7 +630,13 @@ fn init_tracing(config: &Config) -> (LogLevelReloadHandles, TracingFlameGuard) {
Err(e) => panic!("tracing_flame_filter config value is invalid: {e}"), Err(e) => panic!("tracing_flame_filter config value is invalid: {e}"),
}; };
let (flame_layer, flame_guard) = tracing_flame::FlameLayer::with_file("./tracing.folded").unwrap(); let (flame_layer, flame_guard) =
match tracing_flame::FlameLayer::with_file(&config.tracing_flame_output_path) {
Ok(ok) => ok,
Err(e) => {
panic!("failed to initialize tracing-flame: {e}");
},
};
let flame_layer = flame_layer let flame_layer = flame_layer
.with_empty_samples(false) .with_empty_samples(false)
.with_filter(flame_filter); .with_filter(flame_filter);