@@ -191,7 +191,11 @@ impl PyroscopeAgentBuilder {
191191 session_manager,
192192 tx : None ,
193193 handle : None ,
194- running : Arc :: new ( ( Mutex :: new ( false ) , Condvar :: new ( ) ) ) ,
194+ running : Arc :: new ( (
195+ #[ allow( clippy:: mutex_atomic) ]
196+ Mutex :: new ( false ) ,
197+ Condvar :: new ( ) ,
198+ ) ) ,
195199 _state : PhantomData ,
196200 } )
197201 }
@@ -208,16 +212,21 @@ impl PyroscopeAgentState for PyroscopeAgentRunning {}
208212/// PyroscopeAgent is the main object of the library. It is used to start and stop the profiler, schedule the timer, and send the profiler data to the server.
209213#[ derive( Debug ) ]
210214pub struct PyroscopeAgent < S : PyroscopeAgentState > {
215+ /// Instance of the Timer
211216 timer : Timer ,
217+ /// Instance of the SessionManager
212218 session_manager : SessionManager ,
219+ /// Channel sender for the timer thread
213220 tx : Option < Sender < TimerSignal > > ,
221+ /// Handle to the thread that runs the Pyroscope Agent
214222 handle : Option < JoinHandle < Result < ( ) > > > ,
223+ /// A structure to signal thread termination
215224 running : Arc < ( Mutex < bool > , Condvar ) > ,
216-
217225 /// Profiler backend
218226 pub backend : BackendImpl < BackendReady > ,
219227 /// Configuration Object
220228 pub config : PyroscopeConfig ,
229+ /// PyroscopeAgent State
221230 _state : PhantomData < S > ,
222231}
223232
@@ -280,7 +289,7 @@ impl<S: PyroscopeAgentState> PyroscopeAgent<S> {
280289 }
281290 }
282291
283- log:: debug!( target: LOG_TAG , "Agent Dropped " ) ;
292+ log:: debug!( target: LOG_TAG , "Agent Shutdown " ) ;
284293 }
285294}
286295
@@ -387,7 +396,8 @@ impl PyroscopeAgent<PyroscopeAgentRunning> {
387396 // get tx and send termination signal
388397 if let Some ( sender) = self . tx . take ( ) {
389398 // Send last session
390- let _ = sender. send ( TimerSignal :: NextSnapshot ( get_time_range ( 0 ) ?. until ) ) ;
399+ sender. send ( TimerSignal :: NextSnapshot ( get_time_range ( 0 ) ?. until ) ) ?;
400+ // Terminate PyroscopeAgent internal thread
391401 sender. send ( TimerSignal :: Terminate ) ?;
392402 } else {
393403 log:: error!( "PyroscopeAgent - Missing sender" )
@@ -398,20 +408,6 @@ impl PyroscopeAgent<PyroscopeAgentRunning> {
398408 let ( lock, cvar) = & * pair;
399409 let _guard = cvar. wait_while ( lock. lock ( ) ?, |running| * running) ?;
400410
401- // Create a clone of Backend
402- //let backend = Arc::clone(&self.backend);
403-
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-
415411 Ok ( self . transition ( ) )
416412 }
417413
@@ -444,29 +440,28 @@ impl PyroscopeAgent<PyroscopeAgentRunning> {
444440 )
445441 }
446442
447- // TODO: change &mut self to &self
448- pub fn add_global_tag ( & mut self , tag : Tag ) -> Result < ( ) > {
443+ pub fn add_global_tag ( & self , tag : Tag ) -> Result < ( ) > {
449444 let rule = Rule :: GlobalTag ( tag) ;
450445 self . backend . add_rule ( rule) ?;
451446
452447 Ok ( ( ) )
453448 }
454449
455- pub fn remove_global_tag ( & mut self , tag : Tag ) -> Result < ( ) > {
450+ pub fn remove_global_tag ( & self , tag : Tag ) -> Result < ( ) > {
456451 let rule = Rule :: GlobalTag ( tag) ;
457452 self . backend . remove_rule ( rule) ?;
458453
459454 Ok ( ( ) )
460455 }
461456
462- pub fn add_thread_tag ( & mut self , thread_id : u64 , tag : Tag ) -> Result < ( ) > {
457+ pub fn add_thread_tag ( & self , thread_id : u64 , tag : Tag ) -> Result < ( ) > {
463458 let rule = Rule :: ThreadTag ( thread_id, tag) ;
464459 self . backend . add_rule ( rule) ?;
465460
466461 Ok ( ( ) )
467462 }
468463
469- pub fn remove_thread_tag ( & mut self , thread_id : u64 , tag : Tag ) -> Result < ( ) > {
464+ pub fn remove_thread_tag ( & self , thread_id : u64 , tag : Tag ) -> Result < ( ) > {
470465 let rule = Rule :: ThreadTag ( thread_id, tag) ;
471466 self . backend . remove_rule ( rule) ?;
472467
0 commit comments