From 572bcb406b5d48ce06b3becd1ac9463d0a54329b Mon Sep 17 00:00:00 2001 From: Taras Madan Date: Wed, 15 Dec 2021 18:12:41 +0100 Subject: syz-verifier: use int64 instead of int for statistics (#2924) Currently we use int to aggregate statistics. Counters update require the lock() operation. Lets relax it and move to int64 + atomic.AddInt64(). --- syz-verifier/monitoring_api.go | 12 ++++++------ syz-verifier/stats.go | 18 +++++++++--------- syz-verifier/utils_test.go | 2 +- 3 files changed, 16 insertions(+), 16 deletions(-) diff --git a/syz-verifier/monitoring_api.go b/syz-verifier/monitoring_api.go index 8c67cbe40..af852d02a 100644 --- a/syz-verifier/monitoring_api.go +++ b/syz-verifier/monitoring_api.go @@ -44,11 +44,11 @@ func (monitor *Monitor) initHTTPHandlers() { // statsJSON provides information for the "/api/stats.json" render. type statsJSON struct { StartTime time.Time - TotalMismatches int - TotalProgs int - FlakyProgs int - MismatchingProgs int - AverExecSpeed int + TotalMismatches int64 + TotalProgs int64 + FlakyProgs int64 + MismatchingProgs int64 + AverExecSpeed int64 } // handleStats renders the statsJSON object. @@ -60,7 +60,7 @@ func (monitor *Monitor) renderStats() interface{} { TotalProgs: stats.TotalProgs, FlakyProgs: stats.FlakyProgs, MismatchingProgs: stats.MismatchingProgs, - AverExecSpeed: 60 * stats.TotalProgs / int(1+time.Since(stats.StartTime).Seconds()), + AverExecSpeed: 60 * stats.TotalProgs / int64(1+time.Since(stats.StartTime).Seconds()), } } diff --git a/syz-verifier/stats.go b/syz-verifier/stats.go index e06ead8c0..17a443315 100644 --- a/syz-verifier/stats.go +++ b/syz-verifier/stats.go @@ -17,10 +17,10 @@ import ( type Stats struct { // Calls stores statistics for all supported system calls. Calls map[string]*CallStats - TotalMismatches int - TotalProgs int - FlakyProgs int - MismatchingProgs int + TotalMismatches int64 + TotalProgs int64 + FlakyProgs int64 + MismatchingProgs int64 StartTime time.Time } @@ -31,10 +31,10 @@ type CallStats struct { Name string // Mismatches stores the number of errno mismatches identified in the // verified programs for this system call. - Mismatches int + Mismatches int64 // Occurrences is the number of times the system call appeared in a // verified program. - Occurrences int + Occurrences int64 // States stores the kernel return state that caused mismatches. States map[ReturnState]bool } @@ -95,8 +95,8 @@ func (stats *Stats) getCallStatsTextDescription(call string) string { getPercentage(mismatches, stats.TotalMismatches), len(syscallStat.States), stats.getOrderedStates(syscallName)) } -func (stats *Stats) totalCallsExecuted() int { - t := 0 +func (stats *Stats) totalCallsExecuted() int64 { + var t int64 for _, cs := range stats.Calls { t += cs.Occurrences } @@ -128,6 +128,6 @@ func (stats *Stats) getOrderedStates(call string) []string { return ss } -func getPercentage(value, total int) float64 { +func getPercentage(value, total int64) float64 { return float64(value) / float64(total) * 100 } diff --git a/syz-verifier/utils_test.go b/syz-verifier/utils_test.go index 517d17232..a4affe90a 100644 --- a/syz-verifier/utils_test.go +++ b/syz-verifier/utils_test.go @@ -85,7 +85,7 @@ func emptyTestStats() *Stats { } } -func makeCallStats(name string, occurrences, mismatches int, states map[ReturnState]bool) *CallStats { +func makeCallStats(name string, occurrences, mismatches int64, states map[ReturnState]bool) *CallStats { return &CallStats{Name: name, Occurrences: occurrences, Mismatches: mismatches, -- cgit mrf-deployment