Skip to content

Commit 59b42a7

Browse files
author
Ariel Ben-Yehuda
committed
feat: allow running in its own Tokio runtime
Fixes #96
1 parent c3dacac commit 59b42a7

File tree

5 files changed

+373
-19
lines changed

5 files changed

+373
-19
lines changed

.github/workflows/build.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,4 +92,4 @@ jobs:
9292
- name: Run integration test
9393
shell: bash
9494
working-directory: tests
95-
run: chmod +x simple pollcatch-decoder && LD_LIBRARY_PATH=$PWD ./integration.sh
95+
run: chmod +x simple pollcatch-decoder && LD_LIBRARY_PATH=$PWD ./integration.sh && LD_LIBRARY_PATH=$PWD ./separate_runtime_integration.sh

examples/simple/main.rs

Lines changed: 28 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -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

6772
impl 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+
98113
async fn main_internal(args: Args) -> Result<(), anyhow::Error> {
99114
set_up_tracing();
100115
tracing::info!("main started");
@@ -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

Comments
 (0)