-
-
Notifications
You must be signed in to change notification settings - Fork 401
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
63f37a2
commit 4fad579
Showing
5 changed files
with
125 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
#![allow(missing_copy_implementations, missing_debug_implementations)] | ||
|
||
use measureme::{EventId, Profiler, TimingGuard}; | ||
use std::{path::Path, thread::current}; | ||
|
||
/// MmapSerializatioSink is faster on macOS and Linux | ||
/// but FileSerializationSink is faster on Windows | ||
#[cfg(not(windows))] | ||
type SerializationSink = measureme::MmapSerializationSink; | ||
#[cfg(windows)] | ||
type SerializationSink = measureme::FileSerializationSink; | ||
|
||
pub struct MyProfiler { | ||
profiler: Profiler<SerializationSink>, | ||
} | ||
|
||
impl MyProfiler { | ||
pub fn start_event(&self, label: &str) -> TimingGuard<'_, SerializationSink> { | ||
let kind = self.profiler.alloc_string("Generic"); | ||
let id = EventId::from_label(self.profiler.alloc_string(label)); | ||
let thread_id = current().id().as_u64() as u32; | ||
self.profiler | ||
.start_recording_interval_event(kind, id, thread_id) | ||
} | ||
|
||
pub fn new() -> MyProfiler { | ||
let profiler = Profiler::new(Path::new("./my_trace")).unwrap(); | ||
MyProfiler { profiler } | ||
} | ||
} |