From 7f50c705742dd92509ae9fc3003eb7561baa7e8a Mon Sep 17 00:00:00 2001 From: Maxime Chevalier-Boisvert Date: Mon, 27 Nov 2023 17:49:53 -0500 Subject: YJIT: add top C function call counts to `--yjit-stats` (#9047) * YJIT: gather call counts for individual cfuncs Co-authored by Takashi Kokubun --- yjit/src/codegen.rs | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) (limited to 'yjit/src/codegen.rs') 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); -- cgit v1.2.3