Skip to content

Commit bf0331b

Browse files
authored
ZJIT: Add zjit_alloc_bytes and total_mem_bytes stats (ruby#15059)
1 parent d327eb6 commit bf0331b

File tree

3 files changed

+10
-4
lines changed

3 files changed

+10
-4
lines changed

zjit.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,9 @@ def stats_string
211211
:guard_shape_exit_ratio,
212212

213213
:code_region_bytes,
214+
:zjit_alloc_bytes,
215+
:total_mem_bytes,
216+
214217
:side_exit_count,
215218
:total_insn_count,
216219
:vm_insn_count,

zjit/src/stats.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -550,7 +550,10 @@ pub extern "C" fn rb_zjit_stats(_ec: EcPtr, _self: VALUE, target_key: VALUE) ->
550550
}
551551

552552
// Memory usage stats
553-
set_stat_usize!(hash, "code_region_bytes", ZJITState::get_code_block().mapped_region_size());
553+
let code_region_bytes = ZJITState::get_code_block().mapped_region_size();
554+
set_stat_usize!(hash, "code_region_bytes", code_region_bytes);
555+
set_stat_usize!(hash, "zjit_alloc_bytes", zjit_alloc_bytes());
556+
set_stat_usize!(hash, "total_mem_bytes", code_region_bytes + zjit_alloc_bytes());
554557

555558
// End of default stats. Every counter beyond this is provided only for --zjit-stats.
556559
if !get_option!(stats) {
@@ -645,7 +648,7 @@ pub fn with_time_stat<F, R>(counter: Counter, func: F) -> R where F: FnOnce() ->
645648
}
646649

647650
/// The number of bytes ZJIT has allocated on the Rust heap.
648-
pub fn zjit_alloc_size() -> usize {
651+
pub fn zjit_alloc_bytes() -> usize {
649652
jit::GLOBAL_ALLOCATOR.alloc_size.load(Ordering::SeqCst)
650653
}
651654

zjit/src/virtualmem.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
use std::ptr::NonNull;
77
use crate::cruby::*;
8-
use crate::stats::zjit_alloc_size;
8+
use crate::stats::zjit_alloc_bytes;
99

1010
pub type VirtualMem = VirtualMemory<sys::SystemAllocator>;
1111

@@ -199,7 +199,7 @@ impl<A: Allocator> VirtualMemory<A> {
199199
// Ignore zjit_alloc_size() if self.memory_limit_bytes is None for testing
200200
let mut required_region_bytes = page_addr + page_size - start as usize;
201201
if self.memory_limit_bytes.is_some() {
202-
required_region_bytes += zjit_alloc_size();
202+
required_region_bytes += zjit_alloc_bytes();
203203
}
204204

205205
assert!((start..=whole_region_end).contains(&mapped_region_end));

0 commit comments

Comments
 (0)