11extern crate pyroscope;
22
3- use pyroscope:: { backend :: Tag , PyroscopeAgent , Result } ;
3+ use pyroscope:: { PyroscopeAgent , Result } ;
44use pyroscope_pprofrs:: { pprof_backend, PprofConfig } ;
55use std:: {
66 collections:: hash_map:: DefaultHasher ,
@@ -65,7 +65,7 @@ fn extra_rounds2(n: u64) -> u64 {
6565}
6666
6767fn main ( ) -> Result < ( ) > {
68- let mut agent = PyroscopeAgent :: builder ( "http://localhost:4040" , "example.multithread" )
68+ let agent = PyroscopeAgent :: builder ( "http://localhost:4040" , "example.multithread" )
6969 . tags ( [ ( "Host" , "Rust" ) ] . to_vec ( ) )
7070 . backend ( pprof_backend ( PprofConfig :: new ( ) . sample_rate ( 100 ) ) )
7171 . build ( ) ?;
@@ -78,9 +78,9 @@ fn main() -> Result<()> {
7878 println ! ( "Start Time: {}" , start) ;
7979
8080 // Start Agent
81- agent. start ( ) ?;
81+ let agent_running = agent. start ( ) ?;
8282
83- let ( add_tag, remove_tag) = agent . tag_wrapper ( ) ;
83+ let ( add_tag, remove_tag) = agent_running . tag_wrapper ( ) ;
8484
8585 let handle_1 = thread:: Builder :: new ( )
8686 . name ( "thread-1" . to_string ( ) )
@@ -91,7 +91,7 @@ fn main() -> Result<()> {
9191 remove_tag ( "extra" . to_string ( ) , "round-1" . to_string ( ) ) . unwrap ( ) ;
9292 } ) ?;
9393
94- let ( add_tag, remove_tag) = agent . tag_wrapper ( ) ;
94+ let ( add_tag, remove_tag) = agent_running . tag_wrapper ( ) ;
9595
9696 let handle_2 = thread:: Builder :: new ( )
9797 . name ( "thread-2" . to_string ( ) )
@@ -107,9 +107,10 @@ fn main() -> Result<()> {
107107 handle_2. join ( ) . unwrap ( ) ;
108108
109109 // Stop Agent
110- agent . stop ( ) ?;
110+ let agent_ready = agent_running . stop ( ) ?;
111111
112- drop ( agent) ;
112+ // Shutdown the Agent
113+ agent_ready. shutdown ( ) ;
113114
114115 // Show program exit time
115116 let exit = std:: time:: SystemTime :: now ( )
0 commit comments