Skip to content

Commit 129a851

Browse files
committed
imp(cli): add gil/idle/native pyspy arguments
1 parent 06159b2 commit 129a851

File tree

4 files changed

+64
-17
lines changed

4 files changed

+64
-17
lines changed

pyroscope_cli/cli/src/lib.rs

Lines changed: 52 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,13 @@ enum Commands {
9494
parse(try_from_str)
9595
)]
9696
pid: i32,
97+
#[clap(
98+
name = "rbspy_blocking",
99+
long = "rbspy-blocking",
100+
value_name = "RBSPY_BLOCKING",
101+
help = "enable blocking mode for rbspy"
102+
)]
103+
rbspy_blocking: bool,
97104
#[clap(
98105
name = "pyspy_blocking",
99106
long = "pyspy-blocking",
@@ -102,12 +109,26 @@ enum Commands {
102109
)]
103110
pyspy_blocking: bool,
104111
#[clap(
105-
name = "rbspy_blocking",
106-
long = "rbspy-blocking",
107-
value_name = "RBSPY_BLOCKING",
108-
help = "enable blocking mode for rbspy"
112+
name = "pyspy_idle",
113+
long = "pyspy-idle",
114+
value_name = "PYSPY_IDLE",
115+
help = "include idle threads for pyspy"
109116
)]
110-
rbspy_blocking: bool,
117+
pyspy_idle: bool,
118+
#[clap(
119+
name = "pyspy_gil",
120+
long = "pyspy-gil",
121+
value_name = "PYSPY_GIL",
122+
help = "enable GIL mode for pyspy"
123+
)]
124+
pyspy_gil: bool,
125+
#[clap(
126+
name = "pyspy_native",
127+
long = "pyspy-native",
128+
value_name = "PYSPY_NATIVE",
129+
help = "enable native extensions profiling for pyspy"
130+
)]
131+
pyspy_native: bool,
111132
#[clap(
112133
name = "sample_rate",
113134
long = "sample-rate",
@@ -211,6 +232,13 @@ enum Commands {
211232
//help = "disable permissions drop when ran under root. use this one if you want to run your command as root"
212233
//)]
213234
//no_root_drop: bool,
235+
#[clap(
236+
name = "rbspy_blocking",
237+
long = "rbspy-blocking",
238+
value_name = "RBSPY_BLOCKING",
239+
help = "enable blocking mode for rbspy"
240+
)]
241+
rbspy_blocking: bool,
214242
#[clap(
215243
name = "pyspy_blocking",
216244
long = "pyspy-blocking",
@@ -219,12 +247,26 @@ enum Commands {
219247
)]
220248
pyspy_blocking: bool,
221249
#[clap(
222-
name = "rbspy_blocking",
223-
long = "rbspy-blocking",
224-
value_name = "RBSPY_BLOCKING",
225-
help = "enable blocking mode for rbspy"
250+
name = "pyspy_idle",
251+
long = "pyspy-idle",
252+
value_name = "PYSPY_IDLE",
253+
help = "include idle threads for pyspy"
226254
)]
227-
rbspy_blocking: bool,
255+
pyspy_idle: bool,
256+
#[clap(
257+
name = "pyspy_gil",
258+
long = "pyspy-gil",
259+
value_name = "PYSPY_GIL",
260+
help = "enable GIL mode for pyspy"
261+
)]
262+
pyspy_gil: bool,
263+
#[clap(
264+
name = "pyspy_native",
265+
long = "pyspy-native",
266+
value_name = "PYSPY_NATIVE",
267+
help = "enable native extensions profiling for pyspy"
268+
)]
269+
pyspy_native: bool,
228270
#[clap(
229271
name = "sample_rate",
230272
long = "sample-rate",

pyroscope_cli/core/src/commands.rs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,6 @@
11
use utils::app_config::AppConfig;
22
use utils::error::{Error, Result};
3-
use utils::types::{LogLevel, Spy};
4-
5-
use pyroscope::PyroscopeAgent;
6-
use pyroscope_pyspy::{Pyspy, PyspyConfig};
7-
use pyroscope_rbspy::{Rbspy, RbspyConfig};
3+
use utils::types::Spy;
84

95
use ctrlc;
106
use std::sync::mpsc::channel;

pyroscope_cli/core/src/profiler.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,11 @@ impl Profiler {
2121
let sample_rate: u32 = AppConfig::get::<u32>("sample_rate")?;
2222

2323
// TODO: CLI should probably unify this into a single argument
24-
let pyspy_blocking: bool = AppConfig::get::<bool>("pyspy_blocking")?;
2524
let rbspy_blocking: bool = AppConfig::get::<bool>("rbspy_blocking")?;
25+
let pyspy_blocking: bool = AppConfig::get::<bool>("pyspy_blocking")?;
26+
let pyspy_idle: bool = AppConfig::get::<bool>("pyspy_idle")?;
27+
let pyspy_gil: bool = AppConfig::get::<bool>("pyspy_gil")?;
28+
let pyspy_native: bool = AppConfig::get::<bool>("pyspy_native")?;
2629

2730
let detect_subprocesses: bool = AppConfig::get::<bool>("detect_subprocesses")?;
2831

@@ -34,7 +37,10 @@ impl Profiler {
3437
let config = PyspyConfig::new(pid)
3538
.sample_rate(sample_rate)
3639
.lock_process(pyspy_blocking)
37-
.with_subprocesses(detect_subprocesses);
40+
.with_subprocesses(detect_subprocesses)
41+
.include_idle(pyspy_idle)
42+
.gil_only(pyspy_gil)
43+
.native(pyspy_native);
3844
let backend = Pyspy::new(config);
3945
PyroscopeAgent::builder(server_address, app_name)
4046
.backend(backend)

pyroscope_cli/src/resources/default_config.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@ log_level = "info"
33
no_logging = false
44
rbspy_blocking = false
55
pyspy_blocking = false
6+
pyspy_idle = false
7+
pyspy_gil = false
8+
pyspy_native = false
69
sample_rate = 100
710
server_address = "http://localhost:4040"
811
debug = false

0 commit comments

Comments
 (0)