Skip to content

Commit 7756e10

Browse files
author
Ariel Ben-Yehuda
committed
use spawn_controllable in more places
1 parent 51287bd commit 7756e10

File tree

2 files changed

+40
-14
lines changed

2 files changed

+40
-14
lines changed

src/profiler.rs

Lines changed: 37 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -138,14 +138,17 @@ impl ProfilerOptionsBuilder {
138138
/// ```
139139
/// # use async_profiler_agent::profiler::{ProfilerBuilder, ProfilerOptionsBuilder};
140140
/// # use async_profiler_agent::profiler::SpawnError;
141-
/// # fn main() -> Result<(), SpawnError> {
141+
/// # #[tokio::main]
142+
/// # async fn main() -> Result<(), SpawnError> {
142143
/// let opts = ProfilerOptionsBuilder::default().with_native_mem("10m".into()).build();
143144
/// let profiler = ProfilerBuilder::default()
144145
/// .with_profiler_options(opts)
145146
/// .with_local_reporter("/tmp/profiles")
146147
/// .build();
147148
/// # if false { // don't spawn the profiler in doctests
148-
/// profiler.spawn()?;
149+
/// let profiler = profiler.spawn_controllable()?;
150+
/// // ... your program goes here
151+
/// profiler.stop().await; // make sure the last profile is flushed
149152
/// # }
150153
/// # Ok(())
151154
/// # }
@@ -172,14 +175,17 @@ impl ProfilerOptionsBuilder {
172175
/// ```
173176
/// # use async_profiler_agent::profiler::{ProfilerBuilder, ProfilerOptionsBuilder};
174177
/// # use async_profiler_agent::profiler::SpawnError;
175-
/// # fn main() -> Result<(), SpawnError> {
178+
/// # #[tokio::main]
179+
/// # async fn main() -> Result<(), SpawnError> {
176180
/// let opts = ProfilerOptionsBuilder::default().with_native_mem_bytes(10_000_000).build();
177181
/// let profiler = ProfilerBuilder::default()
178182
/// .with_profiler_options(opts)
179183
/// .with_local_reporter("/tmp/profiles")
180184
/// .build();
181185
/// # if false { // don't spawn the profiler in doctests
182-
/// profiler.spawn()?;
186+
/// let profiler = profiler.spawn_controllable()?;
187+
/// // ... your program goes here
188+
/// profiler.stop().await; // make sure the last profile is flushed
183189
/// # }
184190
/// # Ok(())
185191
/// # }
@@ -189,14 +195,17 @@ impl ProfilerOptionsBuilder {
189195
/// ```
190196
/// # use async_profiler_agent::profiler::{ProfilerBuilder, ProfilerOptionsBuilder};
191197
/// # use async_profiler_agent::profiler::SpawnError;
192-
/// # fn main() -> Result<(), SpawnError> {
198+
/// # #[tokio::main]
199+
/// # async fn main() -> Result<(), SpawnError> {
193200
/// let opts = ProfilerOptionsBuilder::default().with_native_mem_bytes(0).build();
194201
/// let profiler = ProfilerBuilder::default()
195202
/// .with_profiler_options(opts)
196203
/// .with_local_reporter("/tmp/profiles")
197204
/// .build();
198205
/// # if false { // don't spawn the profiler in doctests
199-
/// profiler.spawn()?;
206+
/// let profiler = profiler.spawn_controllable()?;
207+
/// // ... your program goes here
208+
/// profiler.stop().await; // make sure the last profile is flushed
200209
/// # }
201210
/// # Ok(())
202211
/// # }
@@ -234,7 +243,8 @@ impl ProfilerOptionsBuilder {
234243
/// # use async_profiler_agent::profiler::{ProfilerBuilder, ProfilerOptionsBuilder};
235244
/// # use async_profiler_agent::profiler::SpawnError;
236245
/// # use std::time::Duration;
237-
/// # fn main() -> Result<(), SpawnError> {
246+
/// # #[tokio::main]
247+
/// # async fn main() -> Result<(), SpawnError> {
238248
/// let opts = ProfilerOptionsBuilder::default()
239249
/// .with_cpu_interval(Duration::from_millis(10))
240250
/// .with_wall_clock_interval(Duration::from_millis(100))
@@ -244,7 +254,9 @@ impl ProfilerOptionsBuilder {
244254
/// .with_local_reporter("/tmp/profiles")
245255
/// .build();
246256
/// # if false { // don't spawn the profiler in doctests
247-
/// profiler.spawn()?;
257+
/// let profiler = profiler.spawn_controllable()?;
258+
/// // ... your program goes here
259+
/// profiler.stop().await; // make sure the last profile is flushed
248260
/// # }
249261
/// # Ok(())
250262
/// # }
@@ -285,7 +297,8 @@ impl ProfilerOptionsBuilder {
285297
/// # use async_profiler_agent::profiler::{ProfilerBuilder, ProfilerOptionsBuilder};
286298
/// # use async_profiler_agent::profiler::SpawnError;
287299
/// # use std::time::Duration;
288-
/// # fn main() -> Result<(), SpawnError> {
300+
/// # #[tokio::main]
301+
/// # async fn main() -> Result<(), SpawnError> {
289302
/// let opts = ProfilerOptionsBuilder::default()
290303
/// .with_cpu_interval(Duration::from_millis(10))
291304
/// .with_wall_clock_interval(Duration::from_millis(10))
@@ -295,7 +308,9 @@ impl ProfilerOptionsBuilder {
295308
/// .with_local_reporter("/tmp/profiles")
296309
/// .build();
297310
/// # if false { // don't spawn the profiler in doctests
298-
/// profiler.spawn()?;
311+
/// let profiler = profiler.spawn_controllable()?;
312+
/// // ... your program goes here
313+
/// profiler.stop().await; // make sure the last profile is flushed
299314
/// # }
300315
/// # Ok(())
301316
/// # }
@@ -339,6 +354,9 @@ impl ProfilerBuilder {
339354
/// ## Example
340355
///
341356
/// ```no_run
357+
/// # use async_profiler_agent::profiler::SpawnError;
358+
/// # #[tokio::main]
359+
/// # async fn main() -> Result<(), SpawnError> {
342360
/// # use std::path::PathBuf;
343361
/// # use std::time::Duration;
344362
/// # use async_profiler_agent::profiler::{ProfilerBuilder, SpawnError};
@@ -347,8 +365,11 @@ impl ProfilerBuilder {
347365
/// .with_local_reporter(path)
348366
/// .with_reporting_interval(Duration::from_secs(15))
349367
/// .build()
350-
/// .spawn()?;
368+
/// .spawn_controllable()?;
369+
/// // .. your program goes here
370+
/// agent.stop().await; // make sure the last profile is flushed
351371
/// # Ok::<_, SpawnError>(())
372+
/// # }
352373
/// ```
353374
pub fn with_reporting_interval(mut self, i: Duration) -> ProfilerBuilder {
354375
self.reporting_interval = Some(i);
@@ -452,14 +473,17 @@ impl ProfilerBuilder {
452473
/// ```
453474
/// # use async_profiler_agent::profiler::{ProfilerBuilder, ProfilerOptionsBuilder};
454475
/// # use async_profiler_agent::profiler::SpawnError;
455-
/// # fn main() -> Result<(), SpawnError> {
476+
/// # #[tokio::main]
477+
/// # async fn main() -> Result<(), SpawnError> {
456478
/// let opts = ProfilerOptionsBuilder::default().with_native_mem("10m".into()).build();
457479
/// let profiler = ProfilerBuilder::default()
458480
/// .with_profiler_options(opts)
459481
/// .with_local_reporter("/tmp/profiles")
460482
/// .build();
461483
/// # if false { // don't spawn the profiler in doctests
462-
/// profiler.spawn()?;
484+
/// let profiler = profiler.spawn_controllable()?;
485+
/// // ... your program goes here
486+
/// profiler.stop().await; // make sure the last profile is flushed
463487
/// # }
464488
/// # Ok(())
465489
/// # }

src/reporter/local.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,9 @@ enum LocalReporterError {
4141
/// .with_local_reporter("/tmp/profiles")
4242
/// .build();
4343
/// # if false { // don't spawn the profiler in doctests
44-
/// profiler.spawn()?;
44+
/// let profiler = profiler.spawn_controllable()?;
45+
/// // ... your program goes here
46+
/// profiler.stop().await; // make sure the last profile is flushed
4547
/// # }
4648
/// # Ok(())
4749
/// # }

0 commit comments

Comments
 (0)