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 7, 2024
1 parent 50611df commit 9b662dc
Show file tree
Hide file tree
Showing 3 changed files with 87 additions and 0 deletions.
67 changes: 67 additions & 0 deletions Cargo.lock

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

2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,10 @@ 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"
scopeguard = "1.2.0"
shlex = "1.1.0"

[target.'cfg(unix)'.dependencies]
Expand Down
18 changes: 18 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ pub enum Workload {

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

use super::*;

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

// perf script can take a long time to run. Notify the user that it is running
// by using a spinner. Ensure that the spinner gets cleaned up regardless of how
// this function exits by using a scopeguard.
let spinner = ProgressBar::new_spinner().with_prefix("Running perf script");
spinner.set_style(
ProgressStyle::with_template("{prefix} [{elapsed}]: {spinner:.green}")
.unwrap()
.tick_strings(&[".", "..", "...", " ..", " .", "", "✓"]),
);
spinner.enable_steady_tick(Duration::from_millis(500));
let _guard = scopeguard::guard(spinner, |spinner| {
spinner.finish();
});

let output = command.output().context("unable to call perf script")?;
if !output.status.success() {
anyhow::bail!(format!(
Expand Down

0 comments on commit 9b662dc

Please sign in to comment.