manager: Just don't call start-/stop_tracing if should_trace is false

This commit is contained in:
Vicki Pfau 2024-03-25 16:15:14 -07:00
parent de55ef31ce
commit ebd89f4f72

View file

@ -146,11 +146,7 @@ async fn restart_iwd() -> Result<bool> {
} }
} }
async fn stop_tracing(should_trace: bool) -> Result<bool> { async fn stop_tracing() -> Result<bool> {
if !should_trace {
return Ok(true);
}
// Stop tracing and extract ring buffer to disk for capture // Stop tracing and extract ring buffer to disk for capture
run_script("stop tracing", "trace-cmd", &["stop"]).await?; run_script("stop tracing", "trace-cmd", &["stop"]).await?;
// stop tracing worked // stop tracing worked
@ -162,11 +158,7 @@ async fn stop_tracing(should_trace: bool) -> Result<bool> {
.await .await
} }
async fn start_tracing(buffer_size: u32, should_trace: bool) -> Result<bool> { async fn start_tracing(buffer_size: u32) -> Result<bool> {
if !should_trace {
return Ok(true);
}
// Start tracing // Start tracing
let size_str = format!("{}", buffer_size); let size_str = format!("{}", buffer_size);
run_script( run_script(
@ -410,16 +402,18 @@ impl SMManager {
Ok(WifiDebugMode::Off) => { Ok(WifiDebugMode::Off) => {
// If mode is 0 disable wifi debug mode // If mode is 0 disable wifi debug mode
// Stop any existing trace and flush to disk. // Stop any existing trace and flush to disk.
let result = match stop_tracing(self.should_trace).await { if self.should_trace {
Ok(result) => result, let result = match stop_tracing().await {
Err(message) => { Ok(result) => result,
error!("stop_tracing command got an error: {message}"); Err(message) => {
error!("stop_tracing command got an error: {message}");
return false;
}
};
if !result {
error!("stop_tracing command returned non-zero");
return false; return false;
} }
};
if !result {
error!("stop_tracing command returned non-zero");
return false;
} }
// Stop_tracing was successful // Stop_tracing was successful
if let Err(message) = setup_iwd_config(false).await { if let Err(message) = setup_iwd_config(false).await {
@ -466,21 +460,22 @@ impl SMManager {
return false; return false;
} }
// restart_iwd worked // restart_iwd worked
let value = match start_tracing(buffer_size, self.should_trace).await { if self.should_trace {
Ok(value) => value, let value = match start_tracing(buffer_size).await {
Err(message) => { Ok(value) => value,
error!("start_tracing got an error: {message}"); Err(message) => {
error!("start_tracing got an error: {message}");
return false;
}
};
if !value {
// start_tracing failed
error!("start_tracing failed");
return false; return false;
} }
};
if value {
// start_tracing worked
self.wifi_debug_mode = WifiDebugMode::On;
} else {
// start_tracing failed
error!("start_tracing failed");
return false;
} }
// start_tracing worked
self.wifi_debug_mode = WifiDebugMode::On;
} }
Err(_) => { Err(_) => {
// Invalid mode requested, more coming later, but add this catch-all for now // Invalid mode requested, more coming later, but add this catch-all for now