ZJIT: Add code_region_bytes stat (#14389)

* ZJIT: Add code_region_bytes stat

* Share more logic among --zjit and --zjit-stats
This commit is contained in:
Takashi Kokubun 2025-08-28 13:45:35 -07:00 committed by GitHub
parent 041450ad41
commit bf3d6a17ee
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 19 additions and 9 deletions

View File

@ -46,6 +46,7 @@ class << RubyVM::ZJIT
:gc_time_ns,
:invalidation_time_ns,
:code_region_bytes,
:side_exit_count,
:total_insn_count,
:vm_insn_count,

View File

@ -84,6 +84,11 @@ impl CodeBlock {
}
}
/// Size of the region in bytes that we have allocated physical memory for.
pub fn mapped_region_size(&self) -> usize {
self.mem_block.borrow().mapped_region_size()
}
/// Add an assembly comment if the feature is on.
pub fn add_comment(&mut self, comment: &str) {
if !self.keep_comments {

View File

@ -48,9 +48,8 @@ macro_rules! make_counters {
$( Counter::$default_counter_name, )+
];
/// List of all counters
pub const ALL_COUNTERS: &'static [Counter] = &[
$( Counter::$default_counter_name, )+
/// List of counters that are available only for --zjit-stats.
pub const STATS_ONLY_COUNTERS: &'static [Counter] = &[
$( Counter::$counter_name, )+
];
}
@ -187,16 +186,21 @@ pub extern "C" fn rb_zjit_stats(_ec: EcPtr, _self: VALUE, target_key: VALUE) ->
Qnil
};
// If not --zjit-stats, set only default counters
// Set default counters
for &counter in DEFAULT_COUNTERS {
set_stat_usize!(hash, &counter.name(), unsafe { *counter_ptr(counter) });
}
// Memory usage stats
set_stat_usize!(hash, "code_region_bytes", ZJITState::get_code_block().mapped_region_size());
// End of default stats. Every counter beyond this is provided only for --zjit-stats.
if !get_option!(stats) {
for &counter in DEFAULT_COUNTERS {
set_stat_usize!(hash, &counter.name(), unsafe { *counter_ptr(counter) });
}
return hash;
}
// Set all counters for --zjit-stats
for &counter in ALL_COUNTERS {
// Set stats-only counters
for &counter in STATS_ONLY_COUNTERS {
set_stat_usize!(hash, &counter.name(), unsafe { *counter_ptr(counter) });
}