Class: Kobako::Usage
- Inherits:
-
Data
- Object
- Data
- Kobako::Usage
- Defined in:
- lib/kobako/usage.rb,
sig/kobako/usage.rbs
Overview
Per-last-invocation resource accounting for a Kobako::Sandbox.
Carries two readers populated by every #eval / #run invocation:
* +wall_time+ — the Float number of seconds the guest export call
spent inside wasmtime during the most recent invocation. The
measurement bracket aligns with the +timeout+ deadline; time spent
in host Service callbacks is included, but everything that runs
after the guest export returns — the post-export
+OUTCOME_BUFFER+ fetch and decode, plus stdout / stderr capture
readout — is excluded.
* +memory_peak+ — the Integer high-water mark, in bytes, of the
per-invocation +memory.grow+ delta past the linear-memory size
captured at invocation entry. Same baseline accounting as
+memory_limit+: the mruby image's initial allocation and any
prior-invocation watermark sit outside the measurement. On
+MemoryLimitError+ +memory_peak+ never exceeds the configured
cap because the rejected +desired+ value is not promoted into
the high-water.
Both readers are populated on every outcome, including TrapError
branches, so the Host App can read Sandbox#usage after rescuing a
trap to diagnose how much of the budget the failing invocation
consumed. Before the first invocation Sandbox#usage returns the
pre-invocation sentinel Kobako::Usage::EMPTY.
Built on the class X < Data.define(...) subclass form (the
Steep-friendly shape — see lib/kobako/outcome/panic.rb).
Constant Summary collapse
- EMPTY =
Pre-invocation sentinel. Reused by
Sandboxbefore any invocation has run so callers do not need to handle anil#usage. new(wall_time: 0.0, memory_peak: 0)
Instance Attribute Summary collapse
-
#memory_peak ⇒ Integer
readonly
Returns the value of attribute memory_peak.
-
#wall_time ⇒ Float
readonly
Returns the value of attribute wall_time.
Class Method Summary collapse
Instance Attribute Details
#memory_peak ⇒ Integer (readonly)
Returns the value of attribute memory_peak.
6 7 8 |
# File 'sig/kobako/usage.rbs', line 6 def memory_peak @memory_peak end |
#wall_time ⇒ Float (readonly)
Returns the value of attribute wall_time.
5 6 7 |
# File 'sig/kobako/usage.rbs', line 5 def wall_time @wall_time end |