Skip to content

Commit

Permalink
More logging of command input/output
Browse files Browse the repository at this point in the history
This will not log the exact command we execute, and will always log
stdout & stderr.
  • Loading branch information
cmyr committed Oct 13, 2023
1 parent 321f1d6 commit a2bb24e
Showing 1 changed file with 28 additions and 6 deletions.
34 changes: 28 additions & 6 deletions src/instruments.rs
Original file line number Diff line number Diff line change
Expand Up @@ -462,19 +462,41 @@ pub(crate) fn profile_target(
command.args(app_config.target_args.as_slice());
}

let output = command.output()?;
log_command_string(&command);

let output = command.output()?;
let stdout = if !output.stdout.is_empty() {
String::from_utf8_lossy(&output.stdout)
} else {
"{empty}".into()
};
let stderr = if !output.stderr.is_empty() {
String::from_utf8_lossy(&output.stderr)
} else {
"{empty}".into()
};
if output.status.success() {
log::debug!("{xctrace_tool} exited successfuly");
log::debug!("captured stdout:\n{stdout}");
log::debug!("captured stderr:\n{stderr}");
}
if !output.status.success() {
let stderr =
String::from_utf8(output.stderr).unwrap_or_else(|_| "failed to capture stderr".into());
let stdout =
String::from_utf8(output.stdout).unwrap_or_else(|_| "failed to capture stdout".into());
return Err(anyhow!("instruments errored: {} {}", stderr, stdout));
return Err(anyhow!(
"{xctrace_tool} exited with error.\nstdout: {}\nstderr: {stderr}",
stdout.trim_end(),
));
}

Ok(trace_filepath)
}

fn log_command_string(command: &Command) {
let mut elements = vec![command.get_program().to_string_lossy()];
elements.extend(command.get_args().map(|arg| arg.to_string_lossy()));
let as_string = elements.join(" ");
log::debug!("executing command {as_string}")
}

/// get the tty of th current terminal session
fn get_tty() -> Result<Option<String>> {
let mut command = Command::new("ps");
Expand Down

0 comments on commit a2bb24e

Please sign in to comment.