1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
//! Runtime counters — performance and event-loop metrics.
//!
//! In Bun/JSC, `Counters` tracks per-VM metrics (tasks completed, I/O events,
//! GC cycles, etc.). In SM, equivalent metrics are available through
//! `js::GetGCStats()` and the event-loop tick counter.
use mozjs::jsapi::*;
/// Runtime performance counters.
///
/// These are read-only snapshots of internal metrics. The actual counters
/// live in the event loop and are atomically updated.
#[derive(Debug, Default)]
pub struct Counters {
pub tasks_completed: u64,
pub io_events: u64,
pub gc_cycles: u64,
pub modules_loaded: u64,
pub http_requests: u64,
}
impl Counters {
/// Create a zeroed counter set.
pub fn new() -> Self {
Counters::default()
}
/// Snapshot the current counters from the event loop.
/// Phase 1: returns default (zero) counters.
pub fn snapshot() -> Self {
Counters::default()
}
}
/// Create a JS object with counter properties on the global object.
///
/// This is the SM equivalent of `bun_jsc::counters::create_counters_object`.
/// Phase 1: creates an empty JS plain object. Phase 2 will add actual
/// counter properties (tasks_completed, io_events, etc.).
///
/// # Safety
/// `cx` must be a valid JSContext.
pub unsafe fn create_counters_object(cx: *mut JSContext) -> *mut JSObject {
if cx.is_null() {
return ::std::ptr::null_mut();
}
unsafe { JS_NewPlainObject(cx) }
}