Skip to main content

PerfCollector

Struct PerfCollector 

Source
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

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<Unshared, Shared> IntoShared<Shared> for Unshared
where Shared: FromUnshared<Unshared>,

Source§

fn into_shared(self) -> Shared

Creates a shared type from an unshared type.
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more