From 9310b54d439d4a1a8d4d337987aa63884df0af76 Mon Sep 17 00:00:00 2001 From: Paul Buetow Date: Wed, 20 May 2026 11:38:19 +0300 Subject: feat: add syscall aggregate sampling infrastructure (task 17) --- internal/statsengine/syscall.go | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) (limited to 'internal/statsengine/syscall.go') diff --git a/internal/statsengine/syscall.go b/internal/statsengine/syscall.go index d58e8c9..5c85b2a 100644 --- a/internal/statsengine/syscall.go +++ b/internal/statsengine/syscall.go @@ -99,6 +99,29 @@ func (a *syscallAccumulator) Add(pair *event.Pair) { } } +func (a *syscallAccumulator) AddAggregate(row SyscallAggregate) { + if a == nil || row.TraceID == 0 || row.Count == 0 { + return + } + + stats := a.byID[row.TraceID] + if stats == nil { + stats = &syscallStats{traceID: row.TraceID, name: row.TraceID.Name()} + a.byID[row.TraceID] = stats + } + + prevCount := stats.count + stats.count += row.Count + stats.errorCount += row.Errors + stats.totalLatency += row.TotalLatencyNs + if prevCount == 0 || row.MinLatencyNs < stats.minLatency { + stats.minLatency = row.MinLatencyNs + } + if row.MaxLatencyNs > stats.maxLatency { + stats.maxLatency = row.MaxLatencyNs + } +} + // Snapshot returns a slice of SyscallSnapshots for all tracked syscalls. // It panics on build error, which should never happen for a valid accumulator. func (a *syscallAccumulator) Snapshot(elapsed time.Duration) []SyscallSnapshot { -- cgit v1.2.3