Class: Phronomy::Runtime::RuntimeMetrics Private
- Inherits:
-
Object
- Object
- Phronomy::Runtime::RuntimeMetrics
- Defined in:
- lib/phronomy/runtime/runtime_metrics.rb
Overview
This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.
Internal store for task-centric counters and latency samples.
All access is mutex-protected. The ring buffers for wait/run times are bounded to WINDOW samples so that long-lived runtimes do not grow unbounded.
Instance Method Summary collapse
-
#increment_starvation ⇒ void
private
Increments the CPU-starvation counter (task ran without yielding over the configured +blocking_detect_threshold_ms+ threshold).
-
#initialize ⇒ RuntimeMetrics
constructor
private
A new instance of RuntimeMetrics.
-
#record_end(type, outcome, run_start_ms) ⇒ void
private
Records completion of a task (decrements active count, appends run time).
-
#record_start(type) ⇒ void
private
Records that a new task of +type+ has been spawned.
-
#record_wait(wait_ms) ⇒ void
private
Appends a wait-time sample (milliseconds from spawn to start).
-
#snapshot ⇒ Hash{Symbol => Numeric}
private
Returns the full task-centric metrics hash (see #task_snapshot).
-
#starvation_count ⇒ Integer
private
Returns the current starvation counter value.
Constructor Details
#initialize ⇒ RuntimeMetrics
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns a new instance of RuntimeMetrics.
15 16 17 18 19 20 21 22 23 |
# File 'lib/phronomy/runtime/runtime_metrics.rb', line 15 def initialize @mutex = Mutex.new @active_by_type = Hash.new(0) @wait_ms = [] @run_ms = [] @cancelled = Hash.new(0) @failed = Hash.new(0) @starvation_count = 0 end |
Instance Method Details
#increment_starvation ⇒ void
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
This method returns an undefined value.
Increments the CPU-starvation counter (task ran without yielding over the configured +blocking_detect_threshold_ms+ threshold).
67 68 69 |
# File 'lib/phronomy/runtime/runtime_metrics.rb', line 67 def increment_starvation @mutex.synchronize { @starvation_count += 1 } end |
#record_end(type, outcome, run_start_ms) ⇒ void
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
This method returns an undefined value.
Records completion of a task (decrements active count, appends run time).
50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/phronomy/runtime/runtime_metrics.rb', line 50 def record_end(type, outcome, run_start_ms) run_ms = Process.clock_gettime(Process::CLOCK_MONOTONIC, :millisecond) - run_start_ms @mutex.synchronize do @active_by_type[type] = [@active_by_type[type] - 1, 0].max @run_ms << run_ms @run_ms.shift if @run_ms.size > WINDOW case outcome when :cancelled then @cancelled[type] += 1 when :failed then @failed[type] += 1 end end end |
#record_start(type) ⇒ void
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
This method returns an undefined value.
Records that a new task of +type+ has been spawned.
29 30 31 |
# File 'lib/phronomy/runtime/runtime_metrics.rb', line 29 def record_start(type) @mutex.synchronize { @active_by_type[type] += 1 } end |
#record_wait(wait_ms) ⇒ void
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
This method returns an undefined value.
Appends a wait-time sample (milliseconds from spawn to start).
37 38 39 40 41 42 |
# File 'lib/phronomy/runtime/runtime_metrics.rb', line 37 def record_wait(wait_ms) @mutex.synchronize do @wait_ms << wait_ms @wait_ms.shift if @wait_ms.size > WINDOW end end |
#snapshot ⇒ Hash{Symbol => Numeric}
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns the full task-centric metrics hash (see Phronomy::Runtime#task_snapshot).
81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 |
# File 'lib/phronomy/runtime/runtime_metrics.rb', line 81 def snapshot @mutex.synchronize do active = @active_by_type.dup wait = @wait_ms.dup run = @run_ms.dup cancelled = @cancelled.values.sum failed = @failed.values.sum starvation = @starvation_count { active_agent_tasks: active[:agent].to_i, active_tool_tasks: active[:tool].to_i, active_workflow_tasks: active[:workflow].to_i, active_rag_tasks: active[:rag].to_i, active_llm_tasks: active[:llm].to_i, task_wait_time_p50_ms: _percentile(wait, 50), task_wait_time_p95_ms: _percentile(wait, 95), task_run_time_p50_ms: _percentile(run, 50), task_run_time_p95_ms: _percentile(run, 95), cancelled_tasks: cancelled, failed_tasks: failed, non_yield_threshold_violation_count: starvation } end end |
#starvation_count ⇒ Integer
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns the current starvation counter value.
74 75 76 |
# File 'lib/phronomy/runtime/runtime_metrics.rb', line 74 def starvation_count @mutex.synchronize { @starvation_count } end |