diff --git a/Cargo.toml b/Cargo.toml index cdfbd569..f3079690 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,3 +1,6 @@ +[features] +unwind = [] + [package] name = "py-spy" version = "0.3.14" diff --git a/src/binary_parser.rs b/src/binary_parser.rs index 057fed67..b79b521c 100644 --- a/src/binary_parser.rs +++ b/src/binary_parser.rs @@ -17,7 +17,7 @@ pub struct BinaryInfo { } impl BinaryInfo { - #[cfg(unwind)] + #[cfg(feature = "unwind")] pub fn contains(&self, addr: u64) -> bool { addr >= self.addr && addr < (self.addr + self.size) } diff --git a/src/config.rs b/src/config.rs index d8c936f9..709516eb 100644 --- a/src/config.rs +++ b/src/config.rs @@ -160,7 +160,7 @@ impl Config { .help("PID of a running python program to spy on") .takes_value(true); - #[cfg(unwind)] + #[cfg(feature = "unwind")] let native = Arg::new("native") .short('n') .long("native") @@ -328,11 +328,11 @@ impl Config { ); // add native unwinding if appropriate - #[cfg(unwind)] + #[cfg(feature = "unwind")] let record = record.arg(native.clone()); - #[cfg(unwind)] + #[cfg(feature = "unwind")] let top = top.arg(native.clone()); - #[cfg(unwind)] + #[cfg(feature = "unwind")] let dump = dump.arg(native.clone()); // Nonblocking isn't an option for freebsd, remove @@ -429,7 +429,7 @@ impl Config { .value_of("pid") .map(|p| p.parse().expect("invalid pid")); config.full_filenames = matches.occurrences_of("full_filenames") > 0; - if cfg!(unwind) { + if cfg!(feature = "unwind") { config.native = matches.occurrences_of("native") > 0; } diff --git a/src/lib.rs b/src/lib.rs index 424e253e..b7bb259b 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -33,10 +33,10 @@ pub mod binary_parser; pub mod config; #[cfg(target_os = "linux")] pub mod coredump; -#[cfg(unwind)] +#[cfg(feature = "unwind")] mod cython; pub mod dump; -#[cfg(unwind)] +#[cfg(feature = "unwind")] mod native_stack_trace; mod python_bindings; mod python_data_access; diff --git a/src/main.rs b/src/main.rs index f965cc71..df0d602c 100644 --- a/src/main.rs +++ b/src/main.rs @@ -9,11 +9,11 @@ mod config; mod console_viewer; #[cfg(target_os = "linux")] mod coredump; -#[cfg(unwind)] +#[cfg(feature = "unwind")] mod cython; mod dump; mod flamegraph; -#[cfg(unwind)] +#[cfg(feature = "unwind")] mod native_stack_trace; mod python_bindings; mod python_data_access; diff --git a/src/python_spy.rs b/src/python_spy.rs index f5e36d68..47c77682 100644 --- a/src/python_spy.rs +++ b/src/python_spy.rs @@ -1,9 +1,9 @@ #[cfg(windows)] use regex::RegexBuilder; use std::collections::HashMap; -#[cfg(all(target_os = "linux", unwind))] +#[cfg(all(target_os = "linux", feature = "unwind"))] use std::collections::HashSet; -#[cfg(all(target_os = "linux", unwind))] +#[cfg(all(target_os = "linux", feature = "unwind"))] use std::iter::FromIterator; use std::path::Path; @@ -11,7 +11,7 @@ use anyhow::{Context, Error, Result}; use remoteprocess::{Pid, Process, ProcessMemory, Tid}; use crate::config::{Config, LockingStrategy}; -#[cfg(unwind)] +#[cfg(feature = "unwind")] use crate::native_stack_trace::NativeStack; use crate::python_bindings::{ v2_7_15, v3_10_0, v3_11_0, v3_3_7, v3_5_5, v3_6_6, v3_7_0, v3_8_0, v3_9_5, @@ -35,7 +35,7 @@ pub struct PythonSpy { pub python_filename: std::path::PathBuf, pub version_string: String, pub config: Config, - #[cfg(unwind)] + #[cfg(feature = "unwind")] pub native: Option, pub short_filenames: HashMap>, pub python_thread_ids: HashMap, @@ -70,7 +70,7 @@ impl PythonSpy { let version_string = format!("python{}.{}", version.major, version.minor); - #[cfg(unwind)] + #[cfg(feature = "unwind")] let native = if config.native { Some(NativeStack::new( pid, @@ -89,7 +89,7 @@ impl PythonSpy { threadstate_address, python_filename: python_info.python_filename, version_string, - #[cfg(unwind)] + #[cfg(feature = "unwind")] native, #[cfg(target_os = "linux")] dockerized: python_info.dockerized, @@ -291,7 +291,7 @@ impl PythonSpy { } // Merge in the native stack frames if necessary - #[cfg(unwind)] + #[cfg(feature = "unwind")] { if self.config.native { if let Some(native) = self.native.as_mut() { @@ -389,7 +389,7 @@ impl PythonSpy { Ok(None) } - #[cfg(all(target_os = "linux", not(unwind)))] + #[cfg(all(target_os = "linux", not(feature = "unwind")))] fn _get_os_thread_id( &mut self, _python_thread_id: u64, @@ -398,7 +398,7 @@ impl PythonSpy { Ok(None) } - #[cfg(all(target_os = "linux", unwind))] + #[cfg(all(target_os = "linux", feature = "unwind"))] fn _get_os_thread_id( &mut self, python_thread_id: u64, @@ -483,7 +483,7 @@ impl PythonSpy { Ok(None) } - #[cfg(all(target_os = "linux", unwind))] + #[cfg(all(target_os = "linux", feature = "unwind"))] pub fn _get_pthread_id( &self, unwinder: &remoteprocess::Unwinder, diff --git a/src/utils.rs b/src/utils.rs index 1d8778bb..2ca1374f 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -1,4 +1,4 @@ -#[cfg(unwind)] +#[cfg(feature = "unwind")] pub fn resolve_filename(filename: &str, modulename: &str) -> Option { // check the filename first, if it exists use it use std::path::Path; diff --git a/tests/integration_test.rs b/tests/integration_test.rs index e136e35c..25ada35c 100644 --- a/tests/integration_test.rs +++ b/tests/integration_test.rs @@ -62,7 +62,7 @@ fn test_busy_loop() { assert!(traces[0].active); } -#[cfg(unwind)] +#[cfg(feature = "unwind")] #[test] fn test_thread_reuse() { // on linux we had an issue with the pthread -> native thread id caching