Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

More logging of command input/output #98

Merged
merged 1 commit into from
Oct 13, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading