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

Add ignore exit code flag #490

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
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
3 changes: 2 additions & 1 deletion samply/src/linux/profiler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ pub fn start_recording(
command_name,
args,
iteration_count,
ignore_exit_code,
} = process_launch_props;

if profile_creation_props.coreclr.any_enabled() {
Expand Down Expand Up @@ -191,7 +192,7 @@ pub fn start_recording(
WaitStatus::Exited(_pid, exit_code) => ExitStatus::from_raw(*exit_code).success(),
_ => false,
};
if !previous_run_exited_with_success {
if !ignore_exit_code && !previous_run_exited_with_success {
eprintln!(
"Skipping remaining iterations due to non-success exit status: {wait_status:?}"
);
Expand Down
4 changes: 3 additions & 1 deletion samply/src/mac/process_launcher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ pub struct TaskLauncher {
args: Vec<OsString>,
child_env: Vec<(OsString, OsString)>,
iteration_count: u32,
ignore_exit_code: bool,
}

impl RootTaskRunner for TaskLauncher {
Expand All @@ -41,7 +42,7 @@ impl RootTaskRunner for TaskLauncher {
let mut exit_status = root_child.wait().expect("couldn't wait for child");

for i in 2..=self.iteration_count {
if !exit_status.success() {
if self.ignore_exit_code && !exit_status.success() {
eprintln!(
"Skipping remaining iterations due to non-success exit status: \"{}\"",
exit_status
Expand All @@ -65,6 +66,7 @@ impl TaskLauncher {
program: S,
args: I,
iteration_count: u32,
ignore_exit_code: bool,
env_vars: &[(OsString, OsString)],
extra_env_vars: &[(OsString, OsString)],
) -> Result<TaskLauncher, MachError>
Expand Down
3 changes: 3 additions & 0 deletions samply/src/mac/profiler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ pub fn start_recording(
command_name,
args,
iteration_count,
ignore_exit_code,
} = process_launch_props;

let task_launcher = if profile_creation_props.coreclr.any_enabled() {
Expand All @@ -62,6 +63,7 @@ pub fn start_recording(
&command_name,
&args,
iteration_count,
ignore_exit_code,
&env_vars,
task_accepter.extra_env_vars(),
)?
Expand All @@ -70,6 +72,7 @@ pub fn start_recording(
&command_name,
&args,
iteration_count,
ignore_exit_code,
&env_vars,
task_accepter.extra_env_vars(),
)?
Expand Down
5 changes: 5 additions & 0 deletions samply/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,10 @@ struct RecordArgs {
#[arg(long, default_value = "1")]
iteration_count: u32,

/// Ignore exit code and continue running when iteration_count > 0
#[arg(short, long)]
ignore_exit_code: bool,

#[command(flatten)]
profile_creation_args: ProfileCreationArgs,

Expand Down Expand Up @@ -647,6 +651,7 @@ impl RecordArgs {
command_name,
args,
iteration_count,
ignore_exit_code: self.ignore_exit_code,
};

RecordingMode::Launch(launch_props)
Expand Down
1 change: 1 addition & 0 deletions samply/src/shared/recording_props.rs
Original file line number Diff line number Diff line change
Expand Up @@ -118,4 +118,5 @@ pub struct ProcessLaunchProps {
pub command_name: OsString,
pub args: Vec<OsString>,
pub iteration_count: u32,
pub ignore_exit_code: bool,
}
4 changes: 4 additions & 0 deletions samply/src/windows/profiler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,10 @@ pub fn start_recording(

pids.push(child.id());

if process_launch_props.ignore_exit_code {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this is right - you need to wait for the child process to finish before you launch the next iteration. Can you combine this check with the existing !exit_status.success() check?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are correct, this condition should go after the wait call. Have updated 👍

continue;
}

// Wait for the child to exit.
//
// TODO: Do the child waiting and the xperf control on different threads,
Expand Down