/// a measureme event, "verbose" generic activities also print a timing entry to
/// stdout if the compiler is invoked with -Ztime or -Ztime-passes.
#[inline(always)]
- pub fn verbose_generic_activity<'a>(&'a self, event_id: &'a str) -> VerboseTimingGuard<'a> {
+ pub fn verbose_generic_activity<'a>(
+ &'a self,
+ event_id: &'static str,
+ ) -> VerboseTimingGuard<'a> {
VerboseTimingGuard::start(
event_id,
self.print_verbose_generic_activities,
self.exec(EventFilter::GENERIC_ACTIVITIES, |profiler| {
let event_id = profiler.get_or_alloc_cached_string(event_id);
let event_id = EventId::from_label(event_id);
- TimingGuard::start(
- profiler,
- profiler.generic_activity_event_kind,
- event_id
- )
+ TimingGuard::start(profiler, profiler.generic_activity_event_kind, event_id)
})
}
#[inline(always)]
pub fn query_blocked(&self) -> TimingGuard<'_> {
self.exec(EventFilter::QUERY_BLOCKED, |profiler| {
- TimingGuard::start(
- profiler,
- profiler.query_blocked_event_kind,
- EventId::INVALID,
- )
+ TimingGuard::start(profiler, profiler.query_blocked_event_kind, EventId::INVALID)
})
}
}
}
+ #[inline]
pub fn enabled(&self) -> bool {
self.profiler.is_some()
}
let string_cache = self.string_cache.read();
if let Some(&id) = string_cache.get(s) {
- return id
+ return id;
}
}
*string_cache.entry(s).or_insert_with(|| self.profiler.alloc_string(s))
}
- pub fn map_query_invocation_id_to_string(
- &self,
- from: QueryInvocationId,
- to: StringId
- ) {
+ pub fn map_query_invocation_id_to_string(&self, from: QueryInvocationId, to: StringId) {
let from = StringId::new_virtual(from.0);
self.profiler.map_virtual_to_concrete_string(from, to);
}
- pub fn bulk_map_query_invocation_id_to_single_string<I>(
- &self,
- from: I,
- to: StringId
- )
- where I: Iterator<Item=QueryInvocationId> + ExactSizeIterator
+ pub fn bulk_map_query_invocation_id_to_single_string<I>(&self, from: I, to: StringId)
+ where
+ I: Iterator<Item = QueryInvocationId> + ExactSizeIterator,
{
let from = from.map(|qid| StringId::new_virtual(qid.0));
self.profiler.bulk_map_virtual_to_single_concrete_string(from, to);
pub fn none() -> TimingGuard<'a> {
TimingGuard(None)
}
+
+ #[inline(always)]
+ pub fn run<R>(self, f: impl FnOnce() -> R) -> R {
+ let _timer = self;
+ f()
+ }
}
#[must_use]
#[cfg(windows)]
fn get_resident() -> Option<usize> {
- type BOOL = i32;
- type DWORD = u32;
- type HANDLE = *mut u8;
- use libc::size_t;
- #[repr(C)]
- #[allow(non_snake_case)]
- struct PROCESS_MEMORY_COUNTERS {
- cb: DWORD,
- PageFaultCount: DWORD,
- PeakWorkingSetSize: size_t,
- WorkingSetSize: size_t,
- QuotaPeakPagedPoolUsage: size_t,
- QuotaPagedPoolUsage: size_t,
- QuotaPeakNonPagedPoolUsage: size_t,
- QuotaNonPagedPoolUsage: size_t,
- PagefileUsage: size_t,
- PeakPagefileUsage: size_t,
- }
- #[allow(non_camel_case_types)]
- type PPROCESS_MEMORY_COUNTERS = *mut PROCESS_MEMORY_COUNTERS;
- #[link(name = "psapi")]
- extern "system" {
- fn GetCurrentProcess() -> HANDLE;
- fn GetProcessMemoryInfo(
- Process: HANDLE,
- ppsmemCounters: PPROCESS_MEMORY_COUNTERS,
- cb: DWORD,
- ) -> BOOL;
- }
- let mut pmc: PROCESS_MEMORY_COUNTERS = unsafe { mem::zeroed() };
- pmc.cb = mem::size_of_val(&pmc) as DWORD;
- match unsafe { GetProcessMemoryInfo(GetCurrentProcess(), &mut pmc, pmc.cb) } {
+ use std::mem::{self, MaybeUninit};
+ use winapi::shared::minwindef::DWORD;
+ use winapi::um::processthreadsapi::GetCurrentProcess;
+ use winapi::um::psapi::{GetProcessMemoryInfo, PROCESS_MEMORY_COUNTERS};
+
+ let mut pmc = MaybeUninit::<PROCESS_MEMORY_COUNTERS>::uninit();
+ match unsafe {
+ GetProcessMemoryInfo(GetCurrentProcess(), pmc.as_mut_ptr(), mem::size_of_val(&pmc) as DWORD)
+ } {
0 => None,
- _ => Some(pmc.WorkingSetSize as usize),
+ _ => {
+ let pmc = unsafe { pmc.assume_init() };
+ Some(pmc.WorkingSetSize as usize)
+ }
}
}