From 257f4cb9050d29a38a992b814bd6e79e6f1bca99 Mon Sep 17 00:00:00 2001 From: Dmitry Vyukov Date: Wed, 16 Dec 2020 13:31:37 +0100 Subject: pkg/cmdprof: merge into pkg/tool cmdprof functionality seems to fit well into pkg/tool. --- pkg/cmdprof/cmdprof.go | 57 -------------------------------------------------- 1 file changed, 57 deletions(-) delete mode 100644 pkg/cmdprof/cmdprof.go (limited to 'pkg/cmdprof') diff --git a/pkg/cmdprof/cmdprof.go b/pkg/cmdprof/cmdprof.go deleted file mode 100644 index ab0396d16..000000000 --- a/pkg/cmdprof/cmdprof.go +++ /dev/null @@ -1,57 +0,0 @@ -// Copyright 2020 syzkaller project authors. All rights reserved. -// Use of this source code is governed by Apache 2 LICENSE that can be found in the LICENSE file. - -// Package cmdprof simplifies cpu/memory profiling for command line tools. Use as: -// flag.Parse() -// defer cmdprof.Install()() -package cmdprof - -import ( - "flag" - "fmt" - "os" - "runtime" - "runtime/pprof" -) - -var ( - flagCPUProfile = flag.String("cpuprofile", "", "write CPU profile to this file") - flagMEMProfile = flag.String("memprofile", "", "write memory profile to this file") -) - -func Install() func() { - res := func() {} - failf := func(msg string, args ...interface{}) { - fmt.Fprintf(os.Stderr, msg+"\n", args...) - os.Exit(1) - } - if *flagCPUProfile != "" { - f, err := os.Create(*flagCPUProfile) - if err != nil { - failf("failed to create cpuprofile file: %v", err) - } - if err := pprof.StartCPUProfile(f); err != nil { - failf("failed to start cpu profile: %v", err) - } - res = func() { - pprof.StopCPUProfile() - f.Close() - } - } - if *flagMEMProfile != "" { - prev := res - res = func() { - prev() - 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) - } - } - } - return res -} -- cgit mrf-deployment