/** * Selector hotspot sampler for the state inspector. * * Tracks invocation frequency and execution duration for named selectors. * An operator can inspect which selectors fire most often (churn hotspots) * or take the longest (latency hotspots) to isolate render/subscription * performance problems. * * ### Usage * ```ts * const sampler = new SelectorHotspotSampler({ windowMs: 10_000 }); * * // Instrument a selector call site: * const t0 = performance.now(); * const result = selectRunningTasks(state); * sampler.record('selectRunningTasks', performance.now() - t0); * * const report = sampler.getReport(); * ``` * * The sampler uses a sliding-window of raw samples to compute p50/p95/p99 * latencies and a calls-per-second rate. Samples older than `windowMs` * are dropped on each `record()` call (lazy GC). */ import type { SelectorHotspot, HotspotReport, HotspotSamplerConfig } from './types.js'; /** * SelectorHotspotSampler, sliding-window latency + frequency tracker. * * Thread-safety note: synchronous JS, no concurrency concerns. */ export declare class SelectorHotspotSampler { private readonly _windowMs; private readonly _maxSamplesPerKey; private readonly _selectors; /** * @param config, Optional sampler configuration. */ constructor(config?: HotspotSamplerConfig); /** Current sliding window duration in ms. */ get windowMs(): number; /** * Record a selector invocation. * * @param key, Selector name / identifier. * @param durationMs, Execution time in milliseconds (may be 0 for sync). */ record(key: string, durationMs: number): void; /** * Return a sorted hotspot report. * * Hotspots are sorted by `callsInWindow` descending (churn first), * then by `p95Ms` descending as a tiebreaker. * * @returns HotspotReport. */ getReport(): HotspotReport; /** * Return the hotspot for a single selector key, or undefined if never recorded. * * @param key, Selector identifier. */ getHotspot(key: string): SelectorHotspot | undefined; /** * Return the top N selectors by call count in the current window. * * @param n, Maximum number of hotspots to return. */ getTopHotspots(n: number): SelectorHotspot[]; /** Number of distinct selector keys tracked. */ get trackedKeyCount(): number; /** * Clear all recorded samples and reset tracking. * Does not reset configuration. */ reset(): void; private _evictOldSamples; private _computeHotspot; private _percentiles; } //# sourceMappingURL=hotspot-sampler.d.ts.map