pub struct MemoryProfiler { /* private fields */ }
Available on Linux and crate feature
memory-profiling
and (crate features logging
or metrics
or telemetry
or tracing
) only.Expand description
A safe interface for jemalloc’s memory profiling functionality.
Implementations§
Source§impl MemoryProfiler
impl MemoryProfiler
Sourcepub fn get_or_init_with(
settings: &MemoryProfilerSettings,
) -> BootstrapResult<Option<Self>>
pub fn get_or_init_with( settings: &MemoryProfilerSettings, ) -> BootstrapResult<Option<Self>>
Creates a new profiler with the given settings or returns a previously initialized profiler ignoring the settings.
§Enabling profiling
Note that profiling needs to be explicitly enabled by setting _RJEM_MALLOC_CONF=prof:true
environment variable for the binary and with MemoryProfilerSettings::enabled
being set
to true
. Otherwise, this method will return None
.
If syscall sandboxing is being used (see crate::security
for more details), telemetry
must be initialized prior to syscall sandboxing.
Sourcepub async fn heap_profile(&self) -> Result<String>
pub async fn heap_profile(&self) -> Result<String>
Returns a heap profile.
§Examples
use rustfoundry::telemetry::MemoryProfiler;
use rustfoundry::telemetry::settings::MemoryProfilerSettings;
#[tokio::main]
async fn main() {
let settings = MemoryProfilerSettings {
enabled: true,
..Default::default()
};
let profiler = MemoryProfiler::get_or_init_with(&settings)
.unwrap()
.expect("profiling should be enabled via `_RJEM_MALLOC_CONF=prof:true` env var");
let profile = profiler.heap_profile().await.unwrap();
assert!(profile.contains("MAPPED_LIBRARIES"));
}
Sourcepub fn heap_stats(&self) -> Result<String>
pub fn heap_stats(&self) -> Result<String>
Returns heap statistics.
§Examples
use rustfoundry::telemetry::MemoryProfiler;
use rustfoundry::telemetry::settings::MemoryProfilerSettings;
let settings = MemoryProfilerSettings {
enabled: true,
..Default::default()
};
let profiler = MemoryProfiler::get_or_init_with(&settings)
.unwrap()
.expect("profiling should be enabled via `_RJEM_MALLOC_CONF=prof:true` env var");
let stats = profiler.heap_stats().unwrap();
assert!(stats.contains("Allocated"));
Trait Implementations§
Source§impl Clone for MemoryProfiler
impl Clone for MemoryProfiler
Source§fn clone(&self) -> MemoryProfiler
fn clone(&self) -> MemoryProfiler
Returns a copy of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source
. Read moreimpl Copy for MemoryProfiler
Auto Trait Implementations§
impl Freeze for MemoryProfiler
impl RefUnwindSafe for MemoryProfiler
impl Send for MemoryProfiler
impl Sync for MemoryProfiler
impl Unpin for MemoryProfiler
impl UnwindSafe for MemoryProfiler
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
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> FutureExt for T
impl<T> FutureExt for T
Source§fn with_context(self, otel_cx: Context) -> WithContext<Self>
fn with_context(self, otel_cx: Context) -> WithContext<Self>
Source§fn with_current_context(self) -> WithContext<Self>
fn with_current_context(self) -> WithContext<Self>
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> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
Source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
Wrap the input message
T
in a tonic::Request