diff options
| author | Aleksandr Nogikh <nogikh@google.com> | 2024-04-10 17:24:01 +0200 |
|---|---|---|
| committer | Aleksandr Nogikh <nogikh@google.com> | 2024-04-10 15:34:42 +0000 |
| commit | 5b968ccf1481a8bae7fce49cca01cf3597da4be8 (patch) | |
| tree | 1f339f51d54e4ca960c31b6d262e2912ade06468 /pkg | |
| parent | 6e189cf48871220fff5a087cc06b6682e052da3c (diff) | |
syz-manager: collect avg instance create time
We will also use it to determine when we are ready to schedule programs
that are very likely to crash instances.
Diffstat (limited to 'pkg')
| -rw-r--r-- | pkg/stats/avg.go | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/pkg/stats/avg.go b/pkg/stats/avg.go new file mode 100644 index 000000000..430ff335b --- /dev/null +++ b/pkg/stats/avg.go @@ -0,0 +1,32 @@ +// Copyright 2024 syzkaller project authors. All rights reserved. +// Use of this source code is governed by Apache 2 LICENSE that can be found in the LICENSE file. + +package stats + +import ( + "sync" + "time" +) + +type AverageParameter interface { + time.Duration +} + +type AverageValue[T AverageParameter] struct { + mu sync.Mutex + total int64 + avg T +} + +func (av *AverageValue[T]) Value() T { + av.mu.Lock() + defer av.mu.Unlock() + return av.avg +} + +func (av *AverageValue[T]) Save(val T) { + av.mu.Lock() + defer av.mu.Unlock() + av.total++ + av.avg += (val - av.avg) / T(av.total) +} |
