• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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
4package main
5
6import (
7	"sync/atomic"
8)
9
10type Stat uint64
11
12type Stats struct {
13	crashes          Stat
14	crashTypes       Stat
15	crashSuppressed  Stat
16	vmRestarts       Stat
17	newInputs        Stat
18	execTotal        Stat
19	hubSendProgAdd   Stat
20	hubSendProgDel   Stat
21	hubSendRepro     Stat
22	hubRecvProg      Stat
23	hubRecvProgDrop  Stat
24	hubRecvRepro     Stat
25	hubRecvReproDrop Stat
26}
27
28func (stats *Stats) all() map[string]uint64 {
29	return map[string]uint64{
30		"crashes":              stats.crashes.get(),
31		"crash types":          stats.crashTypes.get(),
32		"suppressed":           stats.crashSuppressed.get(),
33		"vm restarts":          stats.vmRestarts.get(),
34		"manager new inputs":   stats.newInputs.get(),
35		"exec total":           stats.execTotal.get(),
36		"hub: send prog add":   stats.hubSendProgAdd.get(),
37		"hub: send prog del":   stats.hubSendProgDel.get(),
38		"hub: send repro":      stats.hubSendRepro.get(),
39		"hub: recv prog":       stats.hubRecvProg.get(),
40		"hub: recv prog drop":  stats.hubRecvProgDrop.get(),
41		"hub: recv repro":      stats.hubRecvRepro.get(),
42		"hub: recv repro drop": stats.hubRecvReproDrop.get(),
43	}
44}
45
46func (s *Stat) get() uint64 {
47	return atomic.LoadUint64((*uint64)(s))
48}
49
50func (s *Stat) inc() {
51	s.add(1)
52}
53
54func (s *Stat) add(v int) {
55	atomic.AddUint64((*uint64)(s), uint64(v))
56}
57