@@ -40,6 +40,8 @@ struct S3BucketArgs {
4040}
4141
4242/// Simple program to test the profiler agent
43+ ///
44+ /// This program is intended for test purposes ONLY.
4345#[ derive( Debug , Parser ) ]
4446#[ command( group(
4547 ArgGroup :: new( "options" )
@@ -62,6 +64,9 @@ struct Args {
6264 worker_threads : Option < usize > ,
6365 #[ arg( long) ]
6466 native_mem : Option < String > ,
67+ /// Use the spawn_thread API instead of the Tokio API (does not demonstrate stopping)
68+ #[ arg( long) ]
69+ spawn_into_thread : bool ,
6570}
6671
6772impl Args {
@@ -95,6 +100,16 @@ pub fn main() -> anyhow::Result<()> {
95100 rt. block_on ( main_internal ( args) )
96101}
97102
103+ async fn run_slow ( args : & Args ) {
104+ if let Some ( timeout) = args. duration {
105+ tokio:: time:: timeout ( timeout, slow:: run ( ) )
106+ . await
107+ . unwrap_err ( ) ;
108+ } else {
109+ slow:: run ( ) . await ;
110+ }
111+ }
112+
98113async fn main_internal ( args : Args ) -> Result < ( ) , anyhow:: Error > {
99114 set_up_tracing ( ) ;
100115 tracing:: info!( "main started" ) ;
@@ -104,7 +119,7 @@ async fn main_internal(args: Args) -> Result<(), anyhow::Error> {
104119 let profiler = match ( & args. local , args. s3_bucket_args ( ) ) {
105120 ( Some ( local) , S3BucketArgs { .. } ) => profiler
106121 . with_reporter ( LocalReporter :: new ( local) )
107- . with_custom_agent_metadata ( AgentMetadata :: Other ) ,
122+ . with_custom_agent_metadata ( AgentMetadata :: NoMetadata ) ,
108123 #[ cfg( feature = "s3-no-defaults" ) ]
109124 (
110125 _,
@@ -133,19 +148,21 @@ async fn main_internal(args: Args) -> Result<(), anyhow::Error> {
133148 . with_profiler_options ( profiler_options)
134149 . build ( ) ;
135150
136- tracing:: info!( "starting profiler" ) ;
137- let handle = profiler. spawn_controllable ( ) ?;
138- tracing:: info!( "profiler started" ) ;
139-
140- if let Some ( timeout) = args. duration {
141- tokio:: time:: timeout ( timeout, slow:: run ( ) )
142- . await
143- . unwrap_err ( ) ;
151+ if args. spawn_into_thread {
152+ tracing:: info!( "starting profiler" ) ;
153+ std:: thread:: spawn ( move || {
154+ profiler. spawn_thread ( ) . unwrap ( ) ;
155+ } ) ;
156+ run_slow ( & args) . await ;
144157 } else {
145- slow:: run ( ) . await ;
146- }
158+ tracing:: info!( "starting profiler" ) ;
159+ let handle = profiler. spawn_controllable ( ) ?;
160+ tracing:: info!( "profiler started" ) ;
147161
148- handle. stop ( ) . await ;
162+ run_slow ( & args) . await ;
163+
164+ handle. stop ( ) . await ;
165+ }
149166
150167 Ok ( ( ) )
151168}
0 commit comments