pub struct PerfCollector { /* private fields */ }Expand description
Accumulator used during workflow execution.
Why: Keeping the collector off the workflow context lets us evolve perf
schema without churning WorkflowContext; the engine just calls
record_phase/flush.
What: Holds the build stamp, workflow name, a 120-char preview of the
user task, the wall-clock start Instant, and a growing Vec<PhaseRecord>.
flush(out_dir) writes runs/YYYYMMDD-HHMMSS-build<N>.json and appends a
summary line to runs.log.
Test: see unit tests at bottom of this file.
Implementations§
Source§impl PerfCollector
impl PerfCollector
Sourcepub fn new(build: u64, workflow: &str, task: &str) -> Self
pub fn new(build: u64, workflow: &str, task: &str) -> Self
Construct a new collector.
Why: Called at workflow start so the wall-clock anchor is the true
run start, not a lazy “first phase” moment.
What: Captures the build number, workflow name, truncated task preview,
start Instant, and start ISO8601 UTC timestamp.
Test: collector_records_phases.
Sourcepub fn set_test_counts(&mut self, passed: u64, failed: u64)
pub fn set_test_counts(&mut self, passed: u64, failed: u64)
Record QA test counts (Fix 3 / parity with claude-mpm).
Why: When the QA agent emits a parsable JSON envelope, we want the
exact passed/failed counts on the perf record so dashboards can
chart them over time without re-parsing agent output.
What: Stores the two counts; included in the flushed JSON and the
runs.log summary line.
Test: test_run_record_serializes_test_counts.
Sourcepub fn record_skill_considered(&mut self, name: &str)
pub fn record_skill_considered(&mut self, name: &str)
Record that name was surfaced by pre-plan skill discovery (#173).
Why: Discovery considers a broader set of skills than what is actually
injected. Tracking the full candidate set separately preserves the
recall side of the recall/precision picture for post-run analysis.
What: Appends name to skills_considered if not already present
(insertion-ordered de-dup).
Test: collector_records_skills_considered.
Sourcepub fn record_skill_used(&mut self, name: &str)
pub fn record_skill_used(&mut self, name: &str)
Record that name was injected into a phase prompt during this run
(#171).
Why: Post-run persistence (update_skill_usage in main.rs) needs the
list of injected skills to update use_count and last_used. Tracking
here keeps the collector the single source of truth for the run.
What: Appends name to skills_used if not already present
(insertion-ordered de-dup).
Test: Indirect via update_skill_usage integration in main.
Sourcepub fn set_status(&mut self, status: &str)
pub fn set_status(&mut self, status: &str)
Set the run status (#56).
Why: The workflow engine calls this after the phase loop to record
“success” on clean completion and “partial” / “failed” when a phase
returned an error, so the flushed JSON reflects reality.
What: Stores the status string verbatim; flush serializes it.
Test: collector_flush_records_failed_status.
Sourcepub fn set_failed_phase(&mut self, phase: &str)
pub fn set_failed_phase(&mut self, phase: &str)
Record which phase failed (#56).
Why: Paired with set_status, this lets analysis tooling group failed
runs by failing phase without having to parse the last phases entry.
What: Stores the phase name; included in the flushed JSON when set.
Test: collector_flush_records_failed_status.
Sourcepub fn set_model(&mut self, model: &str)
pub fn set_model(&mut self, model: &str)
Record the dominant model used by the run for pricing.
Why: The LLM pricing table is keyed by model substring. The workflow
engine doesn’t know the model up front (each phase’s agent may use a
different one), so we let the caller set/override as needed.
What: Stores the latest model string; pricing is looked up per
record_phase call using the model argument passed there, not this
field (this is retained for future aggregate analysis).
Test: implicit via collector_flush_writes_json_and_log.
Sourcepub fn record_phase(
&mut self,
name: &str,
duration_ms: u64,
model: &str,
usage: &TokenUsage,
)
pub fn record_phase( &mut self, name: &str, duration_ms: u64, model: &str, usage: &TokenUsage, )
Append a phase’s measurements, computing its USD cost from model.
Why: Engines call this once per phase with the agent model and the
summed TokenUsage from all LLM turns in that phase.
What: Prefers usage.cost_usd (OpenRouter’s authoritative,
cache-discount-aware cost) when the provider reported one; otherwise
falls back to the static per-token recompute via cost_usd(model, ...)
— the static table cannot see the cache discount, so it is a fallback
only, never a substitute when an authoritative figure exists. Pushes a
PhaseRecord.
Test: collector_records_phases, record_phase_prefers_authoritative_cost.
Sourcepub fn build_record(&self) -> PerfRecord
pub fn build_record(&self) -> PerfRecord
Build the final PerfRecord without writing to disk.
Why: Exposed for tests and for in-process consumers (the #151 JSON
envelope projects this record into a PmResponse). flush calls
this internally.
Sourcepub async fn flush(&self, out_dir: &Path) -> Result<()>
pub async fn flush(&self, out_dir: &Path) -> Result<()>
Persist the record to out_dir/runs/<stamp>.json and append a
summary line to out_dir/runs.log.
Why: A single JSON per run is easy to diff and feed to tooling; the
log line is a human-readable one-liner suitable for tail -f.
What: Computes total duration, serializes to pretty JSON, writes the
file atomically-ish (direct write is fine for append-only telemetry),
then appends a one-line summary to runs.log.
Test: collector_flush_writes_json_and_log.
Auto Trait Implementations§
impl Freeze for PerfCollector
impl RefUnwindSafe for PerfCollector
impl Send for PerfCollector
impl Sync for PerfCollector
impl Unpin for PerfCollector
impl UnsafeUnpin for PerfCollector
impl UnwindSafe for PerfCollector
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more