github.com/google/syzkaller@v0.0.0-20240517125934-c0f1611a36d6/syz-manager/stats.go (about)

     1  // Copyright 2018 syzkaller project authors. All rights reserved.
     2  // Use of this source code is governed by Apache 2 LICENSE that can be found in the LICENSE file.
     3  
     4  package main
     5  
     6  import (
     7  	"fmt"
     8  	"runtime"
     9  	"time"
    10  
    11  	"github.com/google/syzkaller/pkg/stats"
    12  )
    13  
    14  type Stats struct {
    15  	statNumFuzzing     *stats.Val
    16  	statNumReproducing *stats.Val
    17  	statExecs          *stats.Val
    18  	statCrashes        *stats.Val
    19  	statCrashTypes     *stats.Val
    20  	statSuppressed     *stats.Val
    21  	statUptime         *stats.Val
    22  	statFuzzingTime    *stats.Val
    23  	statAvgBootTime    *stats.Val
    24  }
    25  
    26  func (mgr *Manager) initStats() {
    27  	mgr.statNumFuzzing = stats.Create("VMs", "Number of VMs that are currently fuzzing",
    28  		stats.Console, stats.NoGraph)
    29  	mgr.statNumReproducing = stats.Create("reproducing", "Number of crashes being reproduced",
    30  		stats.Console, stats.NoGraph)
    31  	mgr.statExecs = stats.Create("exec total", "Total test program executions",
    32  		stats.Console, stats.Rate{}, stats.Prometheus("syz_exec_total"))
    33  	mgr.statCrashes = stats.Create("crashes", "Total number of VM crashes",
    34  		stats.Simple, stats.Prometheus("syz_crash_total"))
    35  	mgr.statCrashTypes = stats.Create("crash types", "Number of unique crashes types",
    36  		stats.Simple, stats.NoGraph)
    37  	mgr.statSuppressed = stats.Create("suppressed", "Total number of suppressed VM crashes",
    38  		stats.Simple, stats.Graph("crashes"))
    39  	mgr.statFuzzingTime = stats.Create("fuzzing", "Total fuzzing time in all VMs (seconds)",
    40  		stats.NoGraph, func(v int, period time.Duration) string { return fmt.Sprintf("%v sec", v/1e9) })
    41  	mgr.statUptime = stats.Create("uptime", "Total uptime (seconds)", stats.Simple, stats.NoGraph,
    42  		func() int {
    43  			firstConnect := mgr.firstConnect.Load()
    44  			if firstConnect == 0 {
    45  				return 0
    46  			}
    47  			return int(time.Now().Unix() - firstConnect)
    48  		}, func(v int, period time.Duration) string {
    49  			return fmt.Sprintf("%v sec", v)
    50  		})
    51  	mgr.statAvgBootTime = stats.Create("instance restart", "Average VM restart time (sec)",
    52  		stats.NoGraph,
    53  		func() int {
    54  			return int(mgr.bootTime.Value().Seconds())
    55  		},
    56  		func(v int, _ time.Duration) string {
    57  			return fmt.Sprintf("%v sec", v)
    58  		})
    59  
    60  	stats.Create("heap", "Process heap size (bytes)", stats.Graph("memory"),
    61  		func() int {
    62  			var ms runtime.MemStats
    63  			runtime.ReadMemStats(&ms)
    64  			return int(ms.Alloc)
    65  		}, func(v int, period time.Duration) string {
    66  			return fmt.Sprintf("%v MB", v>>20)
    67  		})
    68  	stats.Create("VM", "Process VM size (bytes)", stats.Graph("memory"),
    69  		func() int {
    70  			var ms runtime.MemStats
    71  			runtime.ReadMemStats(&ms)
    72  			return int(ms.Sys - ms.HeapReleased)
    73  		}, func(v int, period time.Duration) string {
    74  			return fmt.Sprintf("%v MB", v>>20)
    75  		})
    76  
    77  	// Stats imported from the fuzzer (names must match the the fuzzer names).
    78  	stats.Create("no exec requests", "Number of times fuzzer was stalled with no exec requests", stats.Rate{})
    79  	stats.Create("no exec duration", "Total duration fuzzer was stalled with no exec requests (ns/sec)", stats.Rate{})
    80  }