pub struct Profiler { /* private fields */ }
Expand description
Rust profiler based on async-profiler.
Implementations§
Source§impl Profiler
impl Profiler
Sourcepub fn spawn(self) -> Result<JoinHandle<()>, SpawnError>
pub fn spawn(self) -> Result<JoinHandle<()>, SpawnError>
Start profiling. The profiler will run in a tokio task at the configured interval.
This is the same as calling Profiler::spawn_controllable followed by RunningProfiler::detach, except it returns a JoinHandle.
The returned JoinHandle can be used to detect if the profiler has exited due to a fatal error.
This function will fail if it is unable to start async-profiler, for example
if it can’t find or load libasyncProfiler.so
.
§Example
This example uses a LocalReporter which reports the profiles to a directory. It works with any other Reporter.
let profiler = ProfilerBuilder::default()
.with_reporter(LocalReporter::new("/tmp/profiles"))
.build();
profiler.spawn()?;
Sourcepub fn spawn_controllable(self) -> Result<RunningProfiler, SpawnError>
pub fn spawn_controllable(self) -> Result<RunningProfiler, SpawnError>
Like Self::spawn, but returns a RunningProfiler that allows for controlling (currently only stopping) the profiler.
This allows for changing the configuration of the profiler at runtime, by stopping it and then starting a new Profiler with a new configuration. It also allows for stopping profiling in case the profiler is suspected to cause operational issues.
Dropping the returned RunningProfiler will cause the profiler to quit, so if your application doen’t need to change the profiler’s configuration at runtime, it will be easier to use Profiler::spawn.
This function will fail if it is unable to start async-profiler, for example
if it can’t find or load libasyncProfiler.so
.
§Example
This example uses a LocalReporter which reports the profiles to a directory. It works with any other Reporter.
let profiler = ProfilerBuilder::default()
.with_reporter(LocalReporter::new("/tmp/profiles"))
.build();
let profiler = profiler.spawn_controllable()?;
// [insert your signaling/monitoring mechanism to have a request to disable
// profiling in case of a problem]
let got_request_to_disable_profiling = async move {
// ...
};
// spawn a task that will disable profiling if requested
tokio::task::spawn(async move {
if got_request_to_disable_profiling.await {
profiler.stop().await;
}
});
Auto Trait Implementations§
impl Freeze for Profiler
impl !RefUnwindSafe for Profiler
impl Send for Profiler
impl Sync for Profiler
impl Unpin for Profiler
impl !UnwindSafe for Profiler
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read more