Skip to content

Commit 9f53527

Browse files
committed
wip: cli
1 parent 49b4f64 commit 9f53527

File tree

9 files changed

+204
-321
lines changed

9 files changed

+204
-321
lines changed

pyroscope_cli/cli/src/lib.rs

Lines changed: 54 additions & 226 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use clap::{AppSettings, ArgEnum, ArgMatches, IntoApp, Parser, Subcommand};
1+
use clap::{AppSettings, IntoApp, Parser, Subcommand};
22
use clap_complete::{
33
generate,
44
shells::{Bash, Fish, PowerShell, Zsh},
@@ -8,7 +8,7 @@ use std::path::PathBuf;
88
use core::commands;
99
use utils::app_config::AppConfig;
1010
use utils::error::Result;
11-
use utils::types::{LogLevel, OutputFormat, Spy};
11+
use utils::types::{LogLevel, Spy};
1212

1313
#[derive(Parser, Debug)]
1414
#[clap(
@@ -33,179 +33,6 @@ pub struct Cli {
3333
/// Pyroscope CLI Commands
3434
#[derive(Subcommand, Debug)]
3535
enum Commands {
36-
#[clap(
37-
name = "adhoc",
38-
about = "Profile a process and save the results to be used in adhoc mode",
39-
long_about = "
40-
adhoc command is a complete toolset to profile a process and save the profiling
41-
results.
42-
These results are generated in two different ways:
43-
- Pyroscope stores the profiling data in its native format and data directory
44-
by default. These profiles are then available for analysis using pyroscope UI
45-
(the 'Adhoc Profiling' section), which requires a running pyroscope server.
46-
This output can be disabled with '--no-json-output'.
47-
- Pyroscope also generates profiling data in an external format.
48-
Depending on the number of generated profiles, pyroscope will generate either
49-
a file or a directory, in the directory where pyroscope is run from.
50-
The currently supported formats are standalone HTML (which can then be
51-
shared or directly open in a browser to analyze), pprof or collapsed
52-
(these last two can then be shared and used with either pyroscope UI or other
53-
tooling). The flag '--output-format' is used to specify this format.
54-
There are multiple ways to gather the profiling data, and not all of them are
55-
available for all the languages.
56-
Which way is better depends on several factors: what the language supports,
57-
how the profiled process is launched, and how the profiled process provides
58-
the profiled data.
59-
The different supported ways are:
60-
- exec. In this case, pyroscope creates a different process for the profiled
61-
program and uses a spy to directly gather profiling data. It's a useful way
62-
to profile a whole execution of some program that has no other pyroscope
63-
integration or way of exposing profiling data.
64-
It's the default mode for languages with a supported spy when either the spy
65-
name is specified (through '--spy-name' flag) or when the spyname is
66-
autodetected.
67-
- connect. Similar to exec, pyroscope uses a spy to gather profiling data,
68-
but instead of creating a new profiled process, it spies an already running
69-
process, indicated through '--pid' flag.
70-
- push. In this case, pyroscope creates a different process for the profiled
71-
program and launches an HTTP server with an ingestion endpoint. It's useful
72-
to profile programs already integrated with Pyroscope using its HTTP API.
73-
Push mode is used by default when no spy is detected and no '--url' flag is
74-
provided. It can also be override the default exec mode with the '--push' flag.
75-
- pull. In this case, pyroscope periodically connects to the URL specified
76-
thorugh '--url' where it tries to retrieve profiling data in any of the
77-
supported formats. In this case arguments are optional, and if provided,
78-
they are used to launch a new process before polling the URL.
79-
"
80-
)]
81-
Adhoc {
82-
#[clap(
83-
name = "application_name",
84-
long = "application-name",
85-
value_name = "APPLICATION_NAME",
86-
help = "application name used when uploading profiling data"
87-
)]
88-
application_name: Option<String>,
89-
#[clap(
90-
name = "data_path",
91-
long = "data-path",
92-
value_name = "DATA_PATH",
93-
help = "directory where pyroscope stores adhoc profiles"
94-
)]
95-
data_path: String,
96-
#[clap(
97-
name = "detect_subprocesses",
98-
long = "detect-subprocesses",
99-
value_name = "DECTECT_SUBPROCESSES",
100-
help = "keep track of and profile subprocesses of the main process"
101-
)]
102-
detect_subprocesses: bool,
103-
#[clap(
104-
name = "duration",
105-
long = "duration",
106-
value_name = "DURATION",
107-
help = "duration of the profiling session, which is the whole execution of the profiled process by default",
108-
default_value = "0s"
109-
)]
110-
duration: String,
111-
#[clap(
112-
name = "log_level",
113-
short,
114-
long = "log-level",
115-
value_name = "LOG_LEVEL",
116-
help = "",
117-
default_value = "info"
118-
)]
119-
log_level: LogLevel,
120-
#[clap(
121-
name = "no_logging",
122-
long = "no-logging",
123-
value_name = "NO_LOGGING",
124-
help = "disable logging from pyroscope"
125-
)]
126-
no_logging: bool,
127-
#[clap(
128-
name = "max_nodes_render",
129-
long = "max-nodes-render",
130-
value_name = "MAX_NODES_RENDER",
131-
help = "max number of nodes used to display data on the frontend",
132-
parse(try_from_str),
133-
default_value = "8192"
134-
)]
135-
max_nodes_render: u32,
136-
#[clap(
137-
name = "max_nodes_serialization",
138-
long = "max-nodes-serialization",
139-
value_name = "MAX_NODES_SERIALIZATION",
140-
help = "max number of nodes used when saving profiles to disk",
141-
parse(try_from_str),
142-
default_value = "2048"
143-
)]
144-
max_nodes_serialization: u32,
145-
#[clap(
146-
name = "no_json_output",
147-
long = "no-json-output",
148-
value_name = "NO_JSON_OUTPUT",
149-
help = "disable generating native JSON file(s) in pyroscope data directory"
150-
)]
151-
no_json_output: bool,
152-
#[clap(
153-
name = "output_format",
154-
long = "output-format",
155-
value_name = "OUTPUT_FORMAT",
156-
help = "format to export profiling data",
157-
default_value = "html"
158-
)]
159-
output_format: OutputFormat,
160-
#[clap(
161-
name = "pid",
162-
long = "pid",
163-
value_name = "PID",
164-
help = "PID of the process you want to profile. Pass -1 to profile the whole system (only supported by ebpfspy)",
165-
parse(try_from_str),
166-
default_value = "0"
167-
)]
168-
pid: i32,
169-
#[clap(
170-
name = "push",
171-
long = "push",
172-
value_name = "PUSH",
173-
help = "use push mode, exposing an ingestion endpoint for the profiled program to use"
174-
)]
175-
push: bool,
176-
#[clap(
177-
name = "pyspy_blocking",
178-
long = "pyspy-blocking",
179-
value_name = "PYSPY_BLOCKING",
180-
help = "enable blocking mode for pyspy"
181-
)]
182-
pyspy_blocking: bool,
183-
#[clap(
184-
name = "rbspy_blocking",
185-
long = "rbspy-blocking",
186-
value_name = "RBSPY_BLOCKING",
187-
help = "enable blocking mode for rbspy"
188-
)]
189-
rbspy_blocking: bool,
190-
#[clap(
191-
name = "sample_rate",
192-
long = "sample-rate",
193-
value_name = "SAMPLE_RATE",
194-
help = "sample rate for the profiler in Hz. 100 means reading 100 times per second",
195-
default_value = "100"
196-
)]
197-
sample_rate: i32,
198-
#[clap(
199-
name = "spy_name",
200-
long = "spy-name",
201-
value_name = "SPY_NAME",
202-
help = "name of the profiler to use",
203-
default_value = "auto"
204-
)]
205-
spy_name: Spy,
206-
#[clap(long, value_name = "URL", help = "URL to gather profiling data from")]
207-
url: Option<String>,
208-
},
20936
#[clap(
21037
name = "completion",
21138
about = "Generate the autocompletion script for pyroscope for the specified shell. See each sub-command's help for details on how to use the generated script.",
@@ -228,13 +55,14 @@ they are used to launch a new process before polling the URL.
22855
help = "application name used when uploading profiling data"
22956
)]
23057
application_name: Option<String>,
231-
#[clap(
232-
name = "auth_token",
233-
long = "auth-token",
234-
value_name = "AUTH_TOKEN",
235-
help = "authorization token used to upload profiling data"
236-
)]
237-
auth_token: Option<String>,
58+
// TODO: placeholder for future implementation
59+
//#[clap(
60+
//name = "auth_token",
61+
//long = "auth-token",
62+
//value_name = "AUTH_TOKEN",
63+
//help = "authorization token used to upload profiling data"
64+
//)]
65+
//auth_token: Option<String>,
23866
#[clap(
23967
name = "detect_subprocesses",
24068
long = "detect-subprocesses",
@@ -310,23 +138,24 @@ they are used to launch a new process before polling the URL.
310138
help = "tag in key=value form. The flag may be specified multiple times"
311139
)]
312140
tag: Option<String>,
313-
#[clap(
314-
name = "upstream_request_timeout",
315-
long = "upstream-request-timeout",
316-
value_name = "UPSTREAM_REQUEST_TIMEOUT",
317-
help = "profile upload timeout",
318-
default_value = "10s"
319-
)]
320-
upstream_request_timeout: String,
321-
#[clap(
322-
name = "upstream_threads",
323-
long = "upstream-threads",
324-
value_name = "UPSTREAM_THREADS",
325-
help = "number of upload threads",
326-
parse(try_from_str),
327-
default_value = "4"
328-
)]
329-
upstream_threads: u32,
141+
// TODO: placeholder for future implementation
142+
//#[clap(
143+
//name = "upstream_request_timeout",
144+
//long = "upstream-request-timeout",
145+
//value_name = "UPSTREAM_REQUEST_TIMEOUT",
146+
//help = "profile upload timeout",
147+
//default_value = "10s"
148+
//)]
149+
//upstream_request_timeout: String,
150+
//#[clap(
151+
//name = "upstream_threads",
152+
//long = "upstream-threads",
153+
//value_name = "UPSTREAM_THREADS",
154+
//help = "number of upload threads",
155+
//parse(try_from_str),
156+
//default_value = "4"
157+
//)]
158+
//upstream_threads: u32,
330159
},
331160
#[clap(
332161
name = "exec",
@@ -344,12 +173,13 @@ they are used to launch a new process before polling the URL.
344173
help = "application name used when uploading profiling data"
345174
)]
346175
application_name: Option<String>,
347-
#[clap(
348-
name = "auth_token",
349-
long = "auth-token",
350-
value_name = "AUTH_TOKEN",
351-
help = "authorization token used to upload profiling data"
352-
)]
176+
// TODO: placeholder for future implementation
177+
//#[clap(
178+
//name = "auth_token",
179+
//long = "auth-token",
180+
//value_name = "AUTH_TOKEN",
181+
//help = "authorization token used to upload profiling data"
182+
//)]
353183
auth_token: Option<String>,
354184
#[clap(
355185
name = "detect_subprocesses",
@@ -432,23 +262,24 @@ they are used to launch a new process before polling the URL.
432262
help = "tag in key=value form. The flag may be specified multiple times"
433263
)]
434264
tag: Option<String>,
435-
#[clap(
436-
name = "upstream_request_timeout",
437-
long = "upstream-request-timeout",
438-
value_name = "UPSTREAM_REQUEST_TIMEOUT",
439-
help = "profile upload timeout",
440-
default_value = "10s"
441-
)]
442-
upstream_request_timeout: String,
443-
#[clap(
444-
name = "upstream_threads",
445-
long = "upstream-threads",
446-
value_name = "UPSTREAM_THREADS",
447-
help = "number of upload threads",
448-
parse(try_from_str),
449-
default_value = "4"
450-
)]
451-
upstream_threads: u32,
265+
// TODO: placeholder for future implementation
266+
//#[clap(
267+
//name = "upstream_request_timeout",
268+
//long = "upstream-request-timeout",
269+
//value_name = "UPSTREAM_REQUEST_TIMEOUT",
270+
//help = "profile upload timeout",
271+
//default_value = "10s"
272+
//)]
273+
//upstream_request_timeout: String,
274+
//#[clap(
275+
//name = "upstream_threads",
276+
//long = "upstream-threads",
277+
//value_name = "UPSTREAM_THREADS",
278+
//help = "number of upload threads",
279+
//parse(try_from_str),
280+
//default_value = "4"
281+
//)]
282+
//upstream_threads: u32,
452283
#[clap(
453284
name = "user_name",
454285
long = "user-name",
@@ -493,10 +324,7 @@ pub fn cli_match() -> Result<()> {
493324

494325
// Execute the subcommand
495326
match &cli.command {
496-
Commands::Adhoc { .. } => {
497-
commands::adhoc()?;
498-
}
499-
Commands::Exec { server_address, .. } => {
327+
Commands::Exec { .. } => {
500328
commands::exec()?;
501329
}
502330
Commands::Connect { .. } => {

pyroscope_cli/core/Cargo.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@ edition = "2021"
88
[dependencies]
99
utils = { path = "../utils" }
1010
pyroscope = { path = "../../" }
11+
pyroscope_pprofrs = { path = "../../pyroscope_backends/pyroscope_pprofrs" }
12+
pyroscope_rbspy = { path = "../../pyroscope_backends/pyroscope_rbspy" }
13+
pyroscope_pyspy = { path = "../../pyroscope_backends/pyroscope_pyspy" }
1114
log = "0.4.14"
1215
ctrlc = "3.2.1"
1316
duct = "0.13.5"
17+
names= "0.13.0"

0 commit comments

Comments
 (0)