Skip to content
Merged
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
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,12 @@ usually something like `~/.cargo/bin`.
# if you'd like to profile an arbitrary executable:
flamegraph [-o my_flamegraph.svg] /path/to/my/binary --my-arg 5

# NOTE: By default, perf tries to compute which functions are
# inlined at every stack frame for every sample. This can take
# a very long time (see https://github.com/flamegraph-rs/flamegraph/issues/74).
# If you don't want this, you can pass --no-inline to flamegraph:
flamegraph --no-inline [-o my_flamegraph.svg] /path/to/my/binary --my-arg 5

# cargo support provided through the cargo-flamegraph binary!
# defaults to profiling cargo run --release
cargo flamegraph
Expand Down
5 changes: 5 additions & 0 deletions src/bin/cargo-flamegraph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,10 @@ struct Opt {
)]
custom_cmd: Option<String>,

/// Disable inlining for perf script because of performace issues
#[structopt(long = "no-inline")]
script_no_inline: bool,

#[structopt(flatten)]
flamegraph_options: flamegraph::FlamegraphOptions,

Expand Down Expand Up @@ -386,6 +390,7 @@ fn main() {
Workload::Command(workload),
&flamegraph_filename,
opt.root,
opt.script_no_inline,
opt.frequency,
opt.custom_cmd,
opt.flamegraph_options.into_inferno(),
Expand Down
5 changes: 5 additions & 0 deletions src/bin/flamegraph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@ struct Opt {
)]
custom_cmd: Option<String>,

/// Disable inlining for perf script because of performance issues
#[structopt(long = "no-inline")]
script_no_inline: bool,

#[structopt(flatten)]
flamegraph_options: flamegraph::FlamegraphOptions,

Expand Down Expand Up @@ -88,6 +92,7 @@ fn main() {
workload,
&flamegraph_filename,
opt.root,
opt.script_no_inline,
opt.frequency,
opt.custom_cmd,
opt.flamegraph_options.into_inferno(),
Expand Down
21 changes: 18 additions & 3 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,11 +89,17 @@ mod arch {
(command, perf_output)
}

pub fn output(perf_output: Option<String>) -> Vec<u8> {
pub fn output(
perf_output: Option<String>,
script_no_inline: bool,
) -> Vec<u8> {
let perf = env::var("PERF")
.unwrap_or_else(|_| "perf".to_string());
let mut command = Command::new(perf);
command.arg("script");
if script_no_inline {
command.arg("--no-inline");
}
if let Some(perf_output) = perf_output {
command.arg("-i");
command.arg(perf_output);
Expand Down Expand Up @@ -170,7 +176,14 @@ mod arch {
(command, None)
}

pub fn output(_: Option<String>) -> Vec<u8> {
pub fn output(
_: Option<String>,
script_no_inline: bool,
) -> Vec<u8> {
if script_no_inline {
eprintln!("Option --no-inline is only supported on linux systems.");
std::process::exit(1);
}
let mut buf = vec![];
let mut f = File::open("cargo-flamegraph.stacks")
.expect(
Expand Down Expand Up @@ -234,6 +247,7 @@ pub fn generate_flamegraph_for_workload<
workload: Workload,
flamegraph_filename: P,
sudo: bool,
script_no_inline: bool,
freq: Option<u32>,
custom_cmd: Option<String>,
mut flamegraph_options: inferno::flamegraph::Options,
Expand Down Expand Up @@ -276,7 +290,8 @@ pub fn generate_flamegraph_for_workload<
std::process::exit(1);
}

let output = arch::output(perf_output);
let output =
arch::output(perf_output, script_no_inline);

let perf_reader = BufReader::new(&*output);

Expand Down