From 56f1e905dedb5697a54c02e0f69de3c72aad02c0 Mon Sep 17 00:00:00 2001
From: Benjamin Lee <benjamin@computer.surgery>
Date: Fri, 26 Apr 2024 18:49:58 -0700
Subject: [PATCH] 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.
---
 src/config/mod.rs | 6 ++++++
 src/main.rs       | 8 +++++++-
 2 files changed, 13 insertions(+), 1 deletion(-)

diff --git a/src/config/mod.rs b/src/config/mod.rs
index c842b7706..da14c184b 100644
--- a/src/config/mod.rs
+++ b/src/config/mod.rs
@@ -178,6 +178,9 @@ pub(crate) struct Config {
 	#[serde(default = "default_tracing_flame_filter")]
 	#[cfg(feature = "perf_measurements")]
 	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)]
 	pub(crate) proxy: ProxyConfig,
 	pub(crate) jwt_secret: Option<String>,
@@ -940,6 +943,9 @@ fn default_max_fetch_prev_events() -> u16 { 100_u16 }
 #[cfg(feature = "perf_measurements")]
 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_log() -> String {
diff --git a/src/main.rs b/src/main.rs
index 128766eaf..31f04c10b 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -630,7 +630,13 @@ fn init_tracing(config: &Config) -> (LogLevelReloadHandles, TracingFlameGuard) {
 				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
 				.with_empty_samples(false)
 				.with_filter(flame_filter);
-- 
GitLab