Files
dolt/clients/util/profile.go
T
Chris Masone 17fd75f01d Create d.Exp and d.Try
Introduces the notion of debug 'expectations', analogous to the
'checks' that we already have. d.Exp provides the same API as d.Chk,
but expectation violations can be caught using d.Try().

Toward issue #176
2015-08-10 12:40:43 -07:00

41 lines
1.1 KiB
Go

package util
import (
"flag"
"os"
"runtime/pprof"
"github.com/attic-labs/noms/d"
)
var (
cpuProfile = flag.String("cpuprofile", "", "write cpu profile to file")
memProfile = flag.String("memprofile", "", "write memory profile to this file")
)
// MaybeStartCPUProfile checks the -cpuprofile flag and, if it is set, attempts to start writing CPU profile data to the named file. Stopping CPU profiling is left to the caller.
func MaybeStartCPUProfile() bool {
if *cpuProfile != "" {
f, err := os.Create(*cpuProfile)
d.Exp.NoError(err)
pprof.StartCPUProfile(f)
return true
}
return false
}
// StopCPUProfile is a wrapper around pprof.StopCPUProfile(), provided for consistency; callers don't have to be aware of pprof at all.
func StopCPUProfile() {
pprof.StopCPUProfile()
}
// MaybeWriteMemProfile checks the -memprofile flag and, if it is set, attempts to write memory profiling data to the named file.
func MaybeWriteMemProfile() {
if *memProfile != "" {
f, err := os.Create(*memProfile)
defer f.Close()
d.Exp.NoError(err)
pprof.WriteHeapProfile(f)
}
}