diff options
| author | Maxime Chevalier-Boisvert <maxime.chevalierboisvert@shopify.com> | 2023-11-27 17:49:53 -0500 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-11-27 22:49:53 +0000 |
| commit | 7f50c705742dd92509ae9fc3003eb7561baa7e8a (patch) | |
| tree | b3b4b5a084b460a80a9b3b60622fb621c4cf301b /yjit/src/codegen.rs | |
| parent | 94015e0dce38d238d428b60b46dcb9f3caef445f (diff) | |
YJIT: add top C function call counts to `--yjit-stats` (#9047)
* YJIT: gather call counts for individual cfuncs
Co-authored by Takashi Kokubun
Diffstat (limited to 'yjit/src/codegen.rs')
| -rw-r--r-- | yjit/src/codegen.rs | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/yjit/src/codegen.rs b/yjit/src/codegen.rs index 7846635e71..51a0ba3a31 100644 --- a/yjit/src/codegen.rs +++ b/yjit/src/codegen.rs @@ -5398,6 +5398,7 @@ fn gen_send_cfunc( return None; } + // Increment total cfunc send count gen_counter_incr(asm, Counter::num_send_cfunc); // Delegate to codegen for C methods if we have it. @@ -5416,6 +5417,32 @@ fn gen_send_cfunc( } } + // Log the name of the method we're calling to, + // note that we intentionally don't do this for inlined cfuncs + if get_option!(gen_stats) { + // TODO: extract code to get method name string into its own function + + // Assemble the method name string + let mid = unsafe { vm_ci_mid(ci) }; + let class_name = if recv_known_klass != ptr::null() { + unsafe { cstr_to_rust_string(rb_class2name(*recv_known_klass)) }.unwrap() + } else { + "Unknown".to_string() + }; + let method_name = if mid != 0 { + unsafe { cstr_to_rust_string(rb_id2name(mid)) }.unwrap() + } else { + "Unknown".to_string() + }; + let name_str = format!("{}#{}", class_name, method_name); + + // Get an index for this cfunc name + let cfunc_idx = get_cfunc_idx(&name_str); + + // Increment the counter for this cfunc + asm.ccall(incr_cfunc_counter as *const u8, vec![cfunc_idx.into()]); + } + // Check for interrupts gen_check_ints(asm, Counter::guard_send_interrupted); |
