diff options
| author | Dmitry Vyukov <dvyukov@google.com> | 2020-04-30 16:02:57 +0200 |
|---|---|---|
| committer | Dmitry Vyukov <dvyukov@google.com> | 2020-04-30 17:18:29 +0200 |
| commit | 136082ab38d86932bc3ed0087694e99d0e55491b (patch) | |
| tree | e4b44339320e39f60df4ecd7170666602191b583 /tools/syz-check | |
| parent | cc90e4763e4f1932275adf9c7bd5a1176cecdc74 (diff) | |
pkg/cmdprof: add package
cmdprof simplifies cpu/memory profiling for command line tools. Use as:
flag.Parse()
defer cmdprof.Install
Diffstat (limited to 'tools/syz-check')
| -rw-r--r-- | tools/syz-check/check.go | 35 |
1 files changed, 5 insertions, 30 deletions
diff --git a/tools/syz-check/check.go b/tools/syz-check/check.go index 76a52c50d..490a48c3f 100644 --- a/tools/syz-check/check.go +++ b/tools/syz-check/check.go @@ -31,12 +31,12 @@ import ( "os" "path/filepath" "runtime" - "runtime/pprof" "sort" "strings" "unsafe" "github.com/google/syzkaller/pkg/ast" + "github.com/google/syzkaller/pkg/cmdprof" "github.com/google/syzkaller/pkg/compiler" "github.com/google/syzkaller/pkg/osutil" "github.com/google/syzkaller/pkg/symbolizer" @@ -46,11 +46,9 @@ import ( func main() { var ( - flagOS = flag.String("os", runtime.GOOS, "OS") - flagCPUProfile = flag.String("cpuprofile", "", "write CPU profile to this file") - flagMEMProfile = flag.String("memprofile", "", "write memory profile to this file") - flagDWARF = flag.Bool("dwarf", true, "do checking based on DWARF") - flagNetlink = flag.Bool("netlink", true, "do checking of netlink policies") + flagOS = flag.String("os", runtime.GOOS, "OS") + flagDWARF = flag.Bool("dwarf", true, "do checking based on DWARF") + flagNetlink = flag.Bool("netlink", true, "do checking of netlink policies") ) arches := map[string]*string{"amd64": nil, "386": nil, "arm64": nil, "arm": nil} for arch := range arches { @@ -61,30 +59,7 @@ func main() { os.Exit(1) } flag.Parse() - if *flagCPUProfile != "" { - f, err := os.Create(*flagCPUProfile) - if err != nil { - failf("failed to create cpuprofile file: %v", err) - } - defer f.Close() - if err := pprof.StartCPUProfile(f); err != nil { - failf("failed to start cpu profile: %v", err) - } - defer pprof.StopCPUProfile() - } - if *flagMEMProfile != "" { - defer func() { - f, err := os.Create(*flagMEMProfile) - if err != nil { - failf("failed to create memprofile file: %v", err) - } - defer f.Close() - runtime.GC() - if err := pprof.WriteHeapProfile(f); err != nil { - failf("failed to write mem profile: %v", err) - } - }() - } + defer cmdprof.Install()() var warnings []Warn for arch, obj := range arches { if *obj == "" { |
