Skip to content

Commit a0d3b09

Browse files
committed
Record cranelift pass timings in self profile results
1 parent 469783c commit a0d3b09

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

src/base.rs

+21
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,27 @@ pub(crate) fn compile_fn(
182182
cx.profiler.generic_activity("define function").run(|| {
183183
context.want_disasm = cx.should_write_ir;
184184
module.define_function(codegened_func.func_id, context).unwrap();
185+
186+
if cx.profiler.enabled() {
187+
let mut recording_args = false;
188+
cx.profiler
189+
.generic_activity_with_arg_recorder(
190+
"define function (clif pass timings)",
191+
|recorder| {
192+
let pass_times = cranelift_codegen::timing::take_current();
193+
// Replace newlines with | as measureme doesn't allow control characters like
194+
// newlines inside strings.
195+
recorder.record_arg(format!("{}", pass_times).replace("\n", " | "));
196+
recording_args = true;
197+
},
198+
)
199+
.run(|| {
200+
if recording_args {
201+
// Wait a tiny bit to ensure chrome's profiler doesn't hide the event
202+
std::thread::sleep(std::time::Duration::from_nanos(2))
203+
}
204+
});
205+
}
185206
});
186207

187208
if cx.should_write_ir {

0 commit comments

Comments
 (0)