Expand description
Session hot-path observability.
Thread-safe atomic counters and timing for save/append/serialize/IO
operations. Gated behind PI_PERF_TELEMETRY=1 for zero overhead in
production: when disabled, all recording methods are instant no-ops.
§Design
TimingCounter: atomic count + total microseconds + max microseconds.ByteCounter: atomic count + total bytes.SessionMetrics: composes counters for every instrumented phase.ScopedTimer: RAII guard that records elapsed time on drop.global(): returns&'static SessionMetrics(lazy-initialized once).
§Integration points
Currently instrumented (files owned by this bead):
session_sqlite.rs: save, load, metadata loadsession_index.rs: lock acquisition, upsert, list, reindex
Future instrumentation (requires session.rs access):
Session::save()JSONL path: queue wait, serialization, IO, persistSession::append_*(): in-memory append timing
Structs§
- Byte
Counter - Atomic counter for tracking bytes written/read.
- Byte
Snapshot - Point-in-time snapshot of a
ByteCounter. - Metrics
Snapshot - Complete point-in-time snapshot of all session metrics.
- Scoped
Timer - RAII timer that records elapsed microseconds into a
TimingCounterwhen dropped. IfcounterisNone(metrics disabled), drop is a no-op. - Session
Metrics - Centralized session hot-path metrics collector.
- Timing
Counter - Atomic counter that tracks invocation count, cumulative time (µs), and peak time (µs) for a single instrumented phase.
- Timing
Snapshot - Point-in-time snapshot of a
TimingCounter.
Functions§
- global
- Return the global
SessionMetricssingleton.