From 136082ab38d86932bc3ed0087694e99d0e55491b Mon Sep 17 00:00:00 2001 From: Dmitry Vyukov Date: Thu, 30 Apr 2020 16:02:57 +0200 Subject: pkg/cmdprof: add package cmdprof simplifies cpu/memory profiling for command line tools. Use as: flag.Parse() defer cmdprof.Install --- tools/syz-check/check.go | 35 +++++------------------------------ 1 file changed, 5 insertions(+), 30 deletions(-) (limited to 'tools/syz-check') 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 == "" { -- cgit mrf-deployment