Class: Kobako::Usage

Inherits:
Data
  • Object
show all
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 Sandbox before any invocation has run so callers do not need to handle a nil #usage.

Returns:

new(wall_time: 0.0, memory_peak: 0)

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Attribute Details

#memory_peakInteger (readonly)

Returns the value of attribute memory_peak.

Returns:

  • (Integer)


6
7
8
# File 'sig/kobako/usage.rbs', line 6

def memory_peak
  @memory_peak
end

#wall_timeFloat (readonly)

Returns the value of attribute wall_time.

Returns:

  • (Float)


5
6
7
# File 'sig/kobako/usage.rbs', line 5

def wall_time
  @wall_time
end

Class Method Details

.new(wall_time:, memory_peak:) ⇒ Usage .new(wall_time, memory_peak) ⇒ Usage

Overloads:

  • .new(wall_time:, memory_peak:) ⇒ Usage

    Parameters:

    • wall_time: (Float)
    • memory_peak: (Integer)

    Returns:

  • .new(wall_time, memory_peak) ⇒ Usage

    Parameters:

    • wall_time (Float)
    • memory_peak (Integer)

    Returns:



8
9
# File 'sig/kobako/usage.rbs', line 8

def self.new: (wall_time: Float, memory_peak: Integer) -> Usage
| (Float wall_time, Integer memory_peak) -> Usage