Created
April 29, 2021 15:04
-
-
Save danhhz/fe5667ef774db50227bdefed871a696e to your computer and use it in GitHub Desktop.
Criterion Profiler impl to surround benchmarks with Points of Interest in Instruments
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
struct InstrumentsPointsOfInterest; | |
impl InstrumentsPointsOfInterest { | |
fn code(x: &std::path::Path) -> u32 { | |
// NB: kdebug_signpost* only keeps the bottom 14 bits of this but that | |
// seems fine. | |
use std::collections::hash_map::DefaultHasher; | |
let mut h = DefaultHasher::new(); | |
x.hash(&mut h); | |
h.finish() as u32 | |
} | |
} | |
impl criterion::profiler::Profiler for InstrumentsPointsOfInterest { | |
fn start_profiling(&mut self, _benchmark_id: &str, benchmark_dir: &std::path::Path) { | |
// TODO: What happens if there's a collision and this gets called twice? | |
let code = InstrumentsPointsOfInterest::code(benchmark_dir); | |
unsafe { | |
kdebug_signpost(code, 0, 0, 0, 0); | |
kdebug_signpost_start(code, 0, 0, 0, 0); | |
} | |
} | |
fn stop_profiling(&mut self, _benchmark_id: &str, benchmark_dir: &std::path::Path) { | |
let code = InstrumentsPointsOfInterest::code(benchmark_dir); | |
unsafe { | |
kdebug_signpost_end(code, 0, 0, 0, 0); | |
} | |
} | |
} | |
extern "C" { | |
fn kdebug_signpost(code: u32, arg1: usize, arg2: usize, arg3: usize, arg4: usize); | |
fn kdebug_signpost_start(code: u32, arg1: usize, arg2: usize, arg3: usize, arg4: usize); | |
fn kdebug_signpost_end(code: u32, arg1: usize, arg2: usize, arg3: usize, arg4: usize); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment