Skip to content

Commit cb39283

Browse files
committed
YJIT: In stats, group by resolved C method name
Previously, in the "Top-N most frequent C calls" section of --yjit-stats output, we printed the class name of the receiver, not the method owner. This meant that calls on subclass instances that land on the same method showed up as different entires. Similarly, method called using an alias showed up as different entries from other aliases. Group by the resolved method instead. Test program: 1.itself; [].itself; true.inspect; true.to_s Before: Top-4 most frequent C calls (80.0% of C calls): 1 (20.0%): Integer#itself 1 (20.0%): TrueClass#to_s 1 (20.0%): TrueClass#inspect 1 (20.0%): Array#itself After: Top-2 most frequent C calls (80.0% of C calls): 2 (40.0%): Kernel#itself 2 (40.0%): TrueClass#to_s
1 parent 158b8cb commit cb39283

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

yjit/src/codegen.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6871,8 +6871,8 @@ fn gen_send_cfunc(
68716871
// We also do this after the C call to minimize the impact of spill_temps() on asm.ccall().
68726872
if get_option!(gen_stats) {
68736873
// Assemble the method name string
6874-
let mid = unsafe { vm_ci_mid(ci) };
6875-
let name_str = get_method_name(recv_known_class, mid);
6874+
let mid = unsafe { rb_get_def_original_id((*cme).def) };
6875+
let name_str = get_method_name(Some(unsafe { (*cme).owner }), mid);
68766876

68776877
// Get an index for this cfunc name
68786878
let cfunc_idx = get_cfunc_idx(&name_str);
@@ -9099,7 +9099,10 @@ fn gen_send_general(
90999099

91009100
/// Get class name from a class pointer.
91019101
fn get_class_name(class: Option<VALUE>) -> String {
9102-
class.and_then(|class| unsafe {
9102+
class.filter(|&class| {
9103+
// type checks for rb_class2name()
9104+
unsafe { RB_TYPE_P(class, RUBY_T_MODULE) || RB_TYPE_P(class, RUBY_T_CLASS) }
9105+
}).and_then(|class| unsafe {
91039106
cstr_to_rust_string(rb_class2name(class))
91049107
}).unwrap_or_else(|| "Unknown".to_string())
91059108
}

0 commit comments

Comments
 (0)