5305: Profiling tweaks r=matklad a=matklad



bors r+
🤖

Co-authored-by: Aleksey Kladov <aleksey.kladov@gmail.com>
This commit is contained in:
bors[bot] 2020-07-11 01:05:15 +00:00 committed by GitHub
commit a3edd482e9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 9 additions and 0 deletions

View File

@ -20,3 +20,8 @@ jemalloc-ctl = { version = "0.3.3", optional = true }
[features]
jemalloc = [ "jemallocator", "jemalloc-ctl" ]
cpu_profiler = []
# Uncomment to enable for the whole crate graph
# default = [ "backtrace" ]
# default = [ "jemalloc" ]
# default = [ "cpu_profiler" ]

View File

@ -43,6 +43,7 @@ pub struct Scope {
}
impl Scope {
#[must_use]
pub fn enter() -> Scope {
let prev = IN_SCOPE.with(|slot| std::mem::replace(&mut *slot.borrow_mut(), true));
Scope { prev }
@ -78,6 +79,7 @@ pub struct CpuProfiler {
_private: (),
}
#[must_use]
pub fn cpu_profiler() -> CpuProfiler {
#[cfg(feature = "cpu_profiler")]
{

View File

@ -87,6 +87,8 @@ fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
Ok(())
}
}
#[must_use]
pub fn timeit(label: &'static str) -> impl Drop {
struct Guard {
label: &'static str,