Skip to main content

keyhog_profile/
metrics.rs

1use serde::{Deserialize, Serialize};
2
3/// Stable wire identifier for a metric recorded by `keyhog-profile`.
4#[derive(Clone, Copy, Debug, Eq, Hash, Ord, PartialEq, PartialOrd, Serialize, Deserialize)]
5#[serde(rename_all = "kebab-case")]
6#[repr(usize)]
7pub enum MetricId {
8    SourceAcquire = 0,
9    SourceWalk,
10    SourceRead,
11    Preprocess,
12    Phase1Triggers,
13    BackendDispatch,
14    HotPatterns,
15    ConfirmedPatterns,
16    Phase2Prefilter,
17    Phase2KeywordAc,
18    Phase2SharedAc,
19    Phase2AnchoredVerify,
20    Phase2WholeChunk,
21    GenericDetection,
22    Entropy,
23    MachineLearning,
24    Decode,
25    Suppression,
26    LiveVerification,
27    Reporting,
28    SourceQueueWait,
29    IncrementalLookup,
30    BackendSelect,
31    ResultMerge,
32    ScannerQueueWait,
33    InputBytes,
34    InputUnits,
35    WallTime,
36    ProcessCpuTime,
37    ResidentMemory,
38    VirtualMemory,
39    ProcessThreads,
40    Phase2PrefilterMarkCalls,
41    Phase2PrefilterGateSkips,
42    Phase2PrefilterPerPatternWork,
43    Phase2PrefilterHsServed,
44    Phase2PrefilterRegexsetServed,
45    DecodeParentChunks,
46    DecodeDerivedChunks,
47    DecodeExtractCalls,
48    DecodeExtractBytes,
49    GenericPrefilterCalls,
50    GenericKeywordLines,
51    GenericRegexCaptures,
52    GenericEmits,
53    MlBatchCalls,
54    MlBatchCandidates,
55    MlBatchCallsGe64,
56    MlBatchCandidatesGe64,
57    DecodeExtractNs,
58    GenericPrefilterNs,
59    GenericExtractNs,
60    Phase2PrefilterHsScanNs,
61    Phase2PrefilterDroppedHostNs,
62    MlFeatureNs,
63    MlScoreNs,
64    MlBatchSize,
65    DecodeDerivedBytes,
66    HardwareCycles,
67    HardwareInstructions,
68    HardwareCacheReferences,
69    HardwareCacheMisses,
70    HardwareBranchInstructions,
71    HardwareBranchMisses,
72    HardwareStalledCyclesFrontend,
73    HardwareStalledCyclesBackend,
74    SchedulerVoluntaryContextSwitches,
75    SchedulerInvoluntaryContextSwitches,
76    SchedulerCpuMigrations,
77    SchedulerDelayNs,
78    GpuDispatchCalls,
79    GpuUploadBytes,
80    GpuReadbackBytes,
81    GpuUploadNs,
82    GpuReadbackNs,
83    GpuSubmitToCompleteNs,
84    GpuKernelNs,
85    GpuQueueWaitNs,
86    GpuAllocCalls,
87    GpuAllocBytes,
88    GpuFreeBytes,
89    GpuCompileCalls,
90    GpuCompileNs,
91    GpuPipelineCacheHits,
92    GpuPipelineCacheMisses,
93    GpuFaults,
94    GpuRetries,
95    GpuRecoveries,
96    GpuResidualBatches,
97    GpuOverlapNs,
98    GpuResidentBytes,
99    GpuPeakResidentBytes,
100    AllocationCount,
101    DeallocationCount,
102    AllocationBytes,
103    DeallocationBytes,
104    AllocationLiveBytes,
105    AllocationPeakLiveBytes,
106    MinorFaults,
107    MajorFaults,
108    IoReadBytes,
109    IoWriteBytes,
110    IoReadSyscalls,
111    IoWriteSyscalls,
112    IoCancelledWriteBytes,
113    ResidentHighWaterBytes,
114    RetainedBufferBytes,
115    RetainedBufferPeakBytes,
116    NetworkBytesRead,
117    NetworkBytesWritten,
118    NetworkRequests,
119    NetworkRetries,
120    PageCacheColdObservations,
121    PageCacheWarmObservations,
122    PageCacheDirectObservations,
123    FsOpenLatencyNs,
124    FsReadLatencyNs,
125    FsMetadataLatencyNs,
126    NetworkLatencyNs,
127    AutorouteCalibration,
128    BoundaryScan,
129    DetectorLoad,
130    DetectorValidate,
131    ExecutionPackSelect,
132    ExecutionPackMap,
133    BackendAcquire,
134    BackendInit,
135    Teardown,
136    ScanPipeline,
137    ScannerCompile,
138    FilesScanned,
139    BytesScanned,
140    SkippedFiles,
141    MatchesFound,
142    StructuredParseFailures,
143    StructuredOversizeSkips,
144    DecodeTruncations,
145    DecodeOversizeSkips,
146    InvalidPatternIndexSkips,
147    BoundaryResultCardinalityMismatches,
148    BoundarySeamTruncations,
149    LineOffsetMappingMismatches,
150    ChunkDeadlineAborts,
151    BinaryStringsNamedExclusions,
152    SkippedOverMaxSize,
153    SkippedBinary,
154    SkippedExcluded,
155    SkippedUnreadable,
156    GitObjectUnreadable,
157    SkippedArchiveTruncated,
158    BinarySectionNameUnresolved,
159    SourceTruncated,
160    StructuredSourceParseFailures,
161    ArchiveDuplicateScanUnavailable,
162    GitLfsPointer,
163    VendoredPathSuppressions,
164    ExampleSuppressions,
165    BinaryGhidraDegradedToStrings,
166    BinaryUnreadable,
167    GitBufferedBlobChunks,
168    GpuMatcherNs,
169    GpuCoalesceNs,
170    GpuDispatchNs,
171    GpuDeriveNs,
172    GpuRecallFloorNs,
173    Phase2GpuAdmissionNs,
174    GpuCoalescedBytes,
175    GpuMaxDispatchBytes,
176    GpuPresenceBits,
177    GpuUnderfireRecovered,
178    GpuTriggerBits,
179    Phase2GpuAdmitted,
180    Phase2GpuEvidenceBits,
181    Phase2GpuHaystackUploads,
182    Phase2GpuCompleteChunks,
183    Phase2GpuCompleteRows,
184    Phase2GpuExcludedOversized,
185    Phase2GpuExcludedNonAscii,
186    Phase2AlwaysAnchorChunks,
187    Phase2AlwaysAnchorCandidateRows,
188    Phase2AlwaysAnchorCandidateCount,
189    ConfirmedAnchorCandidateRows,
190    ConfirmedAnchorCandidateCount,
191    GenericKeywordCandidateRows,
192    GenericKeywordCandidateCount,
193    ConfirmedSuffixGateNs,
194    ConfirmedSuffixGateCalls,
195    ConfirmedSuffixGateSkips,
196    ConfirmedCompanionGateNs,
197    ConfirmedCompanionGateCalls,
198    ConfirmedCompanionGateDenials,
199    ConfirmedAnchorCollectNs,
200    ConfirmedAnchorCollectCalls,
201    ConfirmedExtractNs,
202    ConfirmedExtractCalls,
203    ConfirmedAnchoredMatches,
204    ConfirmedWholeChunkMatches,
205    ConfirmedHotDirectFilterSkips,
206    PostprocessFragmentsNs,
207    PostprocessFragmentsCalls,
208    PostprocessFragmentsCandidates,
209    PostprocessFragmentsMatches,
210    PostprocessDedupNs,
211    PostprocessDedupCalls,
212    Phase2AnchorCollectNs,
213    Phase2AnchorCollectCalls,
214    Phase2AnchoredVerifyCandidates,
215    Phase2AnchoredVerifyMatches,
216    Phase2WholeChunkPatterns,
217    Phase2WholeChunkMatches,
218}
219
220/// Stable identifier for a top-level production pipeline stage.
221#[derive(Clone, Copy, Debug, Eq, Hash, Ord, PartialEq, PartialOrd, Serialize, Deserialize)]
222#[serde(rename_all = "kebab-case")]
223#[repr(u8)]
224pub enum MacroStageId {
225    Acquire = 0,
226    Scan,
227    Resolve,
228    Verify,
229    Report,
230}
231
232impl MacroStageId {
233    /// Every macro-stage identifier in stable wire order.
234    pub const ALL: [Self; 5] = [
235        Self::Acquire,
236        Self::Scan,
237        Self::Resolve,
238        Self::Verify,
239        Self::Report,
240    ];
241
242    /// Stable text label used by profiles and operator reports.
243    pub const fn as_str(self) -> &'static str {
244        match self {
245            Self::Acquire => "acquire",
246            Self::Scan => "scan",
247            Self::Resolve => "resolve",
248            Self::Verify => "verify",
249            Self::Report => "report",
250        }
251    }
252}
253
254/// Type-safe identifier for an additive monotonic metric.
255#[derive(Clone, Copy, Debug, Eq, Hash, Ord, PartialEq, PartialOrd, Serialize, Deserialize)]
256#[serde(rename_all = "kebab-case")]
257#[repr(u8)]
258pub enum CounterId {
259    InputBytes = 0,
260    InputUnits,
261    ProcessCpuTime,
262    Phase2PrefilterMarkCalls,
263    Phase2PrefilterGateSkips,
264    Phase2PrefilterPerPatternWork,
265    Phase2PrefilterHsServed,
266    Phase2PrefilterRegexsetServed,
267    DecodeParentChunks,
268    DecodeDerivedChunks,
269    DecodeExtractCalls,
270    DecodeExtractBytes,
271    GenericPrefilterCalls,
272    GenericKeywordLines,
273    GenericRegexCaptures,
274    GenericEmits,
275    MlBatchCalls,
276    MlBatchCandidates,
277    MlBatchCallsGe64,
278    MlBatchCandidatesGe64,
279    DecodeExtractNs,
280    GenericPrefilterNs,
281    GenericExtractNs,
282    Phase2PrefilterHsScanNs,
283    Phase2PrefilterDroppedHostNs,
284    MlFeatureNs,
285    MlScoreNs,
286    DecodeDerivedBytes,
287    HardwareCycles,
288    HardwareInstructions,
289    HardwareCacheReferences,
290    HardwareCacheMisses,
291    HardwareBranchInstructions,
292    HardwareBranchMisses,
293    HardwareStalledCyclesFrontend,
294    HardwareStalledCyclesBackend,
295    SchedulerVoluntaryContextSwitches,
296    SchedulerInvoluntaryContextSwitches,
297    SchedulerCpuMigrations,
298    SchedulerDelayNs,
299    GpuDispatchCalls,
300    GpuUploadBytes,
301    GpuReadbackBytes,
302    GpuUploadNs,
303    GpuReadbackNs,
304    GpuSubmitToCompleteNs,
305    GpuKernelNs,
306    GpuQueueWaitNs,
307    GpuAllocCalls,
308    GpuAllocBytes,
309    GpuFreeBytes,
310    GpuCompileCalls,
311    GpuCompileNs,
312    GpuPipelineCacheHits,
313    GpuPipelineCacheMisses,
314    GpuFaults,
315    GpuRetries,
316    GpuRecoveries,
317    GpuResidualBatches,
318    GpuOverlapNs,
319    AllocationCount,
320    DeallocationCount,
321    AllocationBytes,
322    DeallocationBytes,
323    MinorFaults,
324    MajorFaults,
325    IoReadBytes,
326    IoWriteBytes,
327    IoReadSyscalls,
328    IoWriteSyscalls,
329    IoCancelledWriteBytes,
330    NetworkBytesRead,
331    NetworkBytesWritten,
332    NetworkRequests,
333    NetworkRetries,
334    PageCacheColdObservations,
335    PageCacheWarmObservations,
336    PageCacheDirectObservations,
337    FilesScanned,
338    BytesScanned,
339    SkippedFiles,
340    MatchesFound,
341    StructuredParseFailures,
342    StructuredOversizeSkips,
343    DecodeTruncations,
344    DecodeOversizeSkips,
345    InvalidPatternIndexSkips,
346    BoundaryResultCardinalityMismatches,
347    BoundarySeamTruncations,
348    LineOffsetMappingMismatches,
349    ChunkDeadlineAborts,
350    BinaryStringsNamedExclusions,
351    SkippedOverMaxSize,
352    SkippedBinary,
353    SkippedExcluded,
354    SkippedUnreadable,
355    GitObjectUnreadable,
356    SkippedArchiveTruncated,
357    BinarySectionNameUnresolved,
358    SourceTruncated,
359    StructuredSourceParseFailures,
360    ArchiveDuplicateScanUnavailable,
361    GitLfsPointer,
362    VendoredPathSuppressions,
363    ExampleSuppressions,
364    BinaryGhidraDegradedToStrings,
365    BinaryUnreadable,
366    GpuMatcherNs,
367    GpuCoalesceNs,
368    GpuDispatchNs,
369    GpuDeriveNs,
370    GpuRecallFloorNs,
371    Phase2GpuAdmissionNs,
372    GpuCoalescedBytes,
373    GpuMaxDispatchBytes,
374    GpuPresenceBits,
375    GpuUnderfireRecovered,
376    GpuTriggerBits,
377    Phase2GpuAdmitted,
378    Phase2GpuEvidenceBits,
379    Phase2GpuHaystackUploads,
380    Phase2GpuCompleteChunks,
381    Phase2GpuCompleteRows,
382    Phase2GpuExcludedOversized,
383    Phase2GpuExcludedNonAscii,
384    Phase2AlwaysAnchorChunks,
385    Phase2AlwaysAnchorCandidateRows,
386    Phase2AlwaysAnchorCandidateCount,
387    ConfirmedAnchorCandidateRows,
388    ConfirmedAnchorCandidateCount,
389    GenericKeywordCandidateRows,
390    GenericKeywordCandidateCount,
391    ConfirmedSuffixGateNs,
392    ConfirmedSuffixGateCalls,
393    ConfirmedSuffixGateSkips,
394    ConfirmedCompanionGateNs,
395    ConfirmedCompanionGateCalls,
396    ConfirmedCompanionGateDenials,
397    ConfirmedAnchorCollectNs,
398    ConfirmedAnchorCollectCalls,
399    ConfirmedExtractNs,
400    ConfirmedExtractCalls,
401    ConfirmedAnchoredMatches,
402    ConfirmedWholeChunkMatches,
403    ConfirmedHotDirectFilterSkips,
404    PostprocessFragmentsNs,
405    PostprocessFragmentsCalls,
406    PostprocessFragmentsCandidates,
407    PostprocessFragmentsMatches,
408    PostprocessDedupNs,
409    PostprocessDedupCalls,
410    Phase2AnchorCollectNs,
411    Phase2AnchorCollectCalls,
412    Phase2AnchoredVerifyCandidates,
413    Phase2AnchoredVerifyMatches,
414    Phase2WholeChunkPatterns,
415    Phase2WholeChunkMatches,
416}
417impl CounterId {
418    pub const ALL: [Self; 157] = [
419        Self::InputBytes,
420        Self::InputUnits,
421        Self::ProcessCpuTime,
422        Self::Phase2PrefilterMarkCalls,
423        Self::Phase2PrefilterGateSkips,
424        Self::Phase2PrefilterPerPatternWork,
425        Self::Phase2PrefilterHsServed,
426        Self::Phase2PrefilterRegexsetServed,
427        Self::DecodeParentChunks,
428        Self::DecodeDerivedChunks,
429        Self::DecodeExtractCalls,
430        Self::DecodeExtractBytes,
431        Self::GenericPrefilterCalls,
432        Self::GenericKeywordLines,
433        Self::GenericRegexCaptures,
434        Self::GenericEmits,
435        Self::MlBatchCalls,
436        Self::MlBatchCandidates,
437        Self::MlBatchCallsGe64,
438        Self::MlBatchCandidatesGe64,
439        Self::DecodeExtractNs,
440        Self::GenericPrefilterNs,
441        Self::GenericExtractNs,
442        Self::Phase2PrefilterHsScanNs,
443        Self::Phase2PrefilterDroppedHostNs,
444        Self::MlFeatureNs,
445        Self::MlScoreNs,
446        Self::DecodeDerivedBytes,
447        Self::HardwareCycles,
448        Self::HardwareInstructions,
449        Self::HardwareCacheReferences,
450        Self::HardwareCacheMisses,
451        Self::HardwareBranchInstructions,
452        Self::HardwareBranchMisses,
453        Self::HardwareStalledCyclesFrontend,
454        Self::HardwareStalledCyclesBackend,
455        Self::SchedulerVoluntaryContextSwitches,
456        Self::SchedulerInvoluntaryContextSwitches,
457        Self::SchedulerCpuMigrations,
458        Self::SchedulerDelayNs,
459        Self::GpuDispatchCalls,
460        Self::GpuUploadBytes,
461        Self::GpuReadbackBytes,
462        Self::GpuUploadNs,
463        Self::GpuReadbackNs,
464        Self::GpuSubmitToCompleteNs,
465        Self::GpuKernelNs,
466        Self::GpuQueueWaitNs,
467        Self::GpuAllocCalls,
468        Self::GpuAllocBytes,
469        Self::GpuFreeBytes,
470        Self::GpuCompileCalls,
471        Self::GpuCompileNs,
472        Self::GpuPipelineCacheHits,
473        Self::GpuPipelineCacheMisses,
474        Self::GpuFaults,
475        Self::GpuRetries,
476        Self::GpuRecoveries,
477        Self::GpuResidualBatches,
478        Self::GpuOverlapNs,
479        Self::AllocationCount,
480        Self::DeallocationCount,
481        Self::AllocationBytes,
482        Self::DeallocationBytes,
483        Self::MinorFaults,
484        Self::MajorFaults,
485        Self::IoReadBytes,
486        Self::IoWriteBytes,
487        Self::IoReadSyscalls,
488        Self::IoWriteSyscalls,
489        Self::IoCancelledWriteBytes,
490        Self::NetworkBytesRead,
491        Self::NetworkBytesWritten,
492        Self::NetworkRequests,
493        Self::NetworkRetries,
494        Self::PageCacheColdObservations,
495        Self::PageCacheWarmObservations,
496        Self::PageCacheDirectObservations,
497        Self::FilesScanned,
498        Self::BytesScanned,
499        Self::SkippedFiles,
500        Self::MatchesFound,
501        Self::StructuredParseFailures,
502        Self::StructuredOversizeSkips,
503        Self::DecodeTruncations,
504        Self::DecodeOversizeSkips,
505        Self::InvalidPatternIndexSkips,
506        Self::BoundaryResultCardinalityMismatches,
507        Self::BoundarySeamTruncations,
508        Self::LineOffsetMappingMismatches,
509        Self::ChunkDeadlineAborts,
510        Self::BinaryStringsNamedExclusions,
511        Self::SkippedOverMaxSize,
512        Self::SkippedBinary,
513        Self::SkippedExcluded,
514        Self::SkippedUnreadable,
515        Self::GitObjectUnreadable,
516        Self::SkippedArchiveTruncated,
517        Self::BinarySectionNameUnresolved,
518        Self::SourceTruncated,
519        Self::StructuredSourceParseFailures,
520        Self::ArchiveDuplicateScanUnavailable,
521        Self::GitLfsPointer,
522        Self::VendoredPathSuppressions,
523        Self::ExampleSuppressions,
524        Self::BinaryGhidraDegradedToStrings,
525        Self::BinaryUnreadable,
526        Self::GpuMatcherNs,
527        Self::GpuCoalesceNs,
528        Self::GpuDispatchNs,
529        Self::GpuDeriveNs,
530        Self::GpuRecallFloorNs,
531        Self::Phase2GpuAdmissionNs,
532        Self::GpuCoalescedBytes,
533        Self::GpuMaxDispatchBytes,
534        Self::GpuPresenceBits,
535        Self::GpuUnderfireRecovered,
536        Self::GpuTriggerBits,
537        Self::Phase2GpuAdmitted,
538        Self::Phase2GpuEvidenceBits,
539        Self::Phase2GpuHaystackUploads,
540        Self::Phase2GpuCompleteChunks,
541        Self::Phase2GpuCompleteRows,
542        Self::Phase2GpuExcludedOversized,
543        Self::Phase2GpuExcludedNonAscii,
544        Self::Phase2AlwaysAnchorChunks,
545        Self::Phase2AlwaysAnchorCandidateRows,
546        Self::Phase2AlwaysAnchorCandidateCount,
547        Self::ConfirmedAnchorCandidateRows,
548        Self::ConfirmedAnchorCandidateCount,
549        Self::GenericKeywordCandidateRows,
550        Self::GenericKeywordCandidateCount,
551        Self::ConfirmedSuffixGateNs,
552        Self::ConfirmedSuffixGateCalls,
553        Self::ConfirmedSuffixGateSkips,
554        Self::ConfirmedCompanionGateNs,
555        Self::ConfirmedCompanionGateCalls,
556        Self::ConfirmedCompanionGateDenials,
557        Self::ConfirmedAnchorCollectNs,
558        Self::ConfirmedAnchorCollectCalls,
559        Self::ConfirmedExtractNs,
560        Self::ConfirmedExtractCalls,
561        Self::ConfirmedAnchoredMatches,
562        Self::ConfirmedWholeChunkMatches,
563        Self::ConfirmedHotDirectFilterSkips,
564        Self::PostprocessFragmentsNs,
565        Self::PostprocessFragmentsCalls,
566        Self::PostprocessFragmentsCandidates,
567        Self::PostprocessFragmentsMatches,
568        Self::PostprocessDedupNs,
569        Self::PostprocessDedupCalls,
570        Self::Phase2AnchorCollectNs,
571        Self::Phase2AnchorCollectCalls,
572        Self::Phase2AnchoredVerifyCandidates,
573        Self::Phase2AnchoredVerifyMatches,
574        Self::Phase2WholeChunkPatterns,
575        Self::Phase2WholeChunkMatches,
576    ];
577
578    pub const fn metric_id(self) -> MetricId {
579        match self {
580            Self::InputBytes => MetricId::InputBytes,
581            Self::InputUnits => MetricId::InputUnits,
582            Self::ProcessCpuTime => MetricId::ProcessCpuTime,
583            Self::Phase2PrefilterMarkCalls => MetricId::Phase2PrefilterMarkCalls,
584            Self::Phase2PrefilterGateSkips => MetricId::Phase2PrefilterGateSkips,
585            Self::Phase2PrefilterPerPatternWork => MetricId::Phase2PrefilterPerPatternWork,
586            Self::Phase2PrefilterHsServed => MetricId::Phase2PrefilterHsServed,
587            Self::Phase2PrefilterRegexsetServed => MetricId::Phase2PrefilterRegexsetServed,
588            Self::DecodeParentChunks => MetricId::DecodeParentChunks,
589            Self::DecodeDerivedChunks => MetricId::DecodeDerivedChunks,
590            Self::DecodeExtractCalls => MetricId::DecodeExtractCalls,
591            Self::DecodeExtractBytes => MetricId::DecodeExtractBytes,
592            Self::GenericPrefilterCalls => MetricId::GenericPrefilterCalls,
593            Self::GenericKeywordLines => MetricId::GenericKeywordLines,
594            Self::GenericRegexCaptures => MetricId::GenericRegexCaptures,
595            Self::GenericEmits => MetricId::GenericEmits,
596            Self::MlBatchCalls => MetricId::MlBatchCalls,
597            Self::MlBatchCandidates => MetricId::MlBatchCandidates,
598            Self::MlBatchCallsGe64 => MetricId::MlBatchCallsGe64,
599            Self::MlBatchCandidatesGe64 => MetricId::MlBatchCandidatesGe64,
600            Self::DecodeExtractNs => MetricId::DecodeExtractNs,
601            Self::GenericPrefilterNs => MetricId::GenericPrefilterNs,
602            Self::GenericExtractNs => MetricId::GenericExtractNs,
603            Self::Phase2PrefilterHsScanNs => MetricId::Phase2PrefilterHsScanNs,
604            Self::Phase2PrefilterDroppedHostNs => MetricId::Phase2PrefilterDroppedHostNs,
605            Self::MlFeatureNs => MetricId::MlFeatureNs,
606            Self::MlScoreNs => MetricId::MlScoreNs,
607            Self::DecodeDerivedBytes => MetricId::DecodeDerivedBytes,
608            Self::HardwareCycles => MetricId::HardwareCycles,
609            Self::HardwareInstructions => MetricId::HardwareInstructions,
610            Self::HardwareCacheReferences => MetricId::HardwareCacheReferences,
611            Self::HardwareCacheMisses => MetricId::HardwareCacheMisses,
612            Self::HardwareBranchInstructions => MetricId::HardwareBranchInstructions,
613            Self::HardwareBranchMisses => MetricId::HardwareBranchMisses,
614            Self::HardwareStalledCyclesFrontend => MetricId::HardwareStalledCyclesFrontend,
615            Self::HardwareStalledCyclesBackend => MetricId::HardwareStalledCyclesBackend,
616            Self::SchedulerVoluntaryContextSwitches => MetricId::SchedulerVoluntaryContextSwitches,
617            Self::SchedulerInvoluntaryContextSwitches => {
618                MetricId::SchedulerInvoluntaryContextSwitches
619            }
620            Self::SchedulerCpuMigrations => MetricId::SchedulerCpuMigrations,
621            Self::SchedulerDelayNs => MetricId::SchedulerDelayNs,
622            Self::GpuDispatchCalls => MetricId::GpuDispatchCalls,
623            Self::GpuUploadBytes => MetricId::GpuUploadBytes,
624            Self::GpuReadbackBytes => MetricId::GpuReadbackBytes,
625            Self::GpuUploadNs => MetricId::GpuUploadNs,
626            Self::GpuReadbackNs => MetricId::GpuReadbackNs,
627            Self::GpuSubmitToCompleteNs => MetricId::GpuSubmitToCompleteNs,
628            Self::GpuKernelNs => MetricId::GpuKernelNs,
629            Self::GpuQueueWaitNs => MetricId::GpuQueueWaitNs,
630            Self::GpuAllocCalls => MetricId::GpuAllocCalls,
631            Self::GpuAllocBytes => MetricId::GpuAllocBytes,
632            Self::GpuFreeBytes => MetricId::GpuFreeBytes,
633            Self::GpuCompileCalls => MetricId::GpuCompileCalls,
634            Self::GpuCompileNs => MetricId::GpuCompileNs,
635            Self::GpuPipelineCacheHits => MetricId::GpuPipelineCacheHits,
636            Self::GpuPipelineCacheMisses => MetricId::GpuPipelineCacheMisses,
637            Self::GpuFaults => MetricId::GpuFaults,
638            Self::GpuRetries => MetricId::GpuRetries,
639            Self::GpuRecoveries => MetricId::GpuRecoveries,
640            Self::GpuResidualBatches => MetricId::GpuResidualBatches,
641            Self::GpuOverlapNs => MetricId::GpuOverlapNs,
642            Self::AllocationCount => MetricId::AllocationCount,
643            Self::DeallocationCount => MetricId::DeallocationCount,
644            Self::AllocationBytes => MetricId::AllocationBytes,
645            Self::DeallocationBytes => MetricId::DeallocationBytes,
646            Self::MinorFaults => MetricId::MinorFaults,
647            Self::MajorFaults => MetricId::MajorFaults,
648            Self::IoReadBytes => MetricId::IoReadBytes,
649            Self::IoWriteBytes => MetricId::IoWriteBytes,
650            Self::IoReadSyscalls => MetricId::IoReadSyscalls,
651            Self::IoWriteSyscalls => MetricId::IoWriteSyscalls,
652            Self::IoCancelledWriteBytes => MetricId::IoCancelledWriteBytes,
653            Self::NetworkBytesRead => MetricId::NetworkBytesRead,
654            Self::NetworkBytesWritten => MetricId::NetworkBytesWritten,
655            Self::NetworkRequests => MetricId::NetworkRequests,
656            Self::NetworkRetries => MetricId::NetworkRetries,
657            Self::PageCacheColdObservations => MetricId::PageCacheColdObservations,
658            Self::PageCacheWarmObservations => MetricId::PageCacheWarmObservations,
659            Self::PageCacheDirectObservations => MetricId::PageCacheDirectObservations,
660            Self::FilesScanned => MetricId::FilesScanned,
661            Self::BytesScanned => MetricId::BytesScanned,
662            Self::SkippedFiles => MetricId::SkippedFiles,
663            Self::MatchesFound => MetricId::MatchesFound,
664            Self::StructuredParseFailures => MetricId::StructuredParseFailures,
665            Self::StructuredOversizeSkips => MetricId::StructuredOversizeSkips,
666            Self::DecodeTruncations => MetricId::DecodeTruncations,
667            Self::DecodeOversizeSkips => MetricId::DecodeOversizeSkips,
668            Self::InvalidPatternIndexSkips => MetricId::InvalidPatternIndexSkips,
669            Self::BoundaryResultCardinalityMismatches => {
670                MetricId::BoundaryResultCardinalityMismatches
671            }
672            Self::BoundarySeamTruncations => MetricId::BoundarySeamTruncations,
673            Self::LineOffsetMappingMismatches => MetricId::LineOffsetMappingMismatches,
674            Self::ChunkDeadlineAborts => MetricId::ChunkDeadlineAborts,
675            Self::BinaryStringsNamedExclusions => MetricId::BinaryStringsNamedExclusions,
676            Self::SkippedOverMaxSize => MetricId::SkippedOverMaxSize,
677            Self::SkippedBinary => MetricId::SkippedBinary,
678            Self::SkippedExcluded => MetricId::SkippedExcluded,
679            Self::SkippedUnreadable => MetricId::SkippedUnreadable,
680            Self::GitObjectUnreadable => MetricId::GitObjectUnreadable,
681            Self::SkippedArchiveTruncated => MetricId::SkippedArchiveTruncated,
682            Self::BinarySectionNameUnresolved => MetricId::BinarySectionNameUnresolved,
683            Self::SourceTruncated => MetricId::SourceTruncated,
684            Self::StructuredSourceParseFailures => MetricId::StructuredSourceParseFailures,
685            Self::ArchiveDuplicateScanUnavailable => MetricId::ArchiveDuplicateScanUnavailable,
686            Self::GitLfsPointer => MetricId::GitLfsPointer,
687            Self::VendoredPathSuppressions => MetricId::VendoredPathSuppressions,
688            Self::ExampleSuppressions => MetricId::ExampleSuppressions,
689            Self::BinaryGhidraDegradedToStrings => MetricId::BinaryGhidraDegradedToStrings,
690            Self::BinaryUnreadable => MetricId::BinaryUnreadable,
691            Self::GpuMatcherNs => MetricId::GpuMatcherNs,
692            Self::GpuCoalesceNs => MetricId::GpuCoalesceNs,
693            Self::GpuDispatchNs => MetricId::GpuDispatchNs,
694            Self::GpuDeriveNs => MetricId::GpuDeriveNs,
695            Self::GpuRecallFloorNs => MetricId::GpuRecallFloorNs,
696            Self::Phase2GpuAdmissionNs => MetricId::Phase2GpuAdmissionNs,
697            Self::GpuCoalescedBytes => MetricId::GpuCoalescedBytes,
698            Self::GpuMaxDispatchBytes => MetricId::GpuMaxDispatchBytes,
699            Self::GpuPresenceBits => MetricId::GpuPresenceBits,
700            Self::GpuUnderfireRecovered => MetricId::GpuUnderfireRecovered,
701            Self::GpuTriggerBits => MetricId::GpuTriggerBits,
702            Self::Phase2GpuAdmitted => MetricId::Phase2GpuAdmitted,
703            Self::Phase2GpuEvidenceBits => MetricId::Phase2GpuEvidenceBits,
704            Self::Phase2GpuHaystackUploads => MetricId::Phase2GpuHaystackUploads,
705            Self::Phase2GpuCompleteChunks => MetricId::Phase2GpuCompleteChunks,
706            Self::Phase2GpuCompleteRows => MetricId::Phase2GpuCompleteRows,
707            Self::Phase2GpuExcludedOversized => MetricId::Phase2GpuExcludedOversized,
708            Self::Phase2GpuExcludedNonAscii => MetricId::Phase2GpuExcludedNonAscii,
709            Self::Phase2AlwaysAnchorChunks => MetricId::Phase2AlwaysAnchorChunks,
710            Self::Phase2AlwaysAnchorCandidateRows => MetricId::Phase2AlwaysAnchorCandidateRows,
711            Self::Phase2AlwaysAnchorCandidateCount => MetricId::Phase2AlwaysAnchorCandidateCount,
712            Self::ConfirmedAnchorCandidateRows => MetricId::ConfirmedAnchorCandidateRows,
713            Self::ConfirmedAnchorCandidateCount => MetricId::ConfirmedAnchorCandidateCount,
714            Self::GenericKeywordCandidateRows => MetricId::GenericKeywordCandidateRows,
715            Self::GenericKeywordCandidateCount => MetricId::GenericKeywordCandidateCount,
716            Self::ConfirmedSuffixGateNs => MetricId::ConfirmedSuffixGateNs,
717            Self::ConfirmedSuffixGateCalls => MetricId::ConfirmedSuffixGateCalls,
718            Self::ConfirmedSuffixGateSkips => MetricId::ConfirmedSuffixGateSkips,
719            Self::ConfirmedCompanionGateNs => MetricId::ConfirmedCompanionGateNs,
720            Self::ConfirmedCompanionGateCalls => MetricId::ConfirmedCompanionGateCalls,
721            Self::ConfirmedCompanionGateDenials => MetricId::ConfirmedCompanionGateDenials,
722            Self::ConfirmedAnchorCollectNs => MetricId::ConfirmedAnchorCollectNs,
723            Self::ConfirmedAnchorCollectCalls => MetricId::ConfirmedAnchorCollectCalls,
724            Self::ConfirmedExtractNs => MetricId::ConfirmedExtractNs,
725            Self::ConfirmedExtractCalls => MetricId::ConfirmedExtractCalls,
726            Self::ConfirmedAnchoredMatches => MetricId::ConfirmedAnchoredMatches,
727            Self::ConfirmedWholeChunkMatches => MetricId::ConfirmedWholeChunkMatches,
728            Self::ConfirmedHotDirectFilterSkips => MetricId::ConfirmedHotDirectFilterSkips,
729            Self::PostprocessFragmentsNs => MetricId::PostprocessFragmentsNs,
730            Self::PostprocessFragmentsCalls => MetricId::PostprocessFragmentsCalls,
731            Self::PostprocessFragmentsCandidates => MetricId::PostprocessFragmentsCandidates,
732            Self::PostprocessFragmentsMatches => MetricId::PostprocessFragmentsMatches,
733            Self::PostprocessDedupNs => MetricId::PostprocessDedupNs,
734            Self::PostprocessDedupCalls => MetricId::PostprocessDedupCalls,
735            Self::Phase2AnchorCollectNs => MetricId::Phase2AnchorCollectNs,
736            Self::Phase2AnchorCollectCalls => MetricId::Phase2AnchorCollectCalls,
737            Self::Phase2AnchoredVerifyCandidates => MetricId::Phase2AnchoredVerifyCandidates,
738            Self::Phase2AnchoredVerifyMatches => MetricId::Phase2AnchoredVerifyMatches,
739            Self::Phase2WholeChunkPatterns => MetricId::Phase2WholeChunkPatterns,
740            Self::Phase2WholeChunkMatches => MetricId::Phase2WholeChunkMatches,
741        }
742    }
743}
744
745/// Type-safe identifier for a latest-value metric.
746#[derive(Clone, Copy, Debug, Eq, Hash, Ord, PartialEq, PartialOrd, Serialize, Deserialize)]
747#[serde(rename_all = "kebab-case")]
748#[repr(u8)]
749pub enum GaugeId {
750    ResidentMemory = 0,
751    VirtualMemory,
752    ProcessThreads,
753    GpuResidentBytes,
754    GpuPeakResidentBytes,
755    AllocationLiveBytes,
756    AllocationPeakLiveBytes,
757    ResidentHighWaterBytes,
758    RetainedBufferBytes,
759    RetainedBufferPeakBytes,
760    GitBufferedBlobChunks,
761}
762
763impl GaugeId {
764    pub const ALL: [Self; 11] = [
765        Self::ResidentMemory,
766        Self::VirtualMemory,
767        Self::ProcessThreads,
768        Self::GpuResidentBytes,
769        Self::GpuPeakResidentBytes,
770        Self::AllocationLiveBytes,
771        Self::AllocationPeakLiveBytes,
772        Self::ResidentHighWaterBytes,
773        Self::RetainedBufferBytes,
774        Self::RetainedBufferPeakBytes,
775        Self::GitBufferedBlobChunks,
776    ];
777
778    pub const fn metric_id(self) -> MetricId {
779        match self {
780            Self::ResidentMemory => MetricId::ResidentMemory,
781            Self::VirtualMemory => MetricId::VirtualMemory,
782            Self::ProcessThreads => MetricId::ProcessThreads,
783            Self::GpuResidentBytes => MetricId::GpuResidentBytes,
784            Self::GpuPeakResidentBytes => MetricId::GpuPeakResidentBytes,
785            Self::AllocationLiveBytes => MetricId::AllocationLiveBytes,
786            Self::AllocationPeakLiveBytes => MetricId::AllocationPeakLiveBytes,
787            Self::ResidentHighWaterBytes => MetricId::ResidentHighWaterBytes,
788            Self::RetainedBufferBytes => MetricId::RetainedBufferBytes,
789            Self::RetainedBufferPeakBytes => MetricId::RetainedBufferPeakBytes,
790            Self::GitBufferedBlobChunks => MetricId::GitBufferedBlobChunks,
791        }
792    }
793}
794
795/// Stable identifier for an instantaneous causal event.
796#[derive(Clone, Copy, Debug, Eq, Hash, Ord, PartialEq, PartialOrd, Serialize, Deserialize)]
797#[serde(rename_all = "kebab-case")]
798#[repr(u8)]
799pub enum EventId {
800    BackendBatchCompleted = 0,
801    BackendRecovered,
802    CoverageGap,
803    Interrupted,
804    DetailedDiagnostic,
805    GpuAdapterAcquired,
806    GpuFault,
807    GpuCapabilityUnsupported,
808}
809
810impl EventId {
811    pub const COUNT: usize = 8;
812
813    pub const fn index(self) -> usize {
814        self as usize
815    }
816}
817
818/// Bounded fixed set of queue slots for causality links and depth gauges.
819#[derive(Clone, Copy, Debug, Eq, Hash, Ord, PartialEq, PartialOrd, Serialize, Deserialize)]
820#[serde(rename_all = "kebab-case")]
821#[repr(u8)]
822pub enum QueueId {
823    SourceWork = 0,
824    ScannerWork,
825    DecoderWork,
826    BackendBatch,
827    LiveVerification,
828    ResultMerge,
829}
830
831impl QueueId {
832    /// Every queue slot in stable wire order.
833    pub const ALL: [Self; 6] = [
834        Self::SourceWork,
835        Self::ScannerWork,
836        Self::DecoderWork,
837        Self::BackendBatch,
838        Self::LiveVerification,
839        Self::ResultMerge,
840    ];
841
842    pub const COUNT: usize = 6;
843
844    pub const fn index(self) -> usize {
845        self as usize
846    }
847
848    /// Stable text label used by profiles and operator reports.
849    pub const fn as_str(self) -> &'static str {
850        match self {
851            Self::SourceWork => "source-work",
852            Self::ScannerWork => "scanner-work",
853            Self::DecoderWork => "decoder-work",
854            Self::BackendBatch => "backend-batch",
855            Self::LiveVerification => "live-verification",
856            Self::ResultMerge => "result-merge",
857        }
858    }
859}
860
861/// A reuse cache the profiler reports hit and miss counts for.
862///
863/// Every KeyHog cache that exists to avoid repeating work reports through this
864/// one enum, so "what is our cache hit rate" has a single answer instead of one
865/// per subsystem. Record every consultation with exactly one of
866/// [`crate::record_cache_hit`] or [`crate::record_cache_miss`], so the reported
867/// rate has a real denominator.
868///
869/// Counters are indexed by [`CacheId::index`] into a fixed array of length
870/// [`CacheId::COUNT`], so recording is one relaxed atomic add with no
871/// allocation and no lookup on the hot path.
872#[derive(Clone, Copy, Debug, Eq, Hash, Ord, PartialEq, PartialOrd, Serialize, Deserialize)]
873#[serde(rename_all = "kebab-case")]
874#[repr(u8)]
875pub enum CacheId {
876    /// Persisted autoroute backend decision reused instead of re-deciding.
877    /// A miss means the scan runs without a calibrated route.
878    AutorouteDecision = 0,
879    /// Autoroute calibration measurement reused instead of re-measuring.
880    AutorouteCalibration,
881    /// Chunk skipped because the incremental scan judged it unchanged.
882    IncrementalUnchanged,
883    /// Compiled matcher artifact reused instead of recompiled. This is the
884    /// cache standing between a scan and the engine-initialization cost.
885    MatcherArtifact,
886    /// Credential verification result reused instead of re-requested. A miss
887    /// costs a network round trip, so this rate is also a rate-limit story.
888    VerifierResult,
889    /// Hyperscan compiled regex shard database reused from disk cache.
890    HyperscanShard,
891    /// Compiled GPU literal-set binary matcher reused from disk cache.
892    GpuProgram,
893    /// Pre-parsed detector JSON execution plan reused from cache.
894    DetectorPlan,
895}
896
897impl CacheId {
898    /// Every cache slot in stable wire order.
899    pub const ALL: [Self; Self::COUNT] = [
900        Self::AutorouteDecision,
901        Self::AutorouteCalibration,
902        Self::IncrementalUnchanged,
903        Self::MatcherArtifact,
904        Self::VerifierResult,
905        Self::HyperscanShard,
906        Self::GpuProgram,
907        Self::DetectorPlan,
908    ];
909
910    /// Number of variants, and the length of the profiler's counter arrays.
911    pub const COUNT: usize = 8;
912
913    /// Dense index into the profiler's per-shard counter arrays.
914    pub const fn index(self) -> usize {
915        self as usize
916    }
917
918    /// Stable text label used by profiles and operator reports.
919    pub const fn as_str(self) -> &'static str {
920        match self {
921            Self::AutorouteDecision => "autoroute-decision",
922            Self::AutorouteCalibration => "autoroute-calibration",
923            Self::IncrementalUnchanged => "incremental-unchanged",
924            Self::MatcherArtifact => "matcher-artifact",
925            Self::VerifierResult => "verifier-result",
926            Self::HyperscanShard => "hyperscan-shard",
927            Self::GpuProgram => "gpu-program",
928            Self::DetectorPlan => "detector-plan",
929        }
930    }
931}
932/// A compiler surface / artifact class that compiles matcher, plan, or execution policy data.
933#[derive(Clone, Copy, Debug, Eq, Hash, Ord, PartialEq, PartialOrd, Serialize, Deserialize)]
934#[serde(rename_all = "kebab-case")]
935#[repr(u8)]
936pub enum CompileSurfaceId {
937    /// Detector execution plans compiled from detector definitions.
938    DetectorPlan = 0,
939    /// Entropy policy tables compiled for detector thresholds.
940    EntropyPolicy,
941    /// Assignment keyword index compiled from secret and policy keywords.
942    AssignmentKeywordMatcher,
943    /// GPU literal matchers compiled from detector patterns.
944    GpuLiterals,
945    /// SIMD / Hyperscan regex database compiled from detector patterns.
946    SimdProgram,
947    /// Intermediate compile state and companion compilation.
948    CompileState,
949    /// Decode transformation policy compiled from detector specs.
950    DecodePolicy,
951    /// Checksum validator catalog and index compiled from validator specs.
952    ValidatorCatalog,
953    /// Match confidence policy compiled from detector specs.
954    ConfidencePolicy,
955    /// Credential shape rules compiled from detector specs.
956    CredentialShapes,
957    /// Detector execution policy compiled from detector specs.
958    DetectorExecutionPolicy,
959    /// Canonical hex key material policy compiled from detector specs.
960    DetectorKeyMaterialPolicy,
961    /// Detector ML policy compiled from detector specs.
962    DetectorMlPolicy,
963}
964
965impl CompileSurfaceId {
966    /// Number of distinct compile surface classes.
967    pub const COUNT: usize = 13;
968
969    /// Every compile surface in stable wire order.
970    pub const ALL: [Self; Self::COUNT] = [
971        Self::DetectorPlan,
972        Self::EntropyPolicy,
973        Self::AssignmentKeywordMatcher,
974        Self::GpuLiterals,
975        Self::SimdProgram,
976        Self::CompileState,
977        Self::DecodePolicy,
978        Self::ValidatorCatalog,
979        Self::ConfidencePolicy,
980        Self::CredentialShapes,
981        Self::DetectorExecutionPolicy,
982        Self::DetectorKeyMaterialPolicy,
983        Self::DetectorMlPolicy,
984    ];
985
986    /// Dense index into the profiler's compile-surface arrays.
987    pub const fn index(self) -> usize {
988        self as usize
989    }
990
991    /// Stable text label used by profiles and operator reports.
992    pub const fn as_str(self) -> &'static str {
993        match self {
994            Self::DetectorPlan => "detector-plan",
995            Self::EntropyPolicy => "entropy-policy",
996            Self::AssignmentKeywordMatcher => "assignment-keyword-matcher",
997            Self::GpuLiterals => "gpu-literals",
998            Self::SimdProgram => "simd-program",
999            Self::CompileState => "compile-state",
1000            Self::DecodePolicy => "decode-policy",
1001            Self::ValidatorCatalog => "validator-catalog",
1002            Self::ConfidencePolicy => "confidence-policy",
1003            Self::CredentialShapes => "credential-shapes",
1004            Self::DetectorExecutionPolicy => "detector-execution-policy",
1005            Self::DetectorKeyMaterialPolicy => "detector-key-material-policy",
1006            Self::DetectorMlPolicy => "detector-ml-policy",
1007        }
1008    }
1009
1010    /// Canonical compile entry-point symbols for this surface class.
1011    pub const fn entry_points(self) -> &'static [&'static str] {
1012        match self {
1013            Self::DetectorPlan => &[
1014                "keyhog_scanner::detector_plan::CompiledDetectorPlans::compile",
1015                "keyhog_scanner::detector_plan::CompiledDetectorPlans::compile_with_decoder_plan",
1016                "keyhog_scanner::detector_plan::compile_detector_plan",
1017                "keyhog_scanner::detector_plan::compile_metadata",
1018                "keyhog_scanner::detector_plan::DetectorResolutionIndex::compile",
1019                "keyhog_scanner::detector_plan::CompiledDetectorRelationIndex::compile",
1020            ],
1021            Self::EntropyPolicy => &[
1022                "keyhog_scanner::entropy::policy::compile_entropy_policy",
1023                "keyhog_scanner::entropy::policy::compile_entropy_policy_with_length",
1024                "keyhog_scanner::entropy::policy::CompiledEntropyPolicy::compile",
1025                "keyhog_scanner::entropy::policy::CompiledEntropyPolicy::compile_with_length",
1026                "keyhog_scanner::entropy::policy::CompiledEntropyFloorPolicy::compile",
1027            ],
1028            Self::AssignmentKeywordMatcher => &[
1029                "keyhog_scanner::assignment_keyword_matcher::AssignmentKeywordMatcher::compile",
1030            ],
1031            Self::GpuLiterals => &[
1032                "keyhog_scanner::gpu_literal_artifacts::compile_gpu_literal_artifacts",
1033                "keyhog_scanner::gpu_literal_artifacts::compile_gpu_literal_artifact_plan",
1034                "keyhog_scanner::engine::gpu_lazy_helpers::compile_gpu_literals",
1035            ],
1036            Self::SimdProgram => &[
1037                "keyhog_scanner::simd::backend::HsScanner::compile_with_opts",
1038            ],
1039            Self::CompileState => &[
1040                "keyhog_scanner::compiler::compiler_build::build_compile_state",
1041                "keyhog_scanner::compiler::compiler_compile::compile_companion",
1042                "keyhog_scanner::compiler::compiler_compile::compile_detector_companions",
1043                "keyhog_scanner::compiler::compiler_compile::compile_pattern",
1044            ],
1045            Self::DecodePolicy => &[
1046                "keyhog_scanner::decode::policy::CompiledDecodeTransformPolicy::compile",
1047            ],
1048            Self::ValidatorCatalog => &[
1049                "keyhog_scanner::checksum::compiled::CompiledValidatorCatalog::compile",
1050                "keyhog_scanner::checksum::compiled::CompiledDetectorValidators::compile",
1051            ],
1052            Self::ConfidencePolicy => &[
1053                "keyhog_scanner::confidence::policy::CompiledMatchConfidencePolicy::compile",
1054            ],
1055            Self::CredentialShapes => &[
1056                "keyhog_scanner::credential_shapes::compile_detector_shape_rule",
1057            ],
1058            Self::DetectorExecutionPolicy => &[
1059                "keyhog_scanner::detector_execution_policy::CompiledDetectorExecutionPolicy::compile",
1060            ],
1061            Self::DetectorKeyMaterialPolicy => &[
1062                "keyhog_scanner::detector_key_material_policy::CompiledDetectorKeyMaterialPolicy::compile",
1063            ],
1064            Self::DetectorMlPolicy => &[
1065                "keyhog_scanner::detector_ml_policy::CompiledDetectorMlPolicy::compile",
1066            ],
1067        }
1068    }
1069}
1070
1071/// Execution phase during which compilation occurred.
1072#[derive(Clone, Copy, Debug, Eq, Hash, Ord, PartialEq, PartialOrd, Serialize, Deserialize)]
1073#[serde(rename_all = "kebab-case")]
1074#[repr(u8)]
1075pub enum CompilePhase {
1076    /// Compilation during installer generation (`keyhog install` or compile-execution-packs).
1077    Install = 0,
1078    /// Compilation while generating packs for a candidate binary.
1079    Update,
1080    /// In-process compilation during scan execution.
1081    Scan,
1082    /// In-process compilation under explicit developer escape flag.
1083    Developer,
1084}
1085
1086impl CompilePhase {
1087    /// Number of distinct compile phases.
1088    pub const COUNT: usize = 4;
1089
1090    /// Every compile phase in stable wire order.
1091    pub const ALL: [Self; Self::COUNT] = [Self::Install, Self::Update, Self::Scan, Self::Developer];
1092
1093    /// Dense index into compile phase arrays.
1094    pub const fn index(self) -> usize {
1095        self as usize
1096    }
1097
1098    /// Stable text label used by profiles and operator reports.
1099    pub const fn as_str(self) -> &'static str {
1100        match self {
1101            Self::Install => "install",
1102            Self::Update => "update",
1103            Self::Scan => "scan",
1104            Self::Developer => "developer",
1105        }
1106    }
1107}
1108
1109/// Why one operation was attempted again.
1110///
1111/// A retry that fires is evidence of a defect, not a success, so every attempt
1112/// is counted and surfaced. There is deliberately no catch-all cause: an
1113/// unclassified failure is permanent and is not retried, which is what stops
1114/// "it will just retry" from becoming a reason to ship a racy path.
1115#[derive(Clone, Copy, Debug, Eq, Hash, Ord, PartialEq, PartialOrd, Serialize, Deserialize)]
1116#[serde(rename_all = "kebab-case")]
1117#[repr(u8)]
1118pub enum RetryCause {
1119    /// A syscall returned EINTR.
1120    Interrupted = 0,
1121    /// A syscall returned EAGAIN or EWOULDBLOCK.
1122    WouldBlock,
1123    /// ENOENT or ESTALE on a path the walker had already enumerated.
1124    VanishedUnderWalk,
1125    /// The file was replaced, truncated, or grown between the size decision
1126    /// and the completion of the read.
1127    SizeChangedUnderRead,
1128    /// EBUSY, ETXTBSY, or a sharing violation.
1129    Locked,
1130    /// A 429 or an equivalent provider throttle.
1131    RateLimited,
1132    /// Connection reset, timeout, or name resolution failure.
1133    Network,
1134    /// A git pack was rewritten while it was being read.
1135    PackRewritten,
1136}
1137
1138impl RetryCause {
1139    /// Every cause in stable wire order.
1140    pub const ALL: [Self; Self::COUNT] = [
1141        Self::Interrupted,
1142        Self::WouldBlock,
1143        Self::VanishedUnderWalk,
1144        Self::SizeChangedUnderRead,
1145        Self::Locked,
1146        Self::RateLimited,
1147        Self::Network,
1148        Self::PackRewritten,
1149    ];
1150
1151    pub const COUNT: usize = 8;
1152
1153    /// Dense index into the profiler's per-shard counter arrays.
1154    pub const fn index(self) -> usize {
1155        self as usize
1156    }
1157
1158    /// Stable text label used by profiles and operator reports.
1159    pub const fn as_str(self) -> &'static str {
1160        match self {
1161            Self::Interrupted => "interrupted",
1162            Self::WouldBlock => "would-block",
1163            Self::VanishedUnderWalk => "vanished-under-walk",
1164            Self::SizeChangedUnderRead => "size-changed-under-read",
1165            Self::Locked => "locked",
1166            Self::RateLimited => "rate-limited",
1167            Self::Network => "network",
1168            Self::PackRewritten => "pack-rewritten",
1169        }
1170    }
1171}
1172
1173/// Number of slots in every indexed counter family.
1174///
1175/// Fixed so recording is one relaxed add with no bounds negotiation. A slot
1176/// outside the range is counted as dropped rather than folded into the last
1177/// slot, because a misattributed measurement is worse than a missing one.
1178pub const INDEXED_COUNTER_SLOTS: usize = 16;
1179
1180/// An additive counter that exists once per caller-owned slot.
1181///
1182/// The caller owns the labels. A decoder registry knows slot three is base64,
1183/// so the profiler stores sixteen numbers and never a string, which is what
1184/// keeps the record path allocation-free and hash-free.
1185#[derive(Clone, Copy, Debug, Eq, Hash, Ord, PartialEq, PartialOrd, Serialize, Deserialize)]
1186#[serde(rename_all = "kebab-case")]
1187#[repr(u8)]
1188pub enum IndexedCounterId {
1189    /// Nanoseconds spent inside one decoder slot.
1190    DecoderElapsedNs = 0,
1191    /// Sub-chunks one decoder slot produced.
1192    DecoderSubchunksEmitted,
1193}
1194
1195impl IndexedCounterId {
1196    /// Every indexed family in stable wire order.
1197    pub const ALL: [Self; Self::COUNT] = [Self::DecoderElapsedNs, Self::DecoderSubchunksEmitted];
1198
1199    pub const COUNT: usize = 2;
1200
1201    pub const fn index(self) -> usize {
1202        self as usize
1203    }
1204
1205    /// Stable text label used by profiles and operator reports.
1206    pub const fn as_str(self) -> &'static str {
1207        match self {
1208            Self::DecoderElapsedNs => "decoder-elapsed-ns",
1209            Self::DecoderSubchunksEmitted => "decoder-subchunks-emitted",
1210        }
1211    }
1212}
1213
1214/// Stable identifier for a numeric annotation attached to the run timeline.
1215#[derive(Clone, Copy, Debug, Eq, Hash, Ord, PartialEq, PartialOrd, Serialize, Deserialize)]
1216#[serde(rename_all = "kebab-case")]
1217#[repr(u8)]
1218pub enum AnnotationId {
1219    DecodeDepth = 0,
1220    QueueDepth,
1221    WorkerIndex,
1222    RetryAttempt,
1223    GpuBackendKind,
1224    GpuAdapterVendor,
1225    GpuAdapterDevice,
1226    IoCacheState,
1227}
1228
1229impl From<crate::Stage> for MetricId {
1230    fn from(stage: crate::Stage) -> Self {
1231        match stage {
1232            crate::Stage::SourceAcquire => Self::SourceAcquire,
1233            crate::Stage::SourceWalk => Self::SourceWalk,
1234            crate::Stage::SourceRead => Self::SourceRead,
1235            crate::Stage::Preprocess => Self::Preprocess,
1236            crate::Stage::Phase1Triggers => Self::Phase1Triggers,
1237            crate::Stage::BackendDispatch => Self::BackendDispatch,
1238            crate::Stage::HotPatterns => Self::HotPatterns,
1239            crate::Stage::ConfirmedPatterns => Self::ConfirmedPatterns,
1240            crate::Stage::Phase2Prefilter => Self::Phase2Prefilter,
1241            crate::Stage::Phase2KeywordAc => Self::Phase2KeywordAc,
1242            crate::Stage::Phase2SharedAc => Self::Phase2SharedAc,
1243            crate::Stage::Phase2AnchoredVerify => Self::Phase2AnchoredVerify,
1244            crate::Stage::Phase2WholeChunk => Self::Phase2WholeChunk,
1245            crate::Stage::GenericDetection => Self::GenericDetection,
1246            crate::Stage::Entropy => Self::Entropy,
1247            crate::Stage::MachineLearning => Self::MachineLearning,
1248            crate::Stage::Decode => Self::Decode,
1249            crate::Stage::Suppression => Self::Suppression,
1250            crate::Stage::LiveVerification => Self::LiveVerification,
1251            crate::Stage::Reporting => Self::Reporting,
1252            crate::Stage::SourceQueueWait => Self::SourceQueueWait,
1253            crate::Stage::IncrementalLookup => Self::IncrementalLookup,
1254            crate::Stage::BackendSelect => Self::BackendSelect,
1255            crate::Stage::ResultMerge => Self::ResultMerge,
1256            crate::Stage::ScannerQueueWait => Self::ScannerQueueWait,
1257            crate::Stage::AutorouteCalibration => Self::AutorouteCalibration,
1258            crate::Stage::BoundaryScan => Self::BoundaryScan,
1259            crate::Stage::DetectorLoad => Self::DetectorLoad,
1260            crate::Stage::DetectorValidate => Self::DetectorValidate,
1261            crate::Stage::ExecutionPackSelect => Self::ExecutionPackSelect,
1262            crate::Stage::ExecutionPackMap => Self::ExecutionPackMap,
1263            crate::Stage::BackendAcquire => Self::BackendAcquire,
1264            crate::Stage::BackendInit => Self::BackendInit,
1265            crate::Stage::Teardown => Self::Teardown,
1266            crate::Stage::ScanPipeline => Self::ScanPipeline,
1267            crate::Stage::ScannerCompile => Self::ScannerCompile,
1268        }
1269    }
1270}
1271
1272/// Measurement behavior associated with a metric.
1273#[derive(Serialize, Deserialize, Clone, Copy, Debug, Eq, PartialEq)]
1274pub enum MetricKind {
1275    Counter,
1276    Duration,
1277    Gauge,
1278    Distribution,
1279}
1280
1281/// Stable unit associated with a metric value.
1282#[derive(Clone, Copy, Debug, Eq, PartialEq)]
1283pub enum MetricUnit {
1284    Bytes,
1285    Count,
1286    Milliseconds,
1287    Nanoseconds,
1288}
1289
1290/// Static metric metadata. Every string is embedded in the binary.
1291#[derive(Clone, Copy, Debug, Eq, PartialEq)]
1292pub struct MetricDescriptor {
1293    pub id: MetricId,
1294    pub name: &'static str,
1295    pub kind: MetricKind,
1296    pub unit: MetricUnit,
1297}
1298
1299const fn metric(
1300    id: MetricId,
1301    name: &'static str,
1302    kind: MetricKind,
1303    unit: MetricUnit,
1304) -> MetricDescriptor {
1305    MetricDescriptor {
1306        id,
1307        name,
1308        kind,
1309        unit,
1310    }
1311}
1312
1313/// Allocation-free registry in numeric `MetricId` order.
1314pub static METRICS: [MetricDescriptor; MetricId::COUNT] = [
1315    metric(
1316        MetricId::SourceAcquire,
1317        "source-acquire",
1318        MetricKind::Duration,
1319        MetricUnit::Nanoseconds,
1320    ),
1321    metric(
1322        MetricId::SourceWalk,
1323        "source-walk",
1324        MetricKind::Duration,
1325        MetricUnit::Nanoseconds,
1326    ),
1327    metric(
1328        MetricId::SourceRead,
1329        "source-read",
1330        MetricKind::Duration,
1331        MetricUnit::Nanoseconds,
1332    ),
1333    metric(
1334        MetricId::Preprocess,
1335        "preprocess",
1336        MetricKind::Duration,
1337        MetricUnit::Nanoseconds,
1338    ),
1339    metric(
1340        MetricId::Phase1Triggers,
1341        "phase1-triggers",
1342        MetricKind::Duration,
1343        MetricUnit::Nanoseconds,
1344    ),
1345    metric(
1346        MetricId::BackendDispatch,
1347        "backend-dispatch",
1348        MetricKind::Duration,
1349        MetricUnit::Nanoseconds,
1350    ),
1351    metric(
1352        MetricId::HotPatterns,
1353        "hot-patterns",
1354        MetricKind::Duration,
1355        MetricUnit::Nanoseconds,
1356    ),
1357    metric(
1358        MetricId::ConfirmedPatterns,
1359        "confirmed-patterns",
1360        MetricKind::Duration,
1361        MetricUnit::Nanoseconds,
1362    ),
1363    metric(
1364        MetricId::Phase2Prefilter,
1365        "phase2-prefilter",
1366        MetricKind::Duration,
1367        MetricUnit::Nanoseconds,
1368    ),
1369    metric(
1370        MetricId::Phase2KeywordAc,
1371        "phase2-keyword-ac",
1372        MetricKind::Duration,
1373        MetricUnit::Nanoseconds,
1374    ),
1375    metric(
1376        MetricId::Phase2SharedAc,
1377        "phase2-shared-ac",
1378        MetricKind::Duration,
1379        MetricUnit::Nanoseconds,
1380    ),
1381    metric(
1382        MetricId::Phase2AnchoredVerify,
1383        "phase2-anchored-verify",
1384        MetricKind::Duration,
1385        MetricUnit::Nanoseconds,
1386    ),
1387    metric(
1388        MetricId::Phase2WholeChunk,
1389        "phase2-whole-chunk",
1390        MetricKind::Duration,
1391        MetricUnit::Nanoseconds,
1392    ),
1393    metric(
1394        MetricId::GenericDetection,
1395        "generic-detection",
1396        MetricKind::Duration,
1397        MetricUnit::Nanoseconds,
1398    ),
1399    metric(
1400        MetricId::Entropy,
1401        "entropy",
1402        MetricKind::Duration,
1403        MetricUnit::Nanoseconds,
1404    ),
1405    metric(
1406        MetricId::MachineLearning,
1407        "machine-learning",
1408        MetricKind::Duration,
1409        MetricUnit::Nanoseconds,
1410    ),
1411    metric(
1412        MetricId::Decode,
1413        "decode",
1414        MetricKind::Duration,
1415        MetricUnit::Nanoseconds,
1416    ),
1417    metric(
1418        MetricId::Suppression,
1419        "suppression",
1420        MetricKind::Duration,
1421        MetricUnit::Nanoseconds,
1422    ),
1423    metric(
1424        MetricId::LiveVerification,
1425        "live-verification",
1426        MetricKind::Duration,
1427        MetricUnit::Nanoseconds,
1428    ),
1429    metric(
1430        MetricId::Reporting,
1431        "reporting",
1432        MetricKind::Duration,
1433        MetricUnit::Nanoseconds,
1434    ),
1435    metric(
1436        MetricId::SourceQueueWait,
1437        "source-queue-wait",
1438        MetricKind::Duration,
1439        MetricUnit::Nanoseconds,
1440    ),
1441    metric(
1442        MetricId::IncrementalLookup,
1443        "incremental-lookup",
1444        MetricKind::Duration,
1445        MetricUnit::Nanoseconds,
1446    ),
1447    metric(
1448        MetricId::BackendSelect,
1449        "backend-select",
1450        MetricKind::Duration,
1451        MetricUnit::Nanoseconds,
1452    ),
1453    metric(
1454        MetricId::ResultMerge,
1455        "result-merge",
1456        MetricKind::Duration,
1457        MetricUnit::Nanoseconds,
1458    ),
1459    metric(
1460        MetricId::ScannerQueueWait,
1461        "scanner-queue-wait",
1462        MetricKind::Duration,
1463        MetricUnit::Nanoseconds,
1464    ),
1465    metric(
1466        MetricId::InputBytes,
1467        "input-bytes",
1468        MetricKind::Counter,
1469        MetricUnit::Bytes,
1470    ),
1471    metric(
1472        MetricId::InputUnits,
1473        "input-units",
1474        MetricKind::Counter,
1475        MetricUnit::Count,
1476    ),
1477    metric(
1478        MetricId::WallTime,
1479        "wall-time",
1480        MetricKind::Duration,
1481        MetricUnit::Nanoseconds,
1482    ),
1483    metric(
1484        MetricId::ProcessCpuTime,
1485        "process-cpu-time",
1486        MetricKind::Counter,
1487        MetricUnit::Milliseconds,
1488    ),
1489    metric(
1490        MetricId::ResidentMemory,
1491        "resident-memory",
1492        MetricKind::Gauge,
1493        MetricUnit::Bytes,
1494    ),
1495    metric(
1496        MetricId::VirtualMemory,
1497        "virtual-memory",
1498        MetricKind::Gauge,
1499        MetricUnit::Bytes,
1500    ),
1501    metric(
1502        MetricId::ProcessThreads,
1503        "process-threads",
1504        MetricKind::Gauge,
1505        MetricUnit::Count,
1506    ),
1507    metric(
1508        MetricId::Phase2PrefilterMarkCalls,
1509        "phase2-prefilter-mark-calls",
1510        MetricKind::Counter,
1511        MetricUnit::Count,
1512    ),
1513    metric(
1514        MetricId::Phase2PrefilterGateSkips,
1515        "phase2-prefilter-gate-skips",
1516        MetricKind::Counter,
1517        MetricUnit::Count,
1518    ),
1519    metric(
1520        MetricId::Phase2PrefilterPerPatternWork,
1521        "phase2-prefilter-per-pattern-work",
1522        MetricKind::Counter,
1523        MetricUnit::Count,
1524    ),
1525    metric(
1526        MetricId::Phase2PrefilterHsServed,
1527        "phase2-prefilter-hs-served",
1528        MetricKind::Counter,
1529        MetricUnit::Count,
1530    ),
1531    metric(
1532        MetricId::Phase2PrefilterRegexsetServed,
1533        "phase2-prefilter-regexset-served",
1534        MetricKind::Counter,
1535        MetricUnit::Count,
1536    ),
1537    metric(
1538        MetricId::DecodeParentChunks,
1539        "decode-parent-chunks",
1540        MetricKind::Counter,
1541        MetricUnit::Count,
1542    ),
1543    metric(
1544        MetricId::DecodeDerivedChunks,
1545        "decode-derived-chunks",
1546        MetricKind::Counter,
1547        MetricUnit::Count,
1548    ),
1549    metric(
1550        MetricId::DecodeExtractCalls,
1551        "decode-extract-calls",
1552        MetricKind::Counter,
1553        MetricUnit::Count,
1554    ),
1555    metric(
1556        MetricId::DecodeExtractBytes,
1557        "decode-extract-bytes",
1558        MetricKind::Counter,
1559        MetricUnit::Bytes,
1560    ),
1561    metric(
1562        MetricId::GenericPrefilterCalls,
1563        "generic-prefilter-calls",
1564        MetricKind::Counter,
1565        MetricUnit::Count,
1566    ),
1567    metric(
1568        MetricId::GenericKeywordLines,
1569        "generic-keyword-lines",
1570        MetricKind::Counter,
1571        MetricUnit::Count,
1572    ),
1573    metric(
1574        MetricId::GenericRegexCaptures,
1575        "generic-regex-captures",
1576        MetricKind::Counter,
1577        MetricUnit::Count,
1578    ),
1579    metric(
1580        MetricId::GenericEmits,
1581        "generic-emits",
1582        MetricKind::Counter,
1583        MetricUnit::Count,
1584    ),
1585    metric(
1586        MetricId::MlBatchCalls,
1587        "ml-batch-calls",
1588        MetricKind::Counter,
1589        MetricUnit::Count,
1590    ),
1591    metric(
1592        MetricId::MlBatchCandidates,
1593        "ml-batch-candidates",
1594        MetricKind::Counter,
1595        MetricUnit::Count,
1596    ),
1597    metric(
1598        MetricId::MlBatchCallsGe64,
1599        "ml-batch-calls-ge64",
1600        MetricKind::Counter,
1601        MetricUnit::Count,
1602    ),
1603    metric(
1604        MetricId::MlBatchCandidatesGe64,
1605        "ml-batch-candidates-ge64",
1606        MetricKind::Counter,
1607        MetricUnit::Count,
1608    ),
1609    metric(
1610        MetricId::DecodeExtractNs,
1611        "decode-extract-ns",
1612        MetricKind::Counter,
1613        MetricUnit::Nanoseconds,
1614    ),
1615    metric(
1616        MetricId::GenericPrefilterNs,
1617        "generic-prefilter-ns",
1618        MetricKind::Counter,
1619        MetricUnit::Nanoseconds,
1620    ),
1621    metric(
1622        MetricId::GenericExtractNs,
1623        "generic-extract-ns",
1624        MetricKind::Counter,
1625        MetricUnit::Nanoseconds,
1626    ),
1627    metric(
1628        MetricId::Phase2PrefilterHsScanNs,
1629        "phase2-prefilter-hs-scan-ns",
1630        MetricKind::Counter,
1631        MetricUnit::Nanoseconds,
1632    ),
1633    metric(
1634        MetricId::Phase2PrefilterDroppedHostNs,
1635        "phase2-prefilter-dropped-host-ns",
1636        MetricKind::Counter,
1637        MetricUnit::Nanoseconds,
1638    ),
1639    metric(
1640        MetricId::MlFeatureNs,
1641        "ml-feature-ns",
1642        MetricKind::Counter,
1643        MetricUnit::Nanoseconds,
1644    ),
1645    metric(
1646        MetricId::MlScoreNs,
1647        "ml-score-ns",
1648        MetricKind::Counter,
1649        MetricUnit::Nanoseconds,
1650    ),
1651    metric(
1652        MetricId::MlBatchSize,
1653        "ml-batch-size",
1654        MetricKind::Distribution,
1655        MetricUnit::Count,
1656    ),
1657    metric(
1658        MetricId::DecodeDerivedBytes,
1659        "decode-derived-bytes",
1660        MetricKind::Counter,
1661        MetricUnit::Bytes,
1662    ),
1663    metric(
1664        MetricId::HardwareCycles,
1665        "hardware-cycles",
1666        MetricKind::Counter,
1667        MetricUnit::Count,
1668    ),
1669    metric(
1670        MetricId::HardwareInstructions,
1671        "hardware-instructions",
1672        MetricKind::Counter,
1673        MetricUnit::Count,
1674    ),
1675    metric(
1676        MetricId::HardwareCacheReferences,
1677        "hardware-cache-references",
1678        MetricKind::Counter,
1679        MetricUnit::Count,
1680    ),
1681    metric(
1682        MetricId::HardwareCacheMisses,
1683        "hardware-cache-misses",
1684        MetricKind::Counter,
1685        MetricUnit::Count,
1686    ),
1687    metric(
1688        MetricId::HardwareBranchInstructions,
1689        "hardware-branch-instructions",
1690        MetricKind::Counter,
1691        MetricUnit::Count,
1692    ),
1693    metric(
1694        MetricId::HardwareBranchMisses,
1695        "hardware-branch-misses",
1696        MetricKind::Counter,
1697        MetricUnit::Count,
1698    ),
1699    metric(
1700        MetricId::HardwareStalledCyclesFrontend,
1701        "hardware-stalled-cycles-frontend",
1702        MetricKind::Counter,
1703        MetricUnit::Count,
1704    ),
1705    metric(
1706        MetricId::HardwareStalledCyclesBackend,
1707        "hardware-stalled-cycles-backend",
1708        MetricKind::Counter,
1709        MetricUnit::Count,
1710    ),
1711    metric(
1712        MetricId::SchedulerVoluntaryContextSwitches,
1713        "scheduler-voluntary-context-switches",
1714        MetricKind::Counter,
1715        MetricUnit::Count,
1716    ),
1717    metric(
1718        MetricId::SchedulerInvoluntaryContextSwitches,
1719        "scheduler-involuntary-context-switches",
1720        MetricKind::Counter,
1721        MetricUnit::Count,
1722    ),
1723    metric(
1724        MetricId::SchedulerCpuMigrations,
1725        "scheduler-cpu-migrations",
1726        MetricKind::Counter,
1727        MetricUnit::Count,
1728    ),
1729    metric(
1730        MetricId::SchedulerDelayNs,
1731        "scheduler-delay-ns",
1732        MetricKind::Counter,
1733        MetricUnit::Nanoseconds,
1734    ),
1735    metric(
1736        MetricId::GpuDispatchCalls,
1737        "gpu-dispatch-calls",
1738        MetricKind::Counter,
1739        MetricUnit::Count,
1740    ),
1741    metric(
1742        MetricId::GpuUploadBytes,
1743        "gpu-upload-bytes",
1744        MetricKind::Counter,
1745        MetricUnit::Bytes,
1746    ),
1747    metric(
1748        MetricId::GpuReadbackBytes,
1749        "gpu-readback-bytes",
1750        MetricKind::Counter,
1751        MetricUnit::Bytes,
1752    ),
1753    metric(
1754        MetricId::GpuUploadNs,
1755        "gpu-upload-ns",
1756        MetricKind::Counter,
1757        MetricUnit::Nanoseconds,
1758    ),
1759    metric(
1760        MetricId::GpuReadbackNs,
1761        "gpu-readback-ns",
1762        MetricKind::Counter,
1763        MetricUnit::Nanoseconds,
1764    ),
1765    metric(
1766        MetricId::GpuSubmitToCompleteNs,
1767        "gpu-submit-to-complete-ns",
1768        MetricKind::Counter,
1769        MetricUnit::Nanoseconds,
1770    ),
1771    metric(
1772        MetricId::GpuKernelNs,
1773        "gpu-kernel-ns",
1774        MetricKind::Counter,
1775        MetricUnit::Nanoseconds,
1776    ),
1777    metric(
1778        MetricId::GpuQueueWaitNs,
1779        "gpu-queue-wait-ns",
1780        MetricKind::Counter,
1781        MetricUnit::Nanoseconds,
1782    ),
1783    metric(
1784        MetricId::GpuAllocCalls,
1785        "gpu-alloc-calls",
1786        MetricKind::Counter,
1787        MetricUnit::Count,
1788    ),
1789    metric(
1790        MetricId::GpuAllocBytes,
1791        "gpu-alloc-bytes",
1792        MetricKind::Counter,
1793        MetricUnit::Bytes,
1794    ),
1795    metric(
1796        MetricId::GpuFreeBytes,
1797        "gpu-free-bytes",
1798        MetricKind::Counter,
1799        MetricUnit::Bytes,
1800    ),
1801    metric(
1802        MetricId::GpuCompileCalls,
1803        "gpu-compile-calls",
1804        MetricKind::Counter,
1805        MetricUnit::Count,
1806    ),
1807    metric(
1808        MetricId::GpuCompileNs,
1809        "gpu-compile-ns",
1810        MetricKind::Counter,
1811        MetricUnit::Nanoseconds,
1812    ),
1813    metric(
1814        MetricId::GpuPipelineCacheHits,
1815        "gpu-pipeline-cache-hits",
1816        MetricKind::Counter,
1817        MetricUnit::Count,
1818    ),
1819    metric(
1820        MetricId::GpuPipelineCacheMisses,
1821        "gpu-pipeline-cache-misses",
1822        MetricKind::Counter,
1823        MetricUnit::Count,
1824    ),
1825    metric(
1826        MetricId::GpuFaults,
1827        "gpu-faults",
1828        MetricKind::Counter,
1829        MetricUnit::Count,
1830    ),
1831    metric(
1832        MetricId::GpuRetries,
1833        "gpu-retries",
1834        MetricKind::Counter,
1835        MetricUnit::Count,
1836    ),
1837    metric(
1838        MetricId::GpuRecoveries,
1839        "gpu-recoveries",
1840        MetricKind::Counter,
1841        MetricUnit::Count,
1842    ),
1843    metric(
1844        MetricId::GpuResidualBatches,
1845        "gpu-residual-batches",
1846        MetricKind::Counter,
1847        MetricUnit::Count,
1848    ),
1849    metric(
1850        MetricId::GpuOverlapNs,
1851        "gpu-overlap-ns",
1852        MetricKind::Counter,
1853        MetricUnit::Nanoseconds,
1854    ),
1855    metric(
1856        MetricId::GpuResidentBytes,
1857        "gpu-resident-bytes",
1858        MetricKind::Gauge,
1859        MetricUnit::Bytes,
1860    ),
1861    metric(
1862        MetricId::GpuPeakResidentBytes,
1863        "gpu-peak-resident-bytes",
1864        MetricKind::Gauge,
1865        MetricUnit::Bytes,
1866    ),
1867    metric(
1868        MetricId::AllocationCount,
1869        "allocation-count",
1870        MetricKind::Counter,
1871        MetricUnit::Count,
1872    ),
1873    metric(
1874        MetricId::DeallocationCount,
1875        "deallocation-count",
1876        MetricKind::Counter,
1877        MetricUnit::Count,
1878    ),
1879    metric(
1880        MetricId::AllocationBytes,
1881        "allocation-bytes",
1882        MetricKind::Counter,
1883        MetricUnit::Bytes,
1884    ),
1885    metric(
1886        MetricId::DeallocationBytes,
1887        "deallocation-bytes",
1888        MetricKind::Counter,
1889        MetricUnit::Bytes,
1890    ),
1891    metric(
1892        MetricId::AllocationLiveBytes,
1893        "allocation-live-bytes",
1894        MetricKind::Gauge,
1895        MetricUnit::Bytes,
1896    ),
1897    metric(
1898        MetricId::AllocationPeakLiveBytes,
1899        "allocation-peak-live-bytes",
1900        MetricKind::Gauge,
1901        MetricUnit::Bytes,
1902    ),
1903    metric(
1904        MetricId::MinorFaults,
1905        "minor-faults",
1906        MetricKind::Counter,
1907        MetricUnit::Count,
1908    ),
1909    metric(
1910        MetricId::MajorFaults,
1911        "major-faults",
1912        MetricKind::Counter,
1913        MetricUnit::Count,
1914    ),
1915    metric(
1916        MetricId::IoReadBytes,
1917        "io-read-bytes",
1918        MetricKind::Counter,
1919        MetricUnit::Bytes,
1920    ),
1921    metric(
1922        MetricId::IoWriteBytes,
1923        "io-write-bytes",
1924        MetricKind::Counter,
1925        MetricUnit::Bytes,
1926    ),
1927    metric(
1928        MetricId::IoReadSyscalls,
1929        "io-read-syscalls",
1930        MetricKind::Counter,
1931        MetricUnit::Count,
1932    ),
1933    metric(
1934        MetricId::IoWriteSyscalls,
1935        "io-write-syscalls",
1936        MetricKind::Counter,
1937        MetricUnit::Count,
1938    ),
1939    metric(
1940        MetricId::IoCancelledWriteBytes,
1941        "io-cancelled-write-bytes",
1942        MetricKind::Counter,
1943        MetricUnit::Bytes,
1944    ),
1945    metric(
1946        MetricId::ResidentHighWaterBytes,
1947        "resident-high-water-bytes",
1948        MetricKind::Gauge,
1949        MetricUnit::Bytes,
1950    ),
1951    metric(
1952        MetricId::RetainedBufferBytes,
1953        "retained-buffer-bytes",
1954        MetricKind::Gauge,
1955        MetricUnit::Bytes,
1956    ),
1957    metric(
1958        MetricId::RetainedBufferPeakBytes,
1959        "retained-buffer-peak-bytes",
1960        MetricKind::Gauge,
1961        MetricUnit::Bytes,
1962    ),
1963    metric(
1964        MetricId::NetworkBytesRead,
1965        "network-bytes-read",
1966        MetricKind::Counter,
1967        MetricUnit::Bytes,
1968    ),
1969    metric(
1970        MetricId::NetworkBytesWritten,
1971        "network-bytes-written",
1972        MetricKind::Counter,
1973        MetricUnit::Bytes,
1974    ),
1975    metric(
1976        MetricId::NetworkRequests,
1977        "network-requests",
1978        MetricKind::Counter,
1979        MetricUnit::Count,
1980    ),
1981    metric(
1982        MetricId::NetworkRetries,
1983        "network-retries",
1984        MetricKind::Counter,
1985        MetricUnit::Count,
1986    ),
1987    metric(
1988        MetricId::PageCacheColdObservations,
1989        "page-cache-cold-observations",
1990        MetricKind::Counter,
1991        MetricUnit::Count,
1992    ),
1993    metric(
1994        MetricId::PageCacheWarmObservations,
1995        "page-cache-warm-observations",
1996        MetricKind::Counter,
1997        MetricUnit::Count,
1998    ),
1999    metric(
2000        MetricId::PageCacheDirectObservations,
2001        "page-cache-direct-observations",
2002        MetricKind::Counter,
2003        MetricUnit::Count,
2004    ),
2005    metric(
2006        MetricId::FsOpenLatencyNs,
2007        "fs-open-latency-ns",
2008        MetricKind::Distribution,
2009        MetricUnit::Nanoseconds,
2010    ),
2011    metric(
2012        MetricId::FsReadLatencyNs,
2013        "fs-read-latency-ns",
2014        MetricKind::Distribution,
2015        MetricUnit::Nanoseconds,
2016    ),
2017    metric(
2018        MetricId::FsMetadataLatencyNs,
2019        "fs-metadata-latency-ns",
2020        MetricKind::Distribution,
2021        MetricUnit::Nanoseconds,
2022    ),
2023    metric(
2024        MetricId::NetworkLatencyNs,
2025        "network-latency-ns",
2026        MetricKind::Distribution,
2027        MetricUnit::Nanoseconds,
2028    ),
2029    metric(
2030        MetricId::AutorouteCalibration,
2031        "autoroute-calibration",
2032        MetricKind::Duration,
2033        MetricUnit::Nanoseconds,
2034    ),
2035    metric(
2036        MetricId::BoundaryScan,
2037        "boundary-scan",
2038        MetricKind::Duration,
2039        MetricUnit::Nanoseconds,
2040    ),
2041    metric(
2042        MetricId::DetectorLoad,
2043        "detector-load",
2044        MetricKind::Duration,
2045        MetricUnit::Nanoseconds,
2046    ),
2047    metric(
2048        MetricId::DetectorValidate,
2049        "detector-validate",
2050        MetricKind::Duration,
2051        MetricUnit::Nanoseconds,
2052    ),
2053    metric(
2054        MetricId::ExecutionPackSelect,
2055        "execution-pack-select",
2056        MetricKind::Duration,
2057        MetricUnit::Nanoseconds,
2058    ),
2059    metric(
2060        MetricId::ExecutionPackMap,
2061        "execution-pack-map",
2062        MetricKind::Duration,
2063        MetricUnit::Nanoseconds,
2064    ),
2065    metric(
2066        MetricId::BackendAcquire,
2067        "backend-acquire",
2068        MetricKind::Duration,
2069        MetricUnit::Nanoseconds,
2070    ),
2071    metric(
2072        MetricId::BackendInit,
2073        "backend-init",
2074        MetricKind::Duration,
2075        MetricUnit::Nanoseconds,
2076    ),
2077    metric(
2078        MetricId::Teardown,
2079        "teardown",
2080        MetricKind::Duration,
2081        MetricUnit::Nanoseconds,
2082    ),
2083    metric(
2084        MetricId::ScanPipeline,
2085        "scan-pipeline",
2086        MetricKind::Duration,
2087        MetricUnit::Nanoseconds,
2088    ),
2089    metric(
2090        MetricId::ScannerCompile,
2091        "scanner-compile",
2092        MetricKind::Duration,
2093        MetricUnit::Nanoseconds,
2094    ),
2095    metric(
2096        MetricId::FilesScanned,
2097        "files-scanned",
2098        MetricKind::Counter,
2099        MetricUnit::Count,
2100    ),
2101    metric(
2102        MetricId::BytesScanned,
2103        "bytes-scanned",
2104        MetricKind::Counter,
2105        MetricUnit::Bytes,
2106    ),
2107    metric(
2108        MetricId::SkippedFiles,
2109        "skipped-files",
2110        MetricKind::Counter,
2111        MetricUnit::Count,
2112    ),
2113    metric(
2114        MetricId::MatchesFound,
2115        "matches-found",
2116        MetricKind::Counter,
2117        MetricUnit::Count,
2118    ),
2119    metric(
2120        MetricId::StructuredParseFailures,
2121        "structured-parse-failures",
2122        MetricKind::Counter,
2123        MetricUnit::Count,
2124    ),
2125    metric(
2126        MetricId::StructuredOversizeSkips,
2127        "structured-oversize-skips",
2128        MetricKind::Counter,
2129        MetricUnit::Count,
2130    ),
2131    metric(
2132        MetricId::DecodeTruncations,
2133        "decode-truncations",
2134        MetricKind::Counter,
2135        MetricUnit::Count,
2136    ),
2137    metric(
2138        MetricId::DecodeOversizeSkips,
2139        "decode-oversize-skips",
2140        MetricKind::Counter,
2141        MetricUnit::Count,
2142    ),
2143    metric(
2144        MetricId::InvalidPatternIndexSkips,
2145        "invalid-pattern-index-skips",
2146        MetricKind::Counter,
2147        MetricUnit::Count,
2148    ),
2149    metric(
2150        MetricId::BoundaryResultCardinalityMismatches,
2151        "boundary-result-cardinality-mismatches",
2152        MetricKind::Counter,
2153        MetricUnit::Count,
2154    ),
2155    metric(
2156        MetricId::BoundarySeamTruncations,
2157        "boundary-seam-truncations",
2158        MetricKind::Counter,
2159        MetricUnit::Count,
2160    ),
2161    metric(
2162        MetricId::LineOffsetMappingMismatches,
2163        "line-offset-mapping-mismatches",
2164        MetricKind::Counter,
2165        MetricUnit::Count,
2166    ),
2167    metric(
2168        MetricId::ChunkDeadlineAborts,
2169        "chunk-deadline-aborts",
2170        MetricKind::Counter,
2171        MetricUnit::Count,
2172    ),
2173    metric(
2174        MetricId::BinaryStringsNamedExclusions,
2175        "binary-strings-named-exclusions",
2176        MetricKind::Counter,
2177        MetricUnit::Count,
2178    ),
2179    metric(
2180        MetricId::SkippedOverMaxSize,
2181        "skipped-over-max-size",
2182        MetricKind::Counter,
2183        MetricUnit::Count,
2184    ),
2185    metric(
2186        MetricId::SkippedBinary,
2187        "skipped-binary",
2188        MetricKind::Counter,
2189        MetricUnit::Count,
2190    ),
2191    metric(
2192        MetricId::SkippedExcluded,
2193        "skipped-excluded",
2194        MetricKind::Counter,
2195        MetricUnit::Count,
2196    ),
2197    metric(
2198        MetricId::SkippedUnreadable,
2199        "skipped-unreadable",
2200        MetricKind::Counter,
2201        MetricUnit::Count,
2202    ),
2203    metric(
2204        MetricId::GitObjectUnreadable,
2205        "git-object-unreadable",
2206        MetricKind::Counter,
2207        MetricUnit::Count,
2208    ),
2209    metric(
2210        MetricId::SkippedArchiveTruncated,
2211        "skipped-archive-truncated",
2212        MetricKind::Counter,
2213        MetricUnit::Count,
2214    ),
2215    metric(
2216        MetricId::BinarySectionNameUnresolved,
2217        "binary-section-name-unresolved",
2218        MetricKind::Counter,
2219        MetricUnit::Count,
2220    ),
2221    metric(
2222        MetricId::SourceTruncated,
2223        "source-truncated",
2224        MetricKind::Counter,
2225        MetricUnit::Count,
2226    ),
2227    metric(
2228        MetricId::StructuredSourceParseFailures,
2229        "structured-source-parse-failures",
2230        MetricKind::Counter,
2231        MetricUnit::Count,
2232    ),
2233    metric(
2234        MetricId::ArchiveDuplicateScanUnavailable,
2235        "archive-duplicate-scan-unavailable",
2236        MetricKind::Counter,
2237        MetricUnit::Count,
2238    ),
2239    metric(
2240        MetricId::GitLfsPointer,
2241        "git-lfs-pointer",
2242        MetricKind::Counter,
2243        MetricUnit::Count,
2244    ),
2245    metric(
2246        MetricId::VendoredPathSuppressions,
2247        "vendored-path-suppressions",
2248        MetricKind::Counter,
2249        MetricUnit::Count,
2250    ),
2251    metric(
2252        MetricId::ExampleSuppressions,
2253        "example-suppressions",
2254        MetricKind::Counter,
2255        MetricUnit::Count,
2256    ),
2257    metric(
2258        MetricId::BinaryGhidraDegradedToStrings,
2259        "binary-ghidra-degraded-to-strings",
2260        MetricKind::Counter,
2261        MetricUnit::Count,
2262    ),
2263    metric(
2264        MetricId::BinaryUnreadable,
2265        "binary-unreadable",
2266        MetricKind::Counter,
2267        MetricUnit::Count,
2268    ),
2269    metric(
2270        MetricId::GitBufferedBlobChunks,
2271        "git-buffered-blob-chunks",
2272        MetricKind::Gauge,
2273        MetricUnit::Count,
2274    ),
2275    metric(
2276        MetricId::GpuMatcherNs,
2277        "gpu-matcher-ns",
2278        MetricKind::Counter,
2279        MetricUnit::Nanoseconds,
2280    ),
2281    metric(
2282        MetricId::GpuCoalesceNs,
2283        "gpu-coalesce-ns",
2284        MetricKind::Counter,
2285        MetricUnit::Nanoseconds,
2286    ),
2287    metric(
2288        MetricId::GpuDispatchNs,
2289        "gpu-dispatch-ns",
2290        MetricKind::Counter,
2291        MetricUnit::Nanoseconds,
2292    ),
2293    metric(
2294        MetricId::GpuDeriveNs,
2295        "gpu-derive-ns",
2296        MetricKind::Counter,
2297        MetricUnit::Nanoseconds,
2298    ),
2299    metric(
2300        MetricId::GpuRecallFloorNs,
2301        "gpu-recall-floor-ns",
2302        MetricKind::Counter,
2303        MetricUnit::Nanoseconds,
2304    ),
2305    metric(
2306        MetricId::Phase2GpuAdmissionNs,
2307        "phase2-gpu-admission-ns",
2308        MetricKind::Counter,
2309        MetricUnit::Nanoseconds,
2310    ),
2311    metric(
2312        MetricId::GpuCoalescedBytes,
2313        "gpu-coalesced-bytes",
2314        MetricKind::Counter,
2315        MetricUnit::Bytes,
2316    ),
2317    metric(
2318        MetricId::GpuMaxDispatchBytes,
2319        "gpu-max-dispatch-bytes",
2320        MetricKind::Counter,
2321        MetricUnit::Bytes,
2322    ),
2323    metric(
2324        MetricId::GpuPresenceBits,
2325        "gpu-presence-bits",
2326        MetricKind::Counter,
2327        MetricUnit::Count,
2328    ),
2329    metric(
2330        MetricId::GpuUnderfireRecovered,
2331        "gpu-underfire-recovered",
2332        MetricKind::Counter,
2333        MetricUnit::Count,
2334    ),
2335    metric(
2336        MetricId::GpuTriggerBits,
2337        "gpu-trigger-bits",
2338        MetricKind::Counter,
2339        MetricUnit::Count,
2340    ),
2341    metric(
2342        MetricId::Phase2GpuAdmitted,
2343        "phase2-gpu-admitted",
2344        MetricKind::Counter,
2345        MetricUnit::Count,
2346    ),
2347    metric(
2348        MetricId::Phase2GpuEvidenceBits,
2349        "phase2-gpu-evidence-bits",
2350        MetricKind::Counter,
2351        MetricUnit::Count,
2352    ),
2353    metric(
2354        MetricId::Phase2GpuHaystackUploads,
2355        "phase2-gpu-haystack-uploads",
2356        MetricKind::Counter,
2357        MetricUnit::Count,
2358    ),
2359    metric(
2360        MetricId::Phase2GpuCompleteChunks,
2361        "phase2-gpu-complete-chunks",
2362        MetricKind::Counter,
2363        MetricUnit::Count,
2364    ),
2365    metric(
2366        MetricId::Phase2GpuCompleteRows,
2367        "phase2-gpu-complete-rows",
2368        MetricKind::Counter,
2369        MetricUnit::Count,
2370    ),
2371    metric(
2372        MetricId::Phase2GpuExcludedOversized,
2373        "phase2-gpu-excluded-oversized",
2374        MetricKind::Counter,
2375        MetricUnit::Count,
2376    ),
2377    metric(
2378        MetricId::Phase2GpuExcludedNonAscii,
2379        "phase2-gpu-excluded-non-ascii",
2380        MetricKind::Counter,
2381        MetricUnit::Count,
2382    ),
2383    metric(
2384        MetricId::Phase2AlwaysAnchorChunks,
2385        "phase2-always-anchor-chunks",
2386        MetricKind::Counter,
2387        MetricUnit::Count,
2388    ),
2389    metric(
2390        MetricId::Phase2AlwaysAnchorCandidateRows,
2391        "phase2-always-anchor-candidate-rows",
2392        MetricKind::Counter,
2393        MetricUnit::Count,
2394    ),
2395    metric(
2396        MetricId::Phase2AlwaysAnchorCandidateCount,
2397        "phase2-always-anchor-candidate-count",
2398        MetricKind::Counter,
2399        MetricUnit::Count,
2400    ),
2401    metric(
2402        MetricId::ConfirmedAnchorCandidateRows,
2403        "confirmed-anchor-candidate-rows",
2404        MetricKind::Counter,
2405        MetricUnit::Count,
2406    ),
2407    metric(
2408        MetricId::ConfirmedAnchorCandidateCount,
2409        "confirmed-anchor-candidate-count",
2410        MetricKind::Counter,
2411        MetricUnit::Count,
2412    ),
2413    metric(
2414        MetricId::GenericKeywordCandidateRows,
2415        "generic-keyword-candidate-rows",
2416        MetricKind::Counter,
2417        MetricUnit::Count,
2418    ),
2419    metric(
2420        MetricId::GenericKeywordCandidateCount,
2421        "generic-keyword-candidate-count",
2422        MetricKind::Counter,
2423        MetricUnit::Count,
2424    ),
2425    metric(
2426        MetricId::ConfirmedSuffixGateNs,
2427        "confirmed-suffix-gate-ns",
2428        MetricKind::Counter,
2429        MetricUnit::Nanoseconds,
2430    ),
2431    metric(
2432        MetricId::ConfirmedSuffixGateCalls,
2433        "confirmed-suffix-gate-calls",
2434        MetricKind::Counter,
2435        MetricUnit::Count,
2436    ),
2437    metric(
2438        MetricId::ConfirmedSuffixGateSkips,
2439        "confirmed-suffix-gate-skips",
2440        MetricKind::Counter,
2441        MetricUnit::Count,
2442    ),
2443    metric(
2444        MetricId::ConfirmedCompanionGateNs,
2445        "confirmed-companion-gate-ns",
2446        MetricKind::Counter,
2447        MetricUnit::Nanoseconds,
2448    ),
2449    metric(
2450        MetricId::ConfirmedCompanionGateCalls,
2451        "confirmed-companion-gate-calls",
2452        MetricKind::Counter,
2453        MetricUnit::Count,
2454    ),
2455    metric(
2456        MetricId::ConfirmedCompanionGateDenials,
2457        "confirmed-companion-gate-denials",
2458        MetricKind::Counter,
2459        MetricUnit::Count,
2460    ),
2461    metric(
2462        MetricId::ConfirmedAnchorCollectNs,
2463        "confirmed-anchor-collect-ns",
2464        MetricKind::Counter,
2465        MetricUnit::Nanoseconds,
2466    ),
2467    metric(
2468        MetricId::ConfirmedAnchorCollectCalls,
2469        "confirmed-anchor-collect-calls",
2470        MetricKind::Counter,
2471        MetricUnit::Count,
2472    ),
2473    metric(
2474        MetricId::ConfirmedExtractNs,
2475        "confirmed-extract-ns",
2476        MetricKind::Counter,
2477        MetricUnit::Nanoseconds,
2478    ),
2479    metric(
2480        MetricId::ConfirmedExtractCalls,
2481        "confirmed-extract-calls",
2482        MetricKind::Counter,
2483        MetricUnit::Count,
2484    ),
2485    metric(
2486        MetricId::ConfirmedAnchoredMatches,
2487        "confirmed-anchored-matches",
2488        MetricKind::Counter,
2489        MetricUnit::Count,
2490    ),
2491    metric(
2492        MetricId::ConfirmedWholeChunkMatches,
2493        "confirmed-whole-chunk-matches",
2494        MetricKind::Counter,
2495        MetricUnit::Count,
2496    ),
2497    metric(
2498        MetricId::ConfirmedHotDirectFilterSkips,
2499        "confirmed-hot-direct-filter-skips",
2500        MetricKind::Counter,
2501        MetricUnit::Count,
2502    ),
2503    metric(
2504        MetricId::PostprocessFragmentsNs,
2505        "postprocess-fragments-ns",
2506        MetricKind::Counter,
2507        MetricUnit::Nanoseconds,
2508    ),
2509    metric(
2510        MetricId::PostprocessFragmentsCalls,
2511        "postprocess-fragments-calls",
2512        MetricKind::Counter,
2513        MetricUnit::Count,
2514    ),
2515    metric(
2516        MetricId::PostprocessFragmentsCandidates,
2517        "postprocess-fragments-candidates",
2518        MetricKind::Counter,
2519        MetricUnit::Count,
2520    ),
2521    metric(
2522        MetricId::PostprocessFragmentsMatches,
2523        "postprocess-fragments-matches",
2524        MetricKind::Counter,
2525        MetricUnit::Count,
2526    ),
2527    metric(
2528        MetricId::PostprocessDedupNs,
2529        "postprocess-dedup-ns",
2530        MetricKind::Counter,
2531        MetricUnit::Nanoseconds,
2532    ),
2533    metric(
2534        MetricId::PostprocessDedupCalls,
2535        "postprocess-dedup-calls",
2536        MetricKind::Counter,
2537        MetricUnit::Count,
2538    ),
2539    metric(
2540        MetricId::Phase2AnchorCollectNs,
2541        "phase2-anchor-collect-ns",
2542        MetricKind::Counter,
2543        MetricUnit::Nanoseconds,
2544    ),
2545    metric(
2546        MetricId::Phase2AnchorCollectCalls,
2547        "phase2-anchor-collect-calls",
2548        MetricKind::Counter,
2549        MetricUnit::Count,
2550    ),
2551    metric(
2552        MetricId::Phase2AnchoredVerifyCandidates,
2553        "phase2-anchored-verify-candidates",
2554        MetricKind::Counter,
2555        MetricUnit::Count,
2556    ),
2557    metric(
2558        MetricId::Phase2AnchoredVerifyMatches,
2559        "phase2-anchored-verify-matches",
2560        MetricKind::Counter,
2561        MetricUnit::Count,
2562    ),
2563    metric(
2564        MetricId::Phase2WholeChunkPatterns,
2565        "phase2-whole-chunk-patterns",
2566        MetricKind::Counter,
2567        MetricUnit::Count,
2568    ),
2569    metric(
2570        MetricId::Phase2WholeChunkMatches,
2571        "phase2-whole-chunk-matches",
2572        MetricKind::Counter,
2573        MetricUnit::Count,
2574    ),
2575];
2576
2577impl MetricId {
2578    pub const COUNT: usize = 210;
2579    #[inline]
2580    pub const fn descriptor(self) -> &'static MetricDescriptor {
2581        &METRICS[self as usize]
2582    }
2583
2584    /// Stable metric name from the static registry.
2585    #[inline]
2586    pub const fn as_str(self) -> &'static str {
2587        self.descriptor().name
2588    }
2589}
2590
2591/// Named GPU region dispatch phase timing counters.
2592pub const GPU_DISPATCH_PHASE_COUNTERS: [CounterId; 6] = [
2593    CounterId::GpuMatcherNs,
2594    CounterId::GpuCoalesceNs,
2595    CounterId::GpuDispatchNs,
2596    CounterId::GpuDeriveNs,
2597    CounterId::GpuRecallFloorNs,
2598    CounterId::Phase2GpuAdmissionNs,
2599];
2600
2601/// Named GPU region dispatch decomposition counters whose sum composes the enclosing dispatch duration.
2602pub const GPU_DISPATCH_DECOMPOSITION_COUNTERS: [CounterId; 3] = [
2603    CounterId::GpuCoalesceNs,
2604    CounterId::GpuDispatchNs,
2605    CounterId::GpuDeriveNs,
2606];
2607
2608/// Slice of all GPU dispatch phase timing counters.
2609pub fn gpu_dispatch_phase_counters() -> &'static [CounterId] {
2610    &GPU_DISPATCH_PHASE_COUNTERS
2611}
2612
2613/// Slice of GPU dispatch decomposition timing counters.
2614pub fn gpu_dispatch_decomposition_counters() -> &'static [CounterId] {
2615    &GPU_DISPATCH_DECOMPOSITION_COUNTERS
2616}