From 07e3843c3f5ab6aa011e0cd2cb296030f0477751 Mon Sep 17 00:00:00 2001 From: Jeremy Whiting Date: Tue, 23 Jan 2024 11:00:35 -0700 Subject: [PATCH] wifidebug: Add trace-cmd usage to start and stop gathering data. When wifi debug mode is started trace-cmd start is executed with the given buffer_size parameter. Later when wifi debug mode is stopped, trace-cmd stop is executed as well as trace-cmd extract to write the data to a file on disk. In this way the steam client (or any dbus users...) can decide how long to run trace-cmd for. Change to create_dir_all so we don't get errors if it exists. Signed-off-by: Jeremy Whiting --- src/manager.rs | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/src/manager.rs b/src/manager.rs index 3840fcf..d7dadb3 100644 --- a/src/manager.rs +++ b/src/manager.rs @@ -59,6 +59,10 @@ ExecStart=/usr/lib/iwd/iwd -d "; const OVERRIDE_FOLDER: &str = "/etc/systemd/system/iwd.service.d"; const OVERRIDE_PATH: &str = "/etc/systemd/system/iwd.service.d/override.conf"; +// Only use one path for output for now. If needed we can add a timestamp later +// to have multiple files, etc. +const OUTPUT_FILE: &str = "/var/log/wifitrace.dat"; +const MIN_BUFFER_SIZE: u32 = 100; async fn script_exit_code( executable: &str, @@ -109,7 +113,7 @@ async fn setup_iwd_config(want_override: bool) -> Result<(), std::io::Error> if want_override { // Copy it in // Make sure the folder exists - tokio::fs::create_dir(OVERRIDE_FOLDER).await?; + tokio::fs::create_dir_all(OVERRIDE_FOLDER).await?; // Then write the contents into the file tokio::fs::write(OVERRIDE_PATH, OVERRIDE_CONTENTS).await } else { @@ -130,6 +134,20 @@ async fn restart_iwd() -> bool run_script("restart iwd", "systemctl", &["restart", "iwd"]).await } +async fn stop_tracing() -> bool +{ + // Stop tracing and extract ring buffer to disk for capture + run_script("stop tracing", "trace-cmd", &["stop"]).await; + run_script("extract traces", "trace-cmd", &["extract", "-o", OUTPUT_FILE]).await +} + +async fn start_tracing(buffer_size:u32) -> bool +{ + // Start tracing + let size_str = format!("{}", buffer_size); + run_script("start tracing", "trace-cmd", &["start", "-e", "ath11k_wmi_diag", "-b", &size_str]).await +} + #[dbus_interface(name = "com.steampowered.SteamOSManager1")] impl SMManager { const API_VERSION: u32 = 1; @@ -397,15 +415,22 @@ impl SMManager { // If mode is 0 disable wifi debug mode if mode == 0 { + // Stop any existing trace and flush to disk. + stop_tracing().await; let _ = setup_iwd_config(false).await; reload_systemd().await; restart_iwd().await; } // If mode is 1 enable wifi debug mode else if mode == 1 { + if buffer_size < MIN_BUFFER_SIZE { + return false; + } + let _ = setup_iwd_config(true).await; reload_systemd().await; restart_iwd().await; + start_tracing(buffer_size).await; } else { // Invalid mode requested, more coming later, but add this catch-all for now