@@ -134,7 +134,9 @@ impl PyroscopeAgentBuilder {
134134 /// ?;
135135 /// ```
136136 pub fn backend < T > ( self , backend : T ) -> Self
137- where T : ' static + Backend {
137+ where
138+ T : ' static + Backend ,
139+ {
138140 Self {
139141 backend : Arc :: new ( Mutex :: new ( backend) ) ,
140142 ..self
@@ -237,7 +239,10 @@ impl Drop for PyroscopeAgent {
237239 // Stop the SessionManager
238240 match self . session_manager . push ( SessionSignal :: Kill ) {
239241 Ok ( _) => log:: trace!( target: LOG_TAG , "Sent kill signal to SessionManager" ) ,
240- Err ( _) => log:: error!( target: LOG_TAG , "Error sending kill signal to SessionManager" ) ,
242+ Err ( _) => log:: error!(
243+ target: LOG_TAG ,
244+ "Error sending kill signal to SessionManager"
245+ ) ,
241246 }
242247
243248 if let Some ( handle) = self . session_manager . handle . take ( ) {
@@ -256,7 +261,7 @@ impl Drop for PyroscopeAgent {
256261 }
257262 }
258263
259- log:: debug!( target: LOG_TAG , "Agent Dropped" ) ;
264+ log:: debug!( target: LOG_TAG , "Agent Dropped" ) ;
260265 }
261266}
262267
@@ -272,7 +277,13 @@ impl PyroscopeAgent {
272277 PyroscopeAgentBuilder :: new ( url, application_name)
273278 }
274279
275- fn _start ( & mut self ) -> Result < ( ) > {
280+ /// Start profiling and sending data. The agent will keep running until stopped. The agent will send data to the server every 10s secondy.
281+ /// # Example
282+ /// ```ignore
283+ /// let agent = PyroscopeAgent::builder("http://localhost:8080", "my-app").build()?;
284+ /// agent.start()?;
285+ /// ```
286+ pub fn start ( & mut self ) -> Result < ( ) > {
276287 log:: debug!( target: LOG_TAG , "Starting" ) ;
277288
278289 // Create a clone of Backend
@@ -328,20 +339,15 @@ impl PyroscopeAgent {
328339 Ok ( ( ) )
329340 }
330341
331- /// Start profiling and sending data . The agent will keep running until stopped. The agent will send data to the server every 10s secondy .
342+ /// Stop the agent . The agent will stop profiling and send a last report to the server.
332343 /// # Example
333344 /// ```ignore
334345 /// let agent = PyroscopeAgent::builder("http://localhost:8080", "my-app").build()?;
335- /// agent.start();
346+ /// agent.start()?;
347+ /// // Expensive operation
348+ /// agent.stop();
336349 /// ```
337- pub fn start ( & mut self ) {
338- match self . _start ( ) {
339- Ok ( _) => log:: trace!( target: LOG_TAG , "Agent started" ) ,
340- Err ( _) => log:: error!( target: LOG_TAG , "Error starting agent" ) ,
341- }
342- }
343-
344- fn _stop ( & mut self ) -> Result < ( ) > {
350+ pub fn stop ( & mut self ) -> Result < ( ) > {
345351 log:: debug!( target: LOG_TAG , "Stopping" ) ;
346352 // get tx and send termination signal
347353 if let Some ( sender) = self . tx . take ( ) {
@@ -363,21 +369,6 @@ impl PyroscopeAgent {
363369 Ok ( ( ) )
364370 }
365371
366- /// Stop the agent. The agent will stop profiling and send a last report to the server.
367- /// # Example
368- /// ```ignore
369- /// let agent = PyroscopeAgent::builder("http://localhost:8080", "my-app").build()?;
370- /// agent.start()?;
371- /// // Expensive operation
372- /// agent.stop();
373- /// ```
374- pub fn stop ( & mut self ) {
375- match self . _stop ( ) {
376- Ok ( _) => log:: trace!( target: LOG_TAG , "Agent stopped" ) ,
377- Err ( _) => log:: error!( target: LOG_TAG , "Error stopping agent" ) ,
378- }
379- }
380-
381372 /// Add tags. This will restart the agent.
382373 /// # Example
383374 /// ```ignore
@@ -396,7 +387,7 @@ impl PyroscopeAgent {
396387 }
397388
398389 // Stop Agent
399- self . stop ( ) ;
390+ self . stop ( ) ? ;
400391
401392 // Convert &[(&str, &str)] to HashMap(String, String)
402393 let tags_hashmap: HashMap < String , String > = tags
@@ -409,7 +400,7 @@ impl PyroscopeAgent {
409400 self . config . tags . extend ( tags_hashmap) ;
410401
411402 // Restart Agent
412- self . start ( ) ;
403+ self . start ( ) ? ;
413404
414405 Ok ( ( ) )
415406 }
@@ -440,7 +431,7 @@ impl PyroscopeAgent {
440431 }
441432
442433 // Stop Agent
443- self . stop ( ) ;
434+ self . stop ( ) ? ;
444435
445436 // Iterate through every tag
446437 tags. iter ( ) . for_each ( |key| {
@@ -449,7 +440,7 @@ impl PyroscopeAgent {
449440 } ) ;
450441
451442 // Restart Agent
452- self . start ( ) ;
443+ self . start ( ) ? ;
453444
454445 Ok ( ( ) )
455446 }
0 commit comments