Skip to content

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

Merged
simongdavies merged 1 commit intomainfrom
add-call-stats
Mar 26, 2026
Merged

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

Conversation

@simongdavies
Copy link
Copy Markdown
Member

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
@simongdavies simongdavies force-pushed the add-call-stats branch 2 times, most recently from 46173ba to 85971c2 Compare March 3, 2026 18:04
Comment thread src/js-host-api/src/lib.rs Outdated
dblnz
dblnz previously approved these changes Mar 11, 2026
Copy link
Copy Markdown
Contributor

@dblnz dblnz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great work!
This is a nice to have feature, although I think we might end up needing this pattern in hyperlight-wasm, hyperlight core and maybe other places. Maybe we could use a #[derive] to automatically add this to a sandbox? (just a thought)

Some comments below. Nothing blocking though.

Comment thread src/hyperlight-js/examples/execution_stats/main.rs Outdated
Comment thread src/hyperlight-js/src/sandbox/loaded_js_sandbox.rs
Comment thread Justfile Outdated
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>
@simongdavies simongdavies merged commit a892a0a into main Mar 26, 2026
18 checks passed
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.

3 participants