Skip to content

Commit 673926e

Browse files
committed
imp(agent): add state transition function
1 parent db91182 commit 673926e

File tree

1 file changed

+40
-25
lines changed

1 file changed

+40
-25
lines changed

src/pyroscope.rs

Lines changed: 40 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,22 @@ pub struct PyroscopeAgent<S: PyroscopeAgentState> {
221221
_state: PhantomData<S>,
222222
}
223223

224-
/// Gracefully stop the profiler.
224+
impl<S: PyroscopeAgentState> PyroscopeAgent<S> {
225+
/// Transition the PyroscopeAgent to a new state.
226+
fn transition<D: PyroscopeAgentState>(self) -> PyroscopeAgent<D> {
227+
PyroscopeAgent {
228+
timer: self.timer,
229+
session_manager: self.session_manager,
230+
tx: self.tx,
231+
handle: self.handle,
232+
running: self.running,
233+
backend: self.backend,
234+
config: self.config,
235+
_state: PhantomData,
236+
}
237+
}
238+
}
239+
225240
impl<S: PyroscopeAgentState> PyroscopeAgent<S> {
226241
/// Properly shutdown the agent.
227242
pub fn shutdown(mut self) {
@@ -344,18 +359,18 @@ impl PyroscopeAgent<PyroscopeAgentReady> {
344359
Ok(())
345360
}));
346361

347-
let agent_running = PyroscopeAgent {
348-
timer: self.timer,
349-
session_manager: self.session_manager,
350-
tx: self.tx,
351-
handle: self.handle,
352-
running: self.running,
353-
backend: self.backend,
354-
config: self.config,
355-
_state: PhantomData,
356-
};
357-
358-
Ok(agent_running)
362+
//let agent_running = PyroscopeAgent {
363+
//timer: self.timer,
364+
//session_manager: self.session_manager,
365+
//tx: self.tx,
366+
//handle: self.handle,
367+
//running: self.running,
368+
//backend: self.backend,
369+
//config: self.config,
370+
//_state: PhantomData,
371+
//};
372+
373+
Ok(self.transition())
359374
}
360375
}
361376
impl PyroscopeAgent<PyroscopeAgentRunning> {
@@ -386,18 +401,18 @@ impl PyroscopeAgent<PyroscopeAgentRunning> {
386401
// Create a clone of Backend
387402
//let backend = Arc::clone(&self.backend);
388403

389-
let agent_running = PyroscopeAgent {
390-
timer: self.timer,
391-
session_manager: self.session_manager,
392-
tx: self.tx,
393-
handle: self.handle,
394-
running: self.running,
395-
backend: self.backend,
396-
config: self.config,
397-
_state: PhantomData,
398-
};
399-
400-
Ok(agent_running)
404+
//let agent_running = PyroscopeAgent {
405+
//timer: self.timer,
406+
//session_manager: self.session_manager,
407+
//tx: self.tx,
408+
//handle: self.handle,
409+
//running: self.running,
410+
//backend: self.backend,
411+
//config: self.config,
412+
//_state: PhantomData,
413+
//};
414+
415+
Ok(self.transition())
401416
}
402417

403418
pub fn tag_wrapper(

0 commit comments

Comments
 (0)