Skip to content

Commit

Permalink
Show indicators that perf script is running
Browse files Browse the repository at this point in the history
Perf script can take a long time to run. This change adds an indicator
to show that it is running so that the user knows that their application
is not causing the terminal to hang.

Addresses flamegraph-rs#270
  • Loading branch information
gth828r committed Nov 11, 2024
1 parent 0e2b31c commit e0cd1d3
Show file tree
Hide file tree
Showing 3 changed files with 82 additions and 1 deletion.
66 changes: 66 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ anyhow = "1.0.43"
cargo_metadata = "0.18"
clap = { version = "4.0.11", features = ["derive"] }
clap_complete = "4.0.2"
indicatif = "0.17.8"
inferno = { version = "0.11.0", default_features = false, features = ["multithreaded", "nameattr"] }
opener = "0.7.1"
shlex = "1.1.0"
Expand Down
16 changes: 15 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ pub enum Workload {

#[cfg(target_os = "linux")]
mod arch {
use indicatif::{ProgressBar, ProgressStyle};
use std::time::Duration;

use super::*;

pub const SPAWN_ERROR: &str = "could not spawn perf";
Expand Down Expand Up @@ -116,7 +119,18 @@ mod arch {
command.arg(perf_output);
}

let output = command.output().context("unable to call perf script")?;
// perf script can take a long time to run. Notify the user that it is running
// by using a spinner. Note that if this function exits before calling
// spinner.finish(), then the spinner will be completely removed from the terminal.
let spinner = ProgressBar::new_spinner().with_prefix("Running perf script");
spinner.set_style(
ProgressStyle::with_template("{prefix} [{elapsed}]: {spinner:.green}").unwrap(),
);
spinner.enable_steady_tick(Duration::from_millis(500));

let result = command.output().context("unable to call perf script");
spinner.finish();
let output = result?;
if !output.status.success() {
anyhow::bail!(format!(
"unable to run 'perf script': ({}) {}",
Expand Down

0 comments on commit e0cd1d3

Please sign in to comment.