feat(vm): add resource diagnostics and macOS stability qualification
Intrepid/Prometeu/Runtime/pipeline/pr-master This commit looks good
Intrepid/Prometeu/Runtime/pipeline/pr-master This commit looks good
This commit is contained in:
@@ -0,0 +1,89 @@
|
||||
//! Opt-in engineering observations, never a guest ABI or a source of GC roots.
|
||||
//! Timing distributions are bounded logarithmic histograms in nanoseconds.
|
||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||
pub struct BudgetSnapshot {
|
||||
/// RuntimeResource discriminant order; depth/individual string size are checked,
|
||||
/// not reserved, so their current usage remains zero and their peak records checks.
|
||||
pub used: [u64; 8],
|
||||
pub peaks: [u64; 8],
|
||||
/// Includes refused speculative capacity growth that may fall back to exact growth.
|
||||
pub refusals: [u64; 8],
|
||||
pub limits: [u64; 8],
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct DurationHistogram {
|
||||
buckets: [u64; 64],
|
||||
pub count: u64,
|
||||
pub max_ns: u64,
|
||||
}
|
||||
impl Default for DurationHistogram {
|
||||
fn default() -> Self {
|
||||
Self { buckets: [0; 64], count: 0, max_ns: 0 }
|
||||
}
|
||||
}
|
||||
impl DurationHistogram {
|
||||
pub(crate) fn record(&mut self, elapsed: std::time::Duration) {
|
||||
let ns = elapsed.as_nanos().min(u64::MAX as u128) as u64;
|
||||
let bucket = (63 - ns.max(1).leading_zeros()) as usize;
|
||||
self.buckets[bucket] += 1;
|
||||
self.count += 1;
|
||||
self.max_ns = self.max_ns.max(ns);
|
||||
}
|
||||
/// Inclusive upper bound for the percentile's bucket, capped by observed max.
|
||||
pub fn percentile_upper_ns(&self, percentile: u64) -> u64 {
|
||||
assert!((1..=100).contains(&percentile));
|
||||
if self.count == 0 {
|
||||
return 0;
|
||||
}
|
||||
let rank = (self.count as u128 * percentile as u128).div_ceil(100);
|
||||
let mut seen = 0u128;
|
||||
for (i, &count) in self.buckets.iter().enumerate() {
|
||||
seen += count as u128;
|
||||
if seen >= rank {
|
||||
return (u64::MAX >> (63 - i)).min(self.max_ns);
|
||||
}
|
||||
}
|
||||
self.max_ns
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Default, Clone)]
|
||||
pub struct GcDiagnostics {
|
||||
pub collections: u64,
|
||||
pub reclaimed: u64,
|
||||
pub mark: DurationHistogram,
|
||||
pub sweep: DurationHistogram,
|
||||
pub total: DurationHistogram,
|
||||
pub string_reconciliation: DurationHistogram,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct ResourceSnapshot {
|
||||
pub budget: BudgetSnapshot,
|
||||
pub live_objects: usize,
|
||||
pub free_handles: usize,
|
||||
pub retired_handles: usize,
|
||||
pub tracked_strings: usize,
|
||||
pub call_depth: usize,
|
||||
pub peak_call_depth: usize,
|
||||
pub cycles: u64,
|
||||
pub gc: GcDiagnostics,
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
#[test]
|
||||
fn bounded_histogram_reports_upper_bounds_and_exact_max() {
|
||||
let mut h = DurationHistogram::default();
|
||||
assert_eq!(h.percentile_upper_ns(99), 0);
|
||||
for ns in 0..100 {
|
||||
h.record(std::time::Duration::from_nanos(ns));
|
||||
}
|
||||
assert_eq!(h.count, 100);
|
||||
assert_eq!(h.percentile_upper_ns(50), 63);
|
||||
assert_eq!(h.percentile_upper_ns(95), 99);
|
||||
assert_eq!(h.max_ns, 99);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user