YJIT: fix bug in top cfunc logging in --yjit-stats (#9056)

YJIT: correctly handle case where there are no cfunc calls

Fix bug in top cfunc logging in `--yjit-stats`
This commit is contained in:
Maxime Chevalier-Boisvert 2023-11-28 17:27:11 -05:00 committed by GitHub
parent a9c07cbd21
commit ea3e17e430
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 5 additions and 4 deletions

View file

@ -375,7 +375,9 @@ module RubyVM::YJIT
def print_sorted_cfunc_calls(stats, out:, how_many: 20, left_pad: 4) # :nodoc: def print_sorted_cfunc_calls(stats, out:, how_many: 20, left_pad: 4) # :nodoc:
calls = stats[:cfunc_calls] calls = stats[:cfunc_calls]
#puts calls if calls.empty?
return
end
# Total number of cfunc calls # Total number of cfunc calls
num_send_cfunc = stats[:num_send_cfunc] num_send_cfunc = stats[:num_send_cfunc]

View file

@ -743,9 +743,10 @@ fn rb_yjit_gen_stats_dict(context: bool) -> VALUE {
} }
// Create a hash for the cfunc call counts // Create a hash for the cfunc call counts
let calls_hash = rb_hash_new();
rb_hash_aset(hash, rust_str_to_sym("cfunc_calls"), calls_hash);
if let Some(cfunc_name_to_idx) = CFUNC_NAME_TO_IDX.as_mut() { if let Some(cfunc_name_to_idx) = CFUNC_NAME_TO_IDX.as_mut() {
let call_counts = CFUNC_CALL_COUNT.as_mut().unwrap(); let call_counts = CFUNC_CALL_COUNT.as_mut().unwrap();
let calls_hash = rb_hash_new();
for (name, idx) in cfunc_name_to_idx { for (name, idx) in cfunc_name_to_idx {
let count = call_counts[*idx]; let count = call_counts[*idx];
@ -755,8 +756,6 @@ fn rb_yjit_gen_stats_dict(context: bool) -> VALUE {
let value = VALUE::fixnum_from_usize(count as usize); let value = VALUE::fixnum_from_usize(count as usize);
rb_hash_aset(calls_hash, key, value); rb_hash_aset(calls_hash, key, value);
} }
rb_hash_aset(hash, rust_str_to_sym("cfunc_calls"), calls_hash);
} }
} }