Skip to content

Commit 24518c5

Browse files
committed
refactor(cli): upgrade CLI to 0.5
1 parent 6a972f5 commit 24518c5

File tree

4 files changed

+86
-30
lines changed

4 files changed

+86
-30
lines changed

pyroscope_cli/Cargo.lock

Lines changed: 64 additions & 19 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyroscope_cli/Cargo.toml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,10 @@ slog-term = "2.8.0"
3333
slog-scope = "4.4.0"
3434
slog-async = "2.7.0"
3535
slog-stdlog = "4.1.0"
36-
pyroscope = { version = "0.4", path = "../" }
37-
pyroscope_pprofrs = {version = "0.1", path = "../pyroscope_backends/pyroscope_pprofrs" }
38-
pyroscope_rbspy = {version = "0.1", path = "../pyroscope_backends/pyroscope_rbspy" }
39-
pyroscope_pyspy = {version = "0.1", path = "../pyroscope_backends/pyroscope_pyspy" }
36+
pyroscope = { version = "0.5", path = "../" }
37+
pyroscope_pprofrs = {version = "0.2", path = "../pyroscope_backends/pyroscope_pprofrs" }
38+
pyroscope_rbspy = {version = "0.2", path = "../pyroscope_backends/pyroscope_rbspy" }
39+
pyroscope_pyspy = {version = "0.2", path = "../pyroscope_backends/pyroscope_pyspy" }
4040

4141
[dependencies.clap]
4242
version = "=3.1.6"

pyroscope_cli/src/core/profiler.rs

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
use pyroscope::PyroscopeAgent;
1+
use pyroscope::{
2+
pyroscope::{PyroscopeAgentReady, PyroscopeAgentRunning, PyroscopeAgentState},
3+
PyroscopeAgent,
4+
};
25
use pyroscope_pyspy::{pyspy_backend, PyspyConfig};
36
use pyroscope_rbspy::{rbspy_backend, RbspyConfig};
47

@@ -11,7 +14,7 @@ use crate::utils::{
1114
/// Wrapper for the `pyroscope` library and the `pyroscope_pyspy` and `pyroscope_rbspy` backends.
1215
#[derive(Debug, Default)]
1316
pub struct Profiler {
14-
agent: Option<PyroscopeAgent>,
17+
agent: Option<PyroscopeAgent<PyroscopeAgentRunning>>,
1518
}
1619

1720
impl Profiler {
@@ -36,7 +39,7 @@ impl Profiler {
3639
let tag_str = &AppConfig::get::<String>("tag")?;
3740
let tags = tags_to_array(tag_str)?;
3841

39-
let mut agent = match AppConfig::get::<Spy>("spy_name")? {
42+
let agent = match AppConfig::get::<Spy>("spy_name")? {
4043
Spy::Pyspy => {
4144
let config = PyspyConfig::new(pid)
4245
.sample_rate(sample_rate)
@@ -64,17 +67,18 @@ impl Profiler {
6467
}
6568
};
6669

67-
agent.start()?;
70+
let agent_running = agent.start()?;
6871

69-
self.agent = Some(agent);
72+
self.agent = Some(agent_running);
7073

7174
Ok(())
7275
}
7376

7477
/// Stops the `pyroscope` library agent and the backend.
7578
pub fn stop(self) -> Result<()> {
76-
if let Some(mut agent) = self.agent {
77-
agent.stop()?;
79+
if let Some(agent_running) = self.agent {
80+
let agent_ready = agent_running.stop()?;
81+
agent_ready.shutdown();
7882
}
7983

8084
Ok(())

src/pyroscope.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,12 +207,19 @@ impl PyroscopeAgentBuilder {
207207

208208
/// This trait is used to encode the state of the agent.
209209
pub trait PyroscopeAgentState {}
210+
210211
/// Marker struct for an Uninitialized state.
212+
#[derive(Debug)]
211213
pub struct PyroscopeAgentBare;
214+
212215
/// Marker struct for a Ready state.
216+
#[derive(Debug)]
213217
pub struct PyroscopeAgentReady;
218+
214219
/// Marker struct for a Running state.
220+
#[derive(Debug)]
215221
pub struct PyroscopeAgentRunning;
222+
216223
impl PyroscopeAgentState for PyroscopeAgentBare {}
217224
impl PyroscopeAgentState for PyroscopeAgentReady {}
218225
impl PyroscopeAgentState for PyroscopeAgentRunning {}

0 commit comments

Comments
 (0)