Skip to content

feat: add --iterations flags to specify how many times to run target binary #332

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

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions src/bin/flamegraph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ struct Opt {
#[clap(flatten)]
graph: flamegraph::Options,

/// Read perf data from the given file.
#[clap(long = "perfdata", conflicts_with = "pid")]
perf_file: Option<PathBuf>,

Expand Down
36 changes: 27 additions & 9 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,13 @@
};
use inferno::{collapse::Collapse, flamegraph::color::Palette, flamegraph::from_reader};

/// Mode of operation.
pub enum Workload {
/// Execute an executable with the given command and arguments.
Command(Vec<String>),
/// Profile a running process with the given PID.
Pid(u32),
/// Read profiling data from a file.
ReadPerf(String),
}

Expand Down Expand Up @@ -168,7 +172,7 @@
}

pub(crate) fn initial_command(
workload: Workload,
workload: &Workload,
sudo: Option<Option<&str>>,
freq: u32,
custom_cmd: Option<String>,
Expand Down Expand Up @@ -363,14 +367,24 @@
let perf_output = if let Workload::ReadPerf(perf_file) = workload {
Some(perf_file)
} else {
arch::initial_command(
workload,
sudo,
opts.frequency(),
opts.custom_cmd,
opts.verbose,
opts.ignore_status,
)
let out = (0..opts.iterations.unwrap_or(1)).fold(String::new(), |mut out, _i| {
if let Some(iter_out) = arch::initial_command(
&workload,

Check failure on line 372 in src/lib.rs

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest)

mismatched types
sudo,
opts.frequency(),
opts.custom_cmd.clone(),
opts.verbose,
opts.ignore_status,
) {
out.push_str(&iter_out)
}
out
});
if out.is_empty() {
None
} else {
Some(out)
}
};

#[cfg(unix)]
Expand Down Expand Up @@ -487,6 +501,10 @@
#[clap(short = 'F', long = "freq")]
frequency: Option<u32>,

/// Number of runs for target binary. Defaults to 1.
#[clap(long)]
iterations: Option<usize>,

/// Custom command for invoking perf/dtrace
#[clap(short, long = "cmd")]
custom_cmd: Option<String>,
Expand Down
Loading