Skip to content

Instantly share code, notes, and snippets.

@danhhz
Created April 29, 2021 15:04
Show Gist options
  • Save danhhz/fe5667ef774db50227bdefed871a696e to your computer and use it in GitHub Desktop.
Save danhhz/fe5667ef774db50227bdefed871a696e to your computer and use it in GitHub Desktop.
Criterion Profiler impl to surround benchmarks with Points of Interest in Instruments
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