Skip to content

Commit c0b9bab

Browse files
committed
refactor(code): various minor refactoring
1 parent c96f97b commit c0b9bab

File tree

16 files changed

+60
-194
lines changed

16 files changed

+60
-194
lines changed

pyroscope_backends/pyroscope_pprofrs/src/lib.rs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
use std::collections::HashMap;
2-
use std::ffi::OsStr;
3-
41
use pprof::{ProfilerGuard, ProfilerGuardBuilder};
2+
use pyroscope::{
3+
backend::{Backend, Report, StackFrame, StackTrace, State},
4+
error::{PyroscopeError, Result},
5+
};
6+
use std::{collections::HashMap, ffi::OsStr};
57

6-
use pyroscope::backend::{Backend, Report, StackFrame, StackTrace, State};
7-
use pyroscope::error::{PyroscopeError, Result};
8-
8+
/// Pprof Configuration
99
#[derive(Debug)]
1010
pub struct PprofConfig {
1111
sample_rate: u32,
@@ -27,6 +27,7 @@ impl PprofConfig {
2727
}
2828
}
2929

30+
/// Pprof Backend
3031
#[derive(Default)]
3132
pub struct Pprof<'a> {
3233
config: PprofConfig,

pyroscope_backends/pyroscope_pyspy/src/lib.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
use py_spy::{config::Config, sampler::Sampler};
2-
32
use pyroscope::{
43
backend::{Backend, Report, StackFrame, StackTrace, State},
54
error::{PyroscopeError, Result},
@@ -21,7 +20,7 @@ pub struct PyspyConfig {
2120
sample_rate: u32,
2221
/// Lock Process while sampling
2322
lock_process: py_spy::config::LockingStrategy,
24-
/// Profiling duration. None for infinite.
23+
/// Profiling duration (None for infinite)
2524
time_limit: Option<core::time::Duration>,
2625
/// Include subprocesses
2726
with_subprocesses: bool,

pyroscope_backends/pyroscope_rbspy/src/lib.rs

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
1-
use pyroscope::backend::{Backend, Report, StackFrame, StackTrace, State};
2-
use pyroscope::error::{PyroscopeError, Result};
3-
1+
use pyroscope::{
2+
backend::{Backend, Report, StackFrame, StackTrace, State},
3+
error::{PyroscopeError, Result},
4+
};
45
use rbspy::sampler::Sampler;
5-
6-
use std::sync::mpsc::{channel, sync_channel, Receiver, Sender, SyncSender};
7-
use std::sync::{Arc, Mutex};
6+
use std::sync::{
7+
mpsc::{channel, sync_channel, Receiver, Sender, SyncSender},
8+
Arc, Mutex,
9+
};
810

911
/// Rbspy Configuration
1012
#[derive(Debug)]

pyroscope_cli/cli/src/lib.rs

Lines changed: 5 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,11 @@ use clap_complete::{
66
use std::path::PathBuf;
77

88
use core::commands;
9-
use utils::app_config::AppConfig;
10-
use utils::error::Result;
11-
use utils::types::{LogLevel, Spy};
9+
use utils::{
10+
app_config::AppConfig,
11+
error::Result,
12+
types::{LogLevel, Spy},
13+
};
1214

1315
#[derive(Parser, Debug)]
1416
#[clap(
@@ -54,14 +56,6 @@ enum Commands {
5456
help = "application name used when uploading profiling data"
5557
)]
5658
application_name: Option<String>,
57-
// TODO: placeholder for future implementation
58-
//#[clap(
59-
//name = "auth_token",
60-
//long = "auth-token",
61-
//value_name = "AUTH_TOKEN",
62-
//help = "authorization token used to upload profiling data"
63-
//)]
64-
//auth_token: Option<String>,
6559
#[clap(
6660
name = "detect_subprocesses",
6761
long = "detect-subprocesses",
@@ -165,24 +159,6 @@ enum Commands {
165159
help = "tag in key=value form. The flag may be specified multiple times"
166160
)]
167161
tag: Option<String>,
168-
// TODO: placeholder for future implementation
169-
//#[clap(
170-
//name = "upstream_request_timeout",
171-
//long = "upstream-request-timeout",
172-
//value_name = "UPSTREAM_REQUEST_TIMEOUT",
173-
//help = "profile upload timeout",
174-
//default_value = "10s"
175-
//)]
176-
//upstream_request_timeout: String,
177-
//#[clap(
178-
//name = "upstream_threads",
179-
//long = "upstream-threads",
180-
//value_name = "UPSTREAM_THREADS",
181-
//help = "number of upload threads",
182-
//parse(try_from_str),
183-
//default_value = "4"
184-
//)]
185-
//upstream_threads: u32,
186162
},
187163
#[clap(
188164
name = "exec",
@@ -200,14 +176,6 @@ enum Commands {
200176
help = "application name used when uploading profiling data"
201177
)]
202178
application_name: Option<String>,
203-
// TODO: placeholder for future implementation
204-
//#[clap(
205-
//name = "auth_token",
206-
//long = "auth-token",
207-
//value_name = "AUTH_TOKEN",
208-
//help = "authorization token used to upload profiling data"
209-
//)]
210-
//auth_token: Option<String>,
211179
#[clap(
212180
name = "detect_subprocesses",
213181
long = "detect-subprocesses",
@@ -233,13 +201,6 @@ enum Commands {
233201
takes_value = false
234202
)]
235203
no_logging: bool,
236-
//#[clap(
237-
//name = "no_root_drop",
238-
//long = "no-root-drop",
239-
//value_name = "NO_ROOT_DROP",
240-
//help = "disable permissions drop when ran under root. use this one if you want to run your command as root"
241-
//)]
242-
//no_root_drop: bool,
243204
#[clap(
244205
name = "rbspy_blocking",
245206
long = "rbspy-blocking",
@@ -309,24 +270,6 @@ enum Commands {
309270
help = "tag in key=value form. The flag may be specified multiple times"
310271
)]
311272
tag: Option<String>,
312-
// TODO: placeholder for future implementation
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,
330273
#[clap(
331274
name = "user_name",
332275
long = "user-name",

pyroscope_cli/core/src/commands.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
use utils::app_config::AppConfig;
2-
use utils::error::{Error, Result};
3-
use utils::types::Spy;
4-
51
use ctrlc;
62
use std::sync::mpsc::channel;
73

8-
use crate::executor::Executor;
9-
use crate::profiler::Profiler;
4+
use crate::{executor::Executor, profiler::Profiler};
5+
use utils::{
6+
app_config::AppConfig,
7+
error::{Error, Result},
8+
types::Spy,
9+
};
1010

1111
/// exec command
1212
pub fn exec() -> Result<()> {

pyroscope_cli/core/src/executor.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
use duct::cmd;
22
use std::os::unix::process::CommandExt;
3+
34
use utils::error::{Error, Result};
45

56
pub struct Executor<'a> {

pyroscope_cli/core/src/profiler.rs

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

811
#[derive(Debug, Default)]
912
pub struct Profiler {

pyroscope_cli/src/main.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,7 @@ use human_panic::setup_panic;
44
#[cfg(debug_assertions)]
55
extern crate better_panic;
66

7-
use utils::app_config::AppConfig;
8-
use utils::error::Result;
7+
use utils::{app_config::AppConfig, error::Result};
98

109
/// The main entry point of the application.
1110
fn main() -> Result<()> {

pyroscope_cli/utils/src/app_config.rs

Lines changed: 0 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,6 @@ pub struct AppConfig {
3232
pub sample_rate: Option<u32>,
3333
pub server_address: Option<String>,
3434
pub tag: Option<String>,
35-
// TODO: placeholder for future implementation
36-
//pub upstream_request_timeout: Option<String>,
37-
//pub upstream_threads: Option<u32>,
38-
//pub auth_token: Option<String>,
3935
pub user_name: Option<u32>,
4036
pub group_name: Option<u32>,
4137
pub command: Option<String>,
@@ -80,15 +76,9 @@ impl AppConfig {
8076
}
8177
}
8278
if sub_connect.is_present("no_logging") {
83-
//if let Some(no_logging) = sub_connect.value_of("no_logging") {
84-
//AppConfig::set("no_logging", no_logging)?;
85-
//}
8679
AppConfig::set("no_logging", "true")?;
8780
}
8881
if sub_connect.is_present("pyspy_blocking") {
89-
//if let Some(pyspy_blocking) = sub_connect.value_of("pyspy_blocking") {
90-
//AppConfig::set("pyspy_blocking", pyspy_blocking)?;
91-
//}
9282
AppConfig::set("pyspy_blocking", "true")?;
9383
}
9484
if sub_connect.is_present("pyspy_idle") {
@@ -101,9 +91,6 @@ impl AppConfig {
10191
AppConfig::set("pyspy_native", "true")?;
10292
}
10393
if sub_connect.is_present("rbspy_blocking") {
104-
//if let Some(rbspy_blocking) = sub_connect.value_of("rbspy_blocking") {
105-
//AppConfig::set("rbspy_blocking", rbspy_blocking)?;
106-
//}
10794
AppConfig::set("rbspy_blocking", "true")?;
10895
}
10996
if sub_connect.is_present("sample_rate") {
@@ -124,34 +111,12 @@ impl AppConfig {
124111
AppConfig::set("tag", tag.as_str())?;
125112
}
126113
}
127-
// TODO: placeholder for future implementation
128-
//if sub_connect.is_present("upstream_request_timeout") {
129-
//if let Some(upstream_request_timeout) =
130-
//sub_connect.value_of("upstream_request_timeout")
131-
//{
132-
//AppConfig::set("upstream_request_timeout", upstream_request_timeout)?;
133-
//}
134-
//}
135-
//if sub_connect.is_present("upstream_threads") {
136-
//if let Some(upstream_threads) = sub_connect.value_of("upstream_threads") {
137-
//AppConfig::set("upstream_threads", upstream_threads)?;
138-
//}
139-
//}
140114
if sub_connect.is_present("application_name") {
141115
if let Some(application_name) = sub_connect.value_of("application_name") {
142116
AppConfig::set("application_name", application_name)?;
143117
}
144118
}
145-
// TODO: placeholder for future implementation
146-
//if sub_connect.is_present("auth_token") {
147-
//if let Some(auth_token) = sub_connect.value_of("auth_token") {
148-
//AppConfig::set("auth_token", auth_token)?;
149-
//}
150-
//}
151119
if sub_connect.is_present("detect_subprocesses") {
152-
//if let Some(detect_subprocesses) = sub_connect.value_of("detect_subprocesses") {
153-
//AppConfig::set("detect_subprocesses", detect_subprocesses)?;
154-
//}
155120
AppConfig::set("detect_subprocesses", "true")?;
156121
}
157122
if sub_connect.is_present("pid") {
@@ -179,15 +144,9 @@ impl AppConfig {
179144
}
180145
}
181146
if sub_exec.is_present("no_logging") {
182-
//if let Some(no_logging) = sub_exec.value_of("no_logging") {
183-
//AppConfig::set("no_logging", no_logging)?;
184-
//}
185147
AppConfig::set("no_logging", "true")?;
186148
}
187149
if sub_exec.is_present("pyspy_blocking") {
188-
//if let Some(pyspy_blocking) = sub_exec.value_of("pyspy_blocking") {
189-
//AppConfig::set("pyspy_blocking", pyspy_blocking)?;
190-
//}
191150
AppConfig::set("pyspy_blocking", "true")?;
192151
}
193152
if sub_exec.is_present("pyspy_idle") {
@@ -200,9 +159,6 @@ impl AppConfig {
200159
AppConfig::set("pyspy_native", "true")?;
201160
}
202161
if sub_exec.is_present("rbspy_blocking") {
203-
//if let Some(rbspy_blocking) = sub_exec.value_of("rbspy_blocking") {
204-
//AppConfig::set("rbspy_blocking", rbspy_blocking)?;
205-
//}
206162
AppConfig::set("rbspy_blocking", "true")?;
207163
}
208164
if sub_exec.is_present("sample_rate") {
@@ -223,34 +179,12 @@ impl AppConfig {
223179
AppConfig::set("tag", tag.as_str())?;
224180
}
225181
}
226-
// TODO: placeholder for future implementation
227-
//if sub_exec.is_present("upstream_request_timeout") {
228-
//if let Some(upstream_request_timeout) =
229-
//sub_exec.value_of("upstream_request_timeout")
230-
//{
231-
//AppConfig::set("upstream_request_timeout", upstream_request_timeout)?;
232-
//}
233-
//}
234-
//if sub_exec.is_present("upstream_threads") {
235-
//if let Some(upstream_threads) = sub_exec.value_of("upstream_threads") {
236-
//AppConfig::set("upstream_threads", upstream_threads)?;
237-
//}
238-
//}
239182
if sub_exec.is_present("application_name") {
240183
if let Some(application_name) = sub_exec.value_of("application_name") {
241184
AppConfig::set("application_name", application_name)?;
242185
}
243186
}
244-
// TODO: placeholder for future implementation
245-
//if sub_exec.is_present("auth_token") {
246-
//if let Some(auth_token) = sub_exec.value_of("auth_token") {
247-
//AppConfig::set("auth_token", auth_token)?;
248-
//}
249-
//}
250187
if sub_exec.is_present("detect_subprocesses") {
251-
//if let Some(detect_subprocesses) = sub_exec.value_of("detect_subprocesses") {
252-
//AppConfig::set("detect_subprocesses", detect_subprocesses)?;
253-
//}
254188
AppConfig::set("detect_subprocesses", "true")?;
255189
}
256190
if sub_exec.is_present("spy_name") {

pyroscope_cli/utils/src/logger.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
1-
use slog::o;
2-
use slog::Drain;
1+
use slog::{o, Drain};
32

4-
use super::app_config::AppConfig;
5-
use super::error::Result;
6-
use super::types::LogLevel;
3+
use super::{app_config::AppConfig, error::Result, types::LogLevel};
74

85
pub fn setup_logging() -> Result<slog_scope::GlobalLoggerGuard> {
96
// Setup Logging

0 commit comments

Comments
 (0)