Skip to content

Add guest-call-stats feature with ExecutionStats API#33

Open
simongdavies wants to merge 1 commit intomainfrom
add-call-stats
Open

Add guest-call-stats feature with ExecutionStats API#33
simongdavies wants to merge 1 commit intomainfrom
add-call-stats

Conversation

@simongdavies
Copy link
Contributor

Add per-call execution statistics (wall clock, CPU time, termination info) accessible via LoadedJSSandbox::last_call_stats() behind the guest-call-stats feature flag.

Rust API:

  • New ExecutionStats struct with wall_clock, cpu_time, terminated_by fields
  • last_call_stats() getter on LoadedJSSandbox (feature-gated)
  • Stats captured on every handle_event/handle_event_with_monitor call
  • Stats available even when calls error (monitor termination, guest abort)
  • MonitorSet::to_race() now returns winner name for stats integration

Node.js (NAPI) API:

  • CallStats object with wallClockMs, cpuTimeMs, terminatedBy properties
  • lastCallStats getter on LoadedJSSandbox wrapper
  • guest-call-stats enabled by default in js-host-api

Includes:

  • execution_stats example (Rust) with 6 test scenarios
  • 10 integration tests covering all stats paths
  • Updated cpu-timeout.js example with printCallStats helper
  • Documentation updates (execution-monitors.md, READMEs)
  • Justfile: test-monitors includes guest-call-stats, new example recipe

@simongdavies simongdavies added the kind/enhancement New feature or improvement label Mar 3, 2026
Add per-call execution statistics (wall clock, CPU time, termination info)
accessible via LoadedJSSandbox::last_call_stats() behind the guest-call-stats
feature flag.

Rust API:
- New ExecutionStats struct with wall_clock, cpu_time, terminated_by fields
- last_call_stats() getter on LoadedJSSandbox (feature-gated)
- Stats captured on every handle_event/handle_event_with_monitor call
- Stats available even when calls error (monitor termination, guest abort)
- MonitorSet::to_race() now returns winner name for stats integration

Node.js (NAPI) API:
- CallStats object with wallClockMs, cpuTimeMs, terminatedBy properties
- lastCallStats getter on LoadedJSSandbox wrapper
- guest-call-stats enabled by default in js-host-api

Includes:
- execution_stats example (Rust) with 6 test scenarios
- 10 integration tests covering all stats paths
- Updated cpu-timeout.js example with printCallStats helper
- Documentation updates (execution-monitors.md, READMEs)
- Justfile: test-monitors includes guest-call-stats, new example recipe

Signed-off-by: Simon Davies <simongdavies@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

kind/enhancement New feature or improvement

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant