Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add --full-filenames to allow showing full Python filenames #363

Merged
merged 2 commits into from
Mar 22, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 18 additions & 7 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ pub struct Config {
pub dump_json: bool,
#[doc(hidden)]
pub dump_locals: u64,
#[doc(hidden)]
pub full_filenames: bool,
}

arg_enum!{
Expand Down Expand Up @@ -83,7 +85,8 @@ impl Default for Config {
blocking: LockingStrategy::Lock, show_line_numbers: false, sampling_rate: 100,
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}
hide_progress: false, capture_output: true, dump_json: false, dump_locals: 0, subprocesses: false,
full_filenames: false}
}
}

Expand All @@ -95,7 +98,7 @@ impl Config {
}

pub fn from_args(args: &[String]) -> clap::Result<Config> {
// pid/native/nonblocking/rate/pythonprogram arguments can be
// pid/native/nonblocking/rate/python_program/subprocesses/full_filenames arguments can be
// used across various subcommand - define once here
let pid = Arg::with_name("pid")
.short("p")
Expand Down Expand Up @@ -124,10 +127,14 @@ impl Config {
.default_value("100")
.takes_value(true);

let subprocesses = Arg::with_name("subprocesses")
.short("s")
.long("subprocesses")
.help("Profile subprocesses of the original process");
let subprocesses = Arg::with_name("subprocesses")
.short("s")
.long("subprocesses")
.help("Profile subprocesses of the original process");

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")
Expand All @@ -137,6 +144,7 @@ impl Config {
.about("Records stack trace information to a flamegraph, speedscope or raw file")
.arg(program.clone())
.arg(pid.clone())
.arg(full_filenames.clone())
.arg(Arg::with_name("output")
.short("o")
.long("output")
Expand Down Expand Up @@ -192,11 +200,13 @@ impl Config {
.arg(program.clone())
.arg(pid.clone())
.arg(rate.clone())
.arg(subprocesses.clone());
.arg(subprocesses.clone())
.arg(full_filenames.clone());

let dump = clap::SubCommand::with_name("dump")
.about("Dumps stack traces for a target program to stdout")
.arg(pid.clone().required(true))
.arg(full_filenames.clone())
.arg(Arg::with_name("locals")
.short("l")
.long("locals")
Expand Down Expand Up @@ -273,6 +283,7 @@ impl Config {
config.dump_json = matches.occurrences_of("json") > 0;
config.dump_locals = matches.occurrences_of("locals");
config.subprocesses = matches.occurrences_of("subprocesses") > 0;
config.full_filenames = matches.occurrences_of("full_filenames") > 0;

config.capture_output = config.command != "record" || matches.occurrences_of("capture") > 0;
if !config.capture_output {
Expand Down
5 changes: 5 additions & 0 deletions src/python_spy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -464,6 +464,11 @@ impl PythonSpy {
/// directory etc. This function looks only includes paths inside a python
/// package or subpackage, and not the path the package is installed at
fn shorten_filename(&mut self, filename: &str) -> Option<String> {
// if the user requested full filenames, skip shortening
if self.config.full_filenames {
return Some(filename.to_string());
}

// if we have figured out the short filename already, use it
if let Some(short) = self.short_filenames.get(filename) {
return short.clone();
Expand Down