From a0d3b0963d68ebf4d63bd8ac4a3ca5ab3cc44873 Mon Sep 17 00:00:00 2001 From: bjorn3 <17426603+bjorn3@users.noreply.github.com> Date: Fri, 3 Feb 2023 18:35:09 +0000 Subject: [PATCH] Record cranelift pass timings in self profile results --- src/base.rs | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/src/base.rs b/src/base.rs index b43bb5e8668..3f5cc38b04c 100644 --- a/src/base.rs +++ b/src/base.rs @@ -182,6 +182,27 @@ pub(crate) fn compile_fn( cx.profiler.generic_activity("define function").run(|| { context.want_disasm = cx.should_write_ir; module.define_function(codegened_func.func_id, context).unwrap(); + + if cx.profiler.enabled() { + let mut recording_args = false; + cx.profiler + .generic_activity_with_arg_recorder( + "define function (clif pass timings)", + |recorder| { + let pass_times = cranelift_codegen::timing::take_current(); + // Replace newlines with | as measureme doesn't allow control characters like + // newlines inside strings. + recorder.record_arg(format!("{}", pass_times).replace("\n", " | ")); + recording_args = true; + }, + ) + .run(|| { + if recording_args { + // Wait a tiny bit to ensure chrome's profiler doesn't hide the event + std::thread::sleep(std::time::Duration::from_nanos(2)) + } + }); + } }); if cx.should_write_ir {