From 300c2af830506ff646f837d3e6758a9ddbbc5c3b Mon Sep 17 00:00:00 2001 From: Yonatan Goldschmidt Date: Sat, 20 Mar 2021 00:39:25 +0200 Subject: [PATCH 1/2] Exit with an error if --gil but we failed to get necessary addrs/offsets Previously we'd just emit a warning, which is less noticeable; and the result of a --gil run where without the needed information is going to empty, anyway. --- src/python_spy.rs | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/src/python_spy.rs b/src/python_spy.rs index c50ee01b..c35646a4 100644 --- a/src/python_spy.rs +++ b/src/python_spy.rs @@ -45,6 +45,14 @@ pub struct PythonSpy { pub dockerized: bool } +fn exit_if_gil(config: &Config, version: &Version, msg: &str) { + if config.gil_only { + eprintln!("Cannot detect GIL holding in version '{}' on the current platform (reason: {})", version, msg); + eprintln!("Please open an issue in https://github.com/benfred/py-spy with the Python version and your platform."); + std::process::exit(1); + } +} + impl PythonSpy { /// Constructs a new PythonSpy object. pub fn new(pid: Pid, config: &Config) -> Result { @@ -76,12 +84,12 @@ impl PythonSpy { addr, offset); addr as usize + offset } else { - warn!("Unknown pyruntime.gilstate.tstate_current offset for version {:?}", version); + exit_if_gil(config, &version, "unknown pyruntime.gilstate.tstate_current offset"); 0 } }, None => { - warn!("Failed to find _PyRuntime symbol - won't be able to detect GIL usage"); + exit_if_gil(config, &version, "failed to find _PyRuntime symbol"); 0 } } @@ -93,7 +101,7 @@ impl PythonSpy { addr as usize }, None => { - warn!("Failed to find _PyThreadState_Current symbol - won't be able to detect GIL usage"); + exit_if_gil(config, &version, "failed to find _PyThreadState_Current symbol"); 0 } } From 0a8fca2afff55c2a1f6727df8ecdfd8460b486b8 Mon Sep 17 00:00:00 2001 From: Ben Frederickson Date: Sun, 21 Mar 2021 09:31:31 -0700 Subject: [PATCH 2/2] Update src/python_spy.rs --- src/python_spy.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/python_spy.rs b/src/python_spy.rs index c35646a4..1eb55dc6 100644 --- a/src/python_spy.rs +++ b/src/python_spy.rs @@ -51,6 +51,7 @@ fn exit_if_gil(config: &Config, version: &Version, msg: &str) { eprintln!("Please open an issue in https://github.com/benfred/py-spy with the Python version and your platform."); std::process::exit(1); } + warn!("Unable to detect GIL usage: {}", msg); } impl PythonSpy {