Skip to content

Commit

Permalink
Make 'top' refresh interval configurable (#537)
Browse files Browse the repository at this point in the history
Co-authored-by: Edgars Irmejs <[email protected]>
Co-authored-by: Ben Frederickson <[email protected]>
  • Loading branch information
3 people authored Dec 9, 2022
1 parent e2a4835 commit c325f41
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
19 changes: 16 additions & 3 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use clap::{ArgEnum, Arg, Command, crate_description, crate_name, crate_version,
use remoteprocess::Pid;

/// Options on how to collect samples from a python process
#[derive(Debug, Clone, Eq, PartialEq)]
#[derive(Debug, Clone, PartialEq)]
pub struct Config {
/// Whether or not we should stop the python process when taking samples.
/// Setting this to false will reduce the performance impact on the target
Expand Down Expand Up @@ -53,6 +53,8 @@ pub struct Config {
#[doc(hidden)]
pub lineno: LineNo,
#[doc(hidden)]
pub refresh_seconds: f64,
#[doc(hidden)]
pub core_filename: Option<String>,
}

Expand Down Expand Up @@ -118,7 +120,8 @@ impl Default for Config {
duration: RecordDuration::Unlimited, native: false,
gil_only: false, include_idle: false, include_thread_ids: false,
hide_progress: false, capture_output: true, dump_json: false, dump_locals: 0, subprocesses: false,
full_filenames: false, lineno: LineNo::LastInstruction, core_filename: None }
full_filenames: false, lineno: LineNo::LastInstruction,
refresh_seconds: 1.0, core_filename: None }
}
}

Expand Down Expand Up @@ -181,6 +184,14 @@ impl Config {
.long("gil")
.help("Only include traces that are holding on to the GIL");

let top_delay = Arg::new("delay")
.long("delay")
.value_name("seconds")
.help("Delay between 'top' refreshes.")
.default_value("1.0")
.value_parser(clap::value_parser!(f64))
.takes_value(true);

let record = Command::new("record")
.about("Records stack trace information to a flamegraph, speedscope or raw file")
.arg(program.clone())
Expand Down Expand Up @@ -241,7 +252,8 @@ impl Config {
.arg(subprocesses.clone())
.arg(full_filenames.clone())
.arg(gil.clone())
.arg(idle.clone());
.arg(idle.clone())
.arg(top_delay.clone());

#[cfg(target_os="linux")]
let dump_pid = pid.clone().required_unless_present("core");
Expand Down Expand Up @@ -334,6 +346,7 @@ impl Config {
},
"top" => {
config.sampling_rate = matches.value_of_t("rate")?;
config.refresh_seconds = *matches.get_one::<f64>("delay").unwrap();
},
"dump" => {
config.dump_json = matches.occurrences_of("json") > 0;
Expand Down
2 changes: 1 addition & 1 deletion src/console_viewer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ impl ConsoleViewer {
match self.stats.overall_samples {
10 | 100 | 500 => true,
_ => self.options.lock().unwrap().dirty ||
self.stats.elapsed >= 1.0
self.stats.elapsed >= self.config.refresh_seconds
}
}

Expand Down

0 comments on commit c325f41

Please sign in to comment.