about summary refs log tree commit diff
diff options
context:
space:
mode:
authorbjorn3 <17426603+bjorn3@users.noreply.github.com>2023-02-03 18:35:09 +0000
committerbjorn3 <17426603+bjorn3@users.noreply.github.com>2023-02-03 18:39:05 +0000
commita0d3b0963d68ebf4d63bd8ac4a3ca5ab3cc44873 (patch)
treec617d23fbb6c0f6e50f4516a6ad751b42d902c6e
parent469783c263c3ac0aadde100cbf7e575c21caad1f (diff)
downloadrust-a0d3b0963d68ebf4d63bd8ac4a3ca5ab3cc44873.tar.gz
rust-a0d3b0963d68ebf4d63bd8ac4a3ca5ab3cc44873.zip
Record cranelift pass timings in self profile results
-rw-r--r--src/base.rs21
1 files changed, 21 insertions, 0 deletions
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 {