Skip to content

Commit

Permalink
Add --gil and --idle options to the top subcommand (#411)
Browse files Browse the repository at this point in the history
This change allows you to pass --idle and --gil commands to the top
command as well as the record command. This lets you view all samples
or samples that hold the gil in the 'top' tui the same as you can
with the record subcommand

Closes #406
  • Loading branch information
benfred authored Jun 27, 2021
1 parent 37163b6 commit 5c2b354
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 15 deletions.
25 changes: 15 additions & 10 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -135,11 +135,20 @@ impl Config {
let full_filenames = Arg::with_name("full_filenames")
.long("full-filenames")
.help("Show full Python filenames, instead of shortening to show only the package part");

let program = Arg::with_name("python_program")
.help("commandline of a python program to run")
.multiple(true);

let idle = Arg::with_name("idle")
.short("i")
.long("idle")
.help("Include stack traces for idle threads");

let gil = Arg::with_name("gil")
.short("g")
.long("gil")
.help("Only include traces that are holding on to the GIL");

let record = clap::SubCommand::with_name("record")
.about("Records stack trace information to a flamegraph, speedscope or raw file")
.arg(program.clone())
Expand Down Expand Up @@ -174,18 +183,12 @@ impl Config {
.short("F")
.long("function")
.help("Aggregate samples by function name instead of by line number"))
.arg(Arg::with_name("gil")
.short("g")
.long("gil")
.help("Only include traces that are holding on to the GIL"))
.arg(Arg::with_name("threads")
.short("t")
.long("threads")
.help("Show thread ids in the output"))
.arg(Arg::with_name("idle")
.short("i")
.long("idle")
.help("Include stack traces for idle threads"))
.arg(gil.clone())
.arg(idle.clone())
.arg(Arg::with_name("capture")
.long("capture")
.hidden(true)
Expand All @@ -201,7 +204,9 @@ impl Config {
.arg(pid.clone())
.arg(rate.clone())
.arg(subprocesses.clone())
.arg(full_filenames.clone());
.arg(full_filenames.clone())
.arg(gil.clone())
.arg(idle.clone());

let dump = clap::SubCommand::with_name("dump")
.about("Dumps stack traces for a target program to stdout")
Expand Down
15 changes: 10 additions & 5 deletions src/console_viewer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@ use crate::version::Version;
pub struct ConsoleViewer {
#[allow(dead_code)]
console_config: os_impl::ConsoleConfig,
show_idle: bool,
version: Option<Version>,
command: String,
sampling_rate: f64,
running: Arc<atomic::AtomicBool>,
options: Arc<Mutex<Options>>,
stats: Stats,
subprocesses: bool
subprocesses: bool,
config: Config
}

impl ConsoleViewer {
Expand Down Expand Up @@ -66,9 +66,10 @@ impl ConsoleViewer {
Ok(ConsoleViewer{console_config: os_impl::ConsoleConfig::new()?,
version: version.clone(),
command: python_command.to_owned(),
show_idle: false, running, options, sampling_rate,
running, options, sampling_rate,
subprocesses: config.subprocesses,
stats: Stats::new()})
stats: Stats::new(),
config: config.clone()})
}

pub fn increment(&mut self, traces: &[StackTrace]) -> Result<(), Error> {
Expand All @@ -83,7 +84,11 @@ impl ConsoleViewer {
last_pid = Some(trace.pid);
}

if !(self.show_idle || trace.active) {
if !(self.config.include_idle || trace.active) {
continue;
}

if self.config.gil_only && !trace.owns_gil {
continue;
}

Expand Down

0 comments on commit 5c2b354

Please sign in to comment.