From 5b968ccf1481a8bae7fce49cca01cf3597da4be8 Mon Sep 17 00:00:00 2001 From: Aleksandr Nogikh Date: Wed, 10 Apr 2024 17:24:01 +0200 Subject: 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. --- pkg/stats/avg.go | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 pkg/stats/avg.go (limited to 'pkg') 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) +} -- cgit mrf-deployment