From a516ab122dfe9fe0d8c86a50bb46b1333f794205 Mon Sep 17 00:00:00 2001 From: Aleksandr Nogikh Date: Tue, 19 Mar 2024 15:05:10 +0100 Subject: pkg/fuzzer: expose the number of candidates and running jobs --- pkg/fuzzer/fuzzer.go | 15 ++++++++++++--- pkg/fuzzer/fuzzer_test.go | 4 ++-- 2 files changed, 14 insertions(+), 5 deletions(-) (limited to 'pkg') diff --git a/pkg/fuzzer/fuzzer.go b/pkg/fuzzer/fuzzer.go index bc13bec88..35f409689 100644 --- a/pkg/fuzzer/fuzzer.go +++ b/pkg/fuzzer/fuzzer.go @@ -38,6 +38,7 @@ type Fuzzer struct { runningExecs map[*Request]time.Time nextJobID atomic.Int64 + runningJobs atomic.Int64 queuedCandidates atomic.Int64 // If the source of candidates runs out of them, we risk // generating too many needCandidate requests (one for @@ -214,7 +215,11 @@ func (fuzzer *Fuzzer) nextInput() *Request { func (fuzzer *Fuzzer) startJob(newJob job) { fuzzer.Logf(2, "started %T", newJob) newJob.saveID(-fuzzer.nextJobID.Add(1)) - go newJob.run(fuzzer) + go func() { + fuzzer.runningJobs.Add(1) + newJob.run(fuzzer) + fuzzer.runningJobs.Add(-1) + }() } func (fuzzer *Fuzzer) Logf(level int, msg string, args ...interface{}) { @@ -353,11 +358,15 @@ func (fuzzer *Fuzzer) logCurrentStats() { type Stats struct { CoverStats corpus.Stats + Candidates int + RunningJobs int } func (fuzzer *Fuzzer) Stats() Stats { return Stats{ - CoverStats: fuzzer.Cover.Stats(), - Stats: fuzzer.Config.Corpus.Stats(), + CoverStats: fuzzer.Cover.Stats(), + Stats: fuzzer.Config.Corpus.Stats(), + Candidates: int(fuzzer.queuedCandidates.Load()), + RunningJobs: int(fuzzer.runningJobs.Load()), } } diff --git a/pkg/fuzzer/fuzzer_test.go b/pkg/fuzzer/fuzzer_test.go index ed64a803f..4f8cf41c5 100644 --- a/pkg/fuzzer/fuzzer_test.go +++ b/pkg/fuzzer/fuzzer_test.go @@ -164,8 +164,8 @@ func (f *testFuzzer) oneMore() bool { f.iter++ if f.iter%100 == 0 { stat := f.fuzzer.Stats() - f.t.Logf(": corpus %d, signal %d, max signal %d, crash types %d", - f.iter, stat.Progs, stat.Signal, stat.MaxSignal, len(f.crashes)) + f.t.Logf(": corpus %d, signal %d, max signal %d, crash types %d, running jobs %d", + f.iter, stat.Progs, stat.Signal, stat.MaxSignal, len(f.crashes), stat.RunningJobs) } return f.iter < f.iterLimit && (f.expectedCrashes == nil || len(f.crashes) != len(f.expectedCrashes)) -- cgit mrf-deployment