feat: 新增采样器按指令周期记录样本并输出热点直方图

This commit is contained in:
2026-10-04 21:40:26 +00:00
parent 7390d66f3e
commit b77f75b237
10 changed files with 181 additions and 21 deletions
+14 -1
View File
@@ -8,7 +8,7 @@ use oxide_bytecode::module::Constant;
use crate::bindings;
use crate::vm::{TableGen, Vm};
use crate::vm_info;
use crate::vm_state::{GcState, IterState, ProfilingState, SymbolState};
use crate::vm_state::{GcState, IterState, ProfilingState, SampleState, SymbolState};
use oxide_kernel::kernel::{KernelConfig, KernelCore, KernelSession};
use oxide_kernel::shape_forge::EMPTY_SHAPE_ID;
use oxide_types::mem::P;
@@ -149,6 +149,11 @@ impl Vm {
ic_misses: std::cell::Cell::new(0),
instruction_count: 0,
},
sampling: SampleState {
period: 0,
top_k: 10,
records: Vec::new(),
},
cell_stack: Vec::new(),
template_objects: std::collections::HashMap::new(),
active_flat_id: 0,
@@ -283,6 +288,11 @@ impl Vm {
ic_misses: std::cell::Cell::new(0),
instruction_count: 0,
},
sampling: SampleState {
period: 0,
top_k: 10,
records: Vec::new(),
},
cell_stack: Vec::new(),
template_objects: std::collections::HashMap::new(),
active_flat_id: 0,
@@ -522,6 +532,9 @@ impl Vm {
// per-run 指标(ic_hit_rate)跨文件累积,报告失真。
self.profiling.ic_hits.set(0);
self.profiling.ic_misses.set(0);
// 采样记录同属执行期状态:池化 Vm 跨 run 复用,不清空则上一 run 的
// 样本混入本 run 的直方图,热点分布失真。
self.sampling.clear_records();
// GC 统计同属执行期状态:池化 Vm 跨 run 复用,不清零则 per-run
// 指标(gc_trigger_count)跨文件累积,报告失真。
let gc = &mut self.gc_state.session_gc;