diff options
| author | Dmitry Vyukov <dvyukov@google.com> | 2024-07-24 11:32:41 +0200 |
|---|---|---|
| committer | Dmitry Vyukov <dvyukov@google.com> | 2024-07-24 14:39:45 +0000 |
| commit | 1f032c27c8158e44723253179928104813d45cdc (patch) | |
| tree | 80845c1da6b2c62ccec9118ab68f5d75766f8485 /pkg | |
| parent | bea049d0b7d151ad71617c10191fbd954decb300 (diff) | |
pkg/stats: rename Create to New
New is more idiomatic name and is shorter
(lines where stats.Create is used are usually long,
so making them a bit shorter is good).
Diffstat (limited to 'pkg')
| -rw-r--r-- | pkg/corpus/corpus.go | 6 | ||||
| -rw-r--r-- | pkg/flatrpc/conn.go | 4 | ||||
| -rw-r--r-- | pkg/fuzzer/cover.go | 2 | ||||
| -rw-r--r-- | pkg/fuzzer/stats.go | 38 | ||||
| -rw-r--r-- | pkg/rpcserver/rpcserver.go | 16 | ||||
| -rw-r--r-- | pkg/stats/set.go | 10 | ||||
| -rw-r--r-- | pkg/stats/set_test.go | 24 |
7 files changed, 50 insertions, 50 deletions
diff --git a/pkg/corpus/corpus.go b/pkg/corpus/corpus.go index 4ad4f6f27..af5754273 100644 --- a/pkg/corpus/corpus.go +++ b/pkg/corpus/corpus.go @@ -40,11 +40,11 @@ func NewMonitoredCorpus(ctx context.Context, updates chan<- NewItemEvent) *Corpu updates: updates, ProgramsList: &ProgramsList{}, } - corpus.StatProgs = stats.Create("corpus", "Number of test programs in the corpus", stats.Console, + corpus.StatProgs = stats.New("corpus", "Number of test programs in the corpus", stats.Console, stats.Link("/corpus"), stats.Graph("corpus"), stats.LenOf(&corpus.progs, &corpus.mu)) - corpus.StatSignal = stats.Create("signal", "Fuzzing signal in the corpus", + corpus.StatSignal = stats.New("signal", "Fuzzing signal in the corpus", stats.LenOf(&corpus.signal, &corpus.mu)) - corpus.StatCover = stats.Create("coverage", "Source coverage in the corpus", stats.Console, + corpus.StatCover = stats.New("coverage", "Source coverage in the corpus", stats.Console, stats.Link("/cover"), stats.Prometheus("syz_corpus_cover"), stats.LenOf(&corpus.cover, &corpus.mu)) return corpus } diff --git a/pkg/flatrpc/conn.go b/pkg/flatrpc/conn.go index f3a997e1c..0658522a0 100644 --- a/pkg/flatrpc/conn.go +++ b/pkg/flatrpc/conn.go @@ -19,9 +19,9 @@ import ( ) var ( - statSent = stats.Create("rpc sent", "Outbound RPC traffic", + statSent = stats.New("rpc sent", "Outbound RPC traffic", stats.Graph("traffic"), stats.Rate{}, stats.FormatMB) - statRecv = stats.Create("rpc recv", "Inbound RPC traffic", + statRecv = stats.New("rpc recv", "Inbound RPC traffic", stats.Graph("traffic"), stats.Rate{}, stats.FormatMB) ) diff --git a/pkg/fuzzer/cover.go b/pkg/fuzzer/cover.go index 4421693b1..876d2f4dc 100644 --- a/pkg/fuzzer/cover.go +++ b/pkg/fuzzer/cover.go @@ -19,7 +19,7 @@ type Cover struct { func newCover() *Cover { cover := new(Cover) - stats.Create("max signal", "Maximum fuzzing signal (including flakes)", + stats.New("max signal", "Maximum fuzzing signal (including flakes)", stats.Graph("signal"), stats.LenOf(&cover.maxSignal, &cover.mu)) return cover } diff --git a/pkg/fuzzer/stats.go b/pkg/fuzzer/stats.go index db2dfd3b3..11f98f2a6 100644 --- a/pkg/fuzzer/stats.go +++ b/pkg/fuzzer/stats.go @@ -29,37 +29,37 @@ type Stats struct { func newStats() Stats { return Stats{ - statCandidates: stats.Create("candidates", "Number of candidate programs in triage queue", + statCandidates: stats.New("candidates", "Number of candidate programs in triage queue", stats.Console, stats.Graph("corpus")), - statNewInputs: stats.Create("new inputs", "Potential untriaged corpus candidates", + statNewInputs: stats.New("new inputs", "Potential untriaged corpus candidates", stats.Graph("corpus")), - statJobs: stats.Create("fuzzer jobs", "Total running fuzzer jobs", stats.NoGraph), - statJobsTriage: stats.Create("triage jobs", "Running triage jobs", stats.StackedGraph("jobs")), - statJobsTriageCandidate: stats.Create("candidate triage jobs", "Running candidate triage jobs", + statJobs: stats.New("fuzzer jobs", "Total running fuzzer jobs", stats.NoGraph), + statJobsTriage: stats.New("triage jobs", "Running triage jobs", stats.StackedGraph("jobs")), + statJobsTriageCandidate: stats.New("candidate triage jobs", "Running candidate triage jobs", stats.StackedGraph("jobs")), - statJobsSmash: stats.Create("smash jobs", "Running smash jobs", stats.StackedGraph("jobs")), - statJobsFaultInjection: stats.Create("fault jobs", "Running fault injection jobs", stats.StackedGraph("jobs")), - statJobsHints: stats.Create("hints jobs", "Running hints jobs", stats.StackedGraph("jobs")), - statExecTime: stats.Create("prog exec time", "Test program execution time (ms)", stats.Distribution{}), - statExecGenerate: stats.Create("exec gen", "Executions of generated programs", stats.Rate{}, + statJobsSmash: stats.New("smash jobs", "Running smash jobs", stats.StackedGraph("jobs")), + statJobsFaultInjection: stats.New("fault jobs", "Running fault injection jobs", stats.StackedGraph("jobs")), + statJobsHints: stats.New("hints jobs", "Running hints jobs", stats.StackedGraph("jobs")), + statExecTime: stats.New("prog exec time", "Test program execution time (ms)", stats.Distribution{}), + statExecGenerate: stats.New("exec gen", "Executions of generated programs", stats.Rate{}, stats.StackedGraph("exec")), - statExecFuzz: stats.Create("exec fuzz", "Executions of mutated programs", + statExecFuzz: stats.New("exec fuzz", "Executions of mutated programs", stats.Rate{}, stats.StackedGraph("exec")), - statExecCandidate: stats.Create("exec candidate", "Executions of candidate programs", + statExecCandidate: stats.New("exec candidate", "Executions of candidate programs", stats.Rate{}, stats.StackedGraph("exec")), - statExecTriage: stats.Create("exec triage", "Executions of corpus triage programs", + statExecTriage: stats.New("exec triage", "Executions of corpus triage programs", stats.Rate{}, stats.StackedGraph("exec")), - statExecMinimize: stats.Create("exec minimize", "Executions of programs during minimization", + statExecMinimize: stats.New("exec minimize", "Executions of programs during minimization", stats.Rate{}, stats.StackedGraph("exec")), - statExecSmash: stats.Create("exec smash", "Executions of smashed programs", + statExecSmash: stats.New("exec smash", "Executions of smashed programs", stats.Rate{}, stats.StackedGraph("exec")), - statExecFaultInject: stats.Create("exec inject", "Executions of fault injection", + statExecFaultInject: stats.New("exec inject", "Executions of fault injection", stats.Rate{}, stats.StackedGraph("exec")), - statExecHint: stats.Create("exec hints", "Executions of programs generated using hints", + statExecHint: stats.New("exec hints", "Executions of programs generated using hints", stats.Rate{}, stats.StackedGraph("exec")), - statExecSeed: stats.Create("exec seeds", "Executions of programs for hints extraction", + statExecSeed: stats.New("exec seeds", "Executions of programs for hints extraction", stats.Rate{}, stats.StackedGraph("exec")), - statExecCollide: stats.Create("exec collide", "Executions of programs in collide mode", + statExecCollide: stats.New("exec collide", "Executions of programs in collide mode", stats.Rate{}, stats.StackedGraph("exec")), } } diff --git a/pkg/rpcserver/rpcserver.go b/pkg/rpcserver/rpcserver.go index 0d50695f6..0b7d566bb 100644 --- a/pkg/rpcserver/rpcserver.go +++ b/pkg/rpcserver/rpcserver.go @@ -144,23 +144,23 @@ func newImpl(ctx context.Context, cfg *Config, mgr Manager) (*Server, error) { baseSource: baseSource, execSource: queue.Retry(baseSource), - StatExecs: stats.Create("exec total", "Total test program executions", + StatExecs: stats.New("exec total", "Total test program executions", stats.Console, stats.Rate{}, stats.Prometheus("syz_exec_total")), - StatNumFuzzing: stats.Create("fuzzing VMs", "Number of VMs that are currently fuzzing", + StatNumFuzzing: stats.New("fuzzing VMs", "Number of VMs that are currently fuzzing", stats.Console, stats.Link("/vms")), - statVMRestarts: stats.Create("vm restarts", "Total number of VM starts", + statVMRestarts: stats.New("vm restarts", "Total number of VM starts", stats.Rate{}, stats.NoGraph), runnerStats: &runnerStats{ - statExecRetries: stats.Create("exec retries", + statExecRetries: stats.New("exec retries", "Number of times a test program was restarted because the first run failed", stats.Rate{}, stats.Graph("executor")), - statExecutorRestarts: stats.Create("executor restarts", + statExecutorRestarts: stats.New("executor restarts", "Number of times executor process was restarted", stats.Rate{}, stats.Graph("executor")), - statExecBufferTooSmall: stats.Create("buffer too small", + statExecBufferTooSmall: stats.New("buffer too small", "Program serialization overflowed exec buffer", stats.NoGraph), - statNoExecRequests: stats.Create("no exec requests", + statNoExecRequests: stats.New("no exec requests", "Number of times fuzzer was stalled with no exec requests", stats.Rate{}), - statNoExecDuration: stats.Create("no exec duration", + statNoExecDuration: stats.New("no exec duration", "Total duration fuzzer was stalled with no exec requests (ns/sec)", stats.Rate{}), }, } diff --git a/pkg/stats/set.go b/pkg/stats/set.go index b15a8eecb..7e4804280 100644 --- a/pkg/stats/set.go +++ b/pkg/stats/set.go @@ -23,10 +23,10 @@ import ( // // Simple uses of metrics: // -// statFoo := stats.Create("metric name", "metric description") +// statFoo := stats.New("metric name", "metric description") // statFoo.Add(1) // -// stats.Create("metric name", "metric description", LenOf(mySlice, rwMutex)) +// stats.New("metric name", "metric description", LenOf(mySlice, rwMutex)) // // Metric visualization code uses Collect/RenderHTML functions to obtain values of all registered metrics. @@ -39,8 +39,8 @@ type UI struct { V int } -func Create(name, desc string, opts ...any) *Val { - return global.Create(name, desc, opts...) +func New(name, desc string, opts ...any) *Val { + return global.New(name, desc, opts...) } func Collect(level Level) []UI { @@ -182,7 +182,7 @@ func FormatMB(v int, period time.Duration) string { // Addittionally a custom 'func() int' can be passed to read the metric value from the function. // and 'func(int, time.Duration) string' can be passed for custom formatting of the metric value. -func (s *set) Create(name, desc string, opts ...any) *Val { +func (s *set) New(name, desc string, opts ...any) *Val { v := &Val{ name: name, desc: desc, diff --git a/pkg/stats/set_test.go b/pkg/stats/set_test.go index 56bac54dd..862882fc2 100644 --- a/pkg/stats/set_test.go +++ b/pkg/stats/set_test.go @@ -20,7 +20,7 @@ func TestSet(t *testing.T) { _, err := set.RenderHTML() a.NoError(err) - v0 := set.Create("v0", "desc0") + v0 := set.New("v0", "desc0") a.Equal(v0.Val(), 0) v0.Add(1) a.Equal(v0.Val(), 1) @@ -28,18 +28,18 @@ func TestSet(t *testing.T) { a.Equal(v0.Val(), 2) vv1 := 0 - v1 := set.Create("v1", "desc1", Simple, func() int { return vv1 }) + v1 := set.New("v1", "desc1", Simple, func() int { return vv1 }) a.Equal(v1.Val(), 0) vv1 = 11 a.Equal(v1.Val(), 11) a.Panics(func() { v1.Add(1) }) - v2 := set.Create("v2", "desc2", Console, func(v int, period time.Duration) string { + v2 := set.New("v2", "desc2", Console, func(v int, period time.Duration) string { return fmt.Sprintf("v2 %v %v", v, period) }) v2.Add(100) - v3 := set.Create("v3", "desc3", Link("/v3"), NoGraph, Distribution{}) + v3 := set.New("v3", "desc3", Link("/v3"), NoGraph, Distribution{}) a.Equal(v3.Val(), 0) v3.Add(10) a.Equal(v3.Val(), 10) @@ -55,13 +55,13 @@ func TestSet(t *testing.T) { v3.Add(30) a.Equal(v3.Val(), 24) - v4 := set.Create("v4", "desc4", Rate{}, Graph("graph")) + v4 := set.New("v4", "desc4", Rate{}, Graph("graph")) v4.Add(10) a.Equal(v4.Val(), 10) v4.Add(10) a.Equal(v4.Val(), 20) - a.Panics(func() { set.Create("v0", "desc0", float64(1)) }) + a.Panics(func() { set.New("v0", "desc0", float64(1)) }) ui := set.Collect(All) a.Equal(len(ui), 5) @@ -87,7 +87,7 @@ func TestSet(t *testing.T) { func TestSetRateFormat(t *testing.T) { a := assert.New(t) set := newSet(4, false) - v := set.Create("v", "desc", Rate{}) + v := set.New("v", "desc", Rate{}) a.Equal(set.Collect(All)[0].Value, "0 (0/hour)") v.Add(1) a.Equal(set.Collect(All)[0].Value, "1 (60/min)") @@ -98,7 +98,7 @@ func TestSetRateFormat(t *testing.T) { func TestSetHistoryCounter(t *testing.T) { a := assert.New(t) set := newSet(4, false) - v := set.Create("v0", "desc0") + v := set.New("v0", "desc0") set.tick() hist := func() []float64 { return set.graphs["v0"].lines["v0"].data[:set.historyPos] } step := func(n int) []float64 { @@ -132,7 +132,7 @@ func TestSetHistoryCounter(t *testing.T) { func TestSetHistoryRate(t *testing.T) { a := assert.New(t) set := newSet(4, false) - v := set.Create("v0", "desc0", Rate{}) + v := set.New("v0", "desc0", Rate{}) step := func(n int) []float64 { v.Add(n) set.tick() @@ -155,7 +155,7 @@ func TestSetHistoryRate(t *testing.T) { func TestSetHistoryDistribution(t *testing.T) { a := assert.New(t) set := newSet(4, false) - v := set.Create("v0", "desc0", Distribution{}) + v := set.New("v0", "desc0", Distribution{}) step := func(n int) [3][]float64 { v.Add(n) set.tick() @@ -194,7 +194,7 @@ func TestSetStress(t *testing.T) { for _, opt := range []any{Link(""), NoGraph, Rate{}, Distribution{}} { opt := opt go func() { - v := set.Create(fmt.Sprintf("v%v", seq.Add(1)), "desc", opt) + v := set.New(fmt.Sprintf("v%v", seq.Add(1)), "desc", opt) for p1 := 0; p1 < 2; p1++ { start(func() { v.Val() }) start(func() { v.Add(rand.Intn(10000)) }) @@ -203,7 +203,7 @@ func TestSetStress(t *testing.T) { } go func() { var vv atomic.Uint64 - v := set.Create(fmt.Sprintf("v%v", seq.Add(1)), "desc", + v := set.New(fmt.Sprintf("v%v", seq.Add(1)), "desc", func() int { return int(vv.Load()) }) for p1 := 0; p1 < 2; p1++ { start(func() { v.Val() }) |
