Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(120)

Side by Side Diff: fuzzer/go/generator/afl_generation.go

Issue 1682363003: Migrate fuzzer to use shiny new metrics2 package (Closed) Base URL: https://skia.googlesource.com/buildbot@master
Patch Set: Rename metrics Created 4 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 package generator 1 package generator
2 2
3 import ( 3 import (
4 "fmt" 4 "fmt"
5 "io/ioutil" 5 "io/ioutil"
6 "os" 6 "os"
7 "path/filepath" 7 "path/filepath"
8 "strings" 8 "strings"
9 9
10 go_metrics "github.com/rcrowley/go-metrics"
11 "github.com/skia-dev/glog" 10 "github.com/skia-dev/glog"
12 "go.skia.org/infra/fuzzer/go/common" 11 "go.skia.org/infra/fuzzer/go/common"
13 "go.skia.org/infra/fuzzer/go/config" 12 "go.skia.org/infra/fuzzer/go/config"
14 "go.skia.org/infra/go/exec" 13 "go.skia.org/infra/go/exec"
15 "go.skia.org/infra/go/fileutil" 14 "go.skia.org/infra/go/fileutil"
16 "go.skia.org/infra/go/gs" 15 "go.skia.org/infra/go/gs"
16 "go.skia.org/infra/go/metrics2"
17 "google.golang.org/cloud/storage" 17 "google.golang.org/cloud/storage"
18 ) 18 )
19 19
20 type Generator struct { 20 type Generator struct {
21 Category string 21 Category string
22 » fuzzProcessCount go_metrics.Counter 22 » fuzzProcessCount *metrics2.Counter
23 fuzzProcesses []exec.Process 23 fuzzProcesses []exec.Process
24 } 24 }
25 25
26 func New(category string) *Generator { 26 func New(category string) *Generator {
27 return &Generator{ 27 return &Generator{
28 Category: category, 28 Category: category,
29 fuzzProcesses: nil, 29 fuzzProcesses: nil,
30 } 30 }
31 } 31 }
32 32
(...skipping 18 matching lines...) Expand all
51 masterCmd.Stdout = os.Stdout 51 masterCmd.Stdout = os.Stdout
52 } 52 }
53 53
54 g.fuzzProcesses = append(g.fuzzProcesses, g.run(masterCmd)) 54 g.fuzzProcesses = append(g.fuzzProcesses, g.run(masterCmd))
55 55
56 fuzzCount := config.Generator.NumFuzzProcesses 56 fuzzCount := config.Generator.NumFuzzProcesses
57 if fuzzCount <= 0 { 57 if fuzzCount <= 0 {
58 // TODO(kjlubick): Make this actually an intelligent number base d on the number of cores. 58 // TODO(kjlubick): Make this actually an intelligent number base d on the number of cores.
59 fuzzCount = 10 59 fuzzCount = 10
60 } 60 }
61 » g.fuzzProcessCount = go_metrics.NewRegisteredCounter("afl_fuzz_process_c ount", go_metrics.DefaultRegistry) 61 » g.fuzzProcessCount = metrics2.NewCounter("afl-fuzz-process-count", map[s tring]string{"category": g.Category})
62 g.fuzzProcessCount.Inc(int64(fuzzCount)) 62 g.fuzzProcessCount.Inc(int64(fuzzCount))
63 for i := 1; i < fuzzCount; i++ { 63 for i := 1; i < fuzzCount; i++ {
64 fuzzerName := fmt.Sprintf("fuzzer%d", i) 64 fuzzerName := fmt.Sprintf("fuzzer%d", i)
65 slaveCmd := &exec.Command{ 65 slaveCmd := &exec.Command{
66 Name: "./afl-fuzz", 66 Name: "./afl-fuzz",
67 Args: common.GenerationArgsFor(g.Category, executab le, fuzzerName, false), 67 Args: common.GenerationArgsFor(g.Category, executab le, fuzzerName, false),
68 Dir: config.Generator.AflRoot, 68 Dir: config.Generator.AflRoot,
69 LogStdout: true, 69 LogStdout: true,
70 LogStderr: true, 70 LogStderr: true,
71 Env: []string{"AFL_SKIP_CPUFREQ=true"}, // Avoids a warning afl-fuzz spits out about dynamic scaling of cpu frequency 71 Env: []string{"AFL_SKIP_CPUFREQ=true"}, // Avoids a warning afl-fuzz spits out about dynamic scaling of cpu frequency
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
118 // manually kill the command. 118 // manually kill the command.
119 func (g *Generator) run(command *exec.Command) exec.Process { 119 func (g *Generator) run(command *exec.Command) exec.Process {
120 p, status, err := exec.RunIndefinitely(command) 120 p, status, err := exec.RunIndefinitely(command)
121 if err != nil { 121 if err != nil {
122 glog.Errorf("Failed afl fuzzer command %#v: %s", command, err) 122 glog.Errorf("Failed afl fuzzer command %#v: %s", command, err)
123 return nil 123 return nil
124 } 124 }
125 go func() { 125 go func() {
126 err := <-status 126 err := <-status
127 g.fuzzProcessCount.Dec(int64(1)) 127 g.fuzzProcessCount.Dec(int64(1))
128 » » glog.Infof(`[%s] afl fuzzer with args %q ended with error "%v". There are %d fuzzers remaining`, g.Category, command.Args, err, g.fuzzProcessCo unt.Count()) 128 » » glog.Infof(`[%s] afl fuzzer with args %q ended with error "%v". There are %d fuzzers remaining`, g.Category, command.Args, err, g.fuzzProcessCo unt.Get())
129 }() 129 }()
130 return p 130 return p
131 } 131 }
132 132
133 // Stop terminates all afl-fuzz processes that were spawned, 133 // Stop terminates all afl-fuzz processes that were spawned,
134 // logging any errors. 134 // logging any errors.
135 func (g *Generator) Stop() { 135 func (g *Generator) Stop() {
136 glog.Infof("Trying to stop %d fuzz processes", len(g.fuzzProcesses)) 136 glog.Infof("Trying to stop %d fuzz processes", len(g.fuzzProcesses))
137 for _, p := range g.fuzzProcesses { 137 for _, p := range g.fuzzProcesses {
138 if p != nil { 138 if p != nil {
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
171 glog.Errorf("[%s] Problem downloading %s from Google Sto rage, continuing anyway", g.Category, item.Name) 171 glog.Errorf("[%s] Problem downloading %s from Google Sto rage, continuing anyway", g.Category, item.Name)
172 return 172 return
173 } 173 }
174 fileName := filepath.Join(seedPath, strings.SplitAfter(name, gsF older)[1]) 174 fileName := filepath.Join(seedPath, strings.SplitAfter(name, gsF older)[1])
175 if err = ioutil.WriteFile(fileName, content, 0644); err != nil & & !os.IsExist(err) { 175 if err = ioutil.WriteFile(fileName, content, 0644); err != nil & & !os.IsExist(err) {
176 glog.Errorf("[%s] Problem creating binary seed file %s, continuing anyway", g.Category, fileName) 176 glog.Errorf("[%s] Problem creating binary seed file %s, continuing anyway", g.Category, fileName)
177 } 177 }
178 }) 178 })
179 return err 179 return err
180 } 180 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698