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 2190753
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
@@ -1,3 +1,4 @@
use indicatif::{ProgressBar, ProgressStyle};
use std::{
env,
fs::File,
Expand Down Expand Up @@ -34,6 +35,8 @@ pub enum Workload {

#[cfg(target_os = "linux")]
mod arch {
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, so notify the user that it is running
// by using a spinner.
let spinner = ProgressBar::new_spinner().with_prefix("Running perf script");
spinner.set_style(ProgressStyle::with_template("{prefix}: {spinner} [{elapsed}]").unwrap());
spinner.enable_steady_tick(Duration::from_millis(80));

// Call perf script here, but if there is an error, do not exit the function until
// we have cleaned up the spinner. If there was no error running the command, process
// the status of the command and return its output.
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 2190753

Please sign in to comment.