mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +00:00
pprof: add goroutine blocking profiling
The profiler collects goroutine blocking information similar to Google Perf Tools. You may see an example of the profile (converted to svg) attached to http://code.google.com/p/go/issues/detail?id=3946 The public API changes are: +pkg runtime, func BlockProfile([]BlockProfileRecord) (int, bool) +pkg runtime, func SetBlockProfileRate(int) +pkg runtime, method (*BlockProfileRecord) Stack() []uintptr +pkg runtime, type BlockProfileRecord struct +pkg runtime, type BlockProfileRecord struct, Count int64 +pkg runtime, type BlockProfileRecord struct, Cycles int64 +pkg runtime, type BlockProfileRecord struct, embedded StackRecord R=rsc, dave, minux.ma, r CC=gobot, golang-dev, r, remyoudompheng https://golang.org/cl/6443115
This commit is contained in:
parent
ebb0e5db75
commit
4cc7bf326a
12 changed files with 350 additions and 52 deletions
|
|
@ -102,14 +102,16 @@ var (
|
|||
short = flag.Bool("test.short", false, "run smaller test suite to save time")
|
||||
|
||||
// Report as tests are run; default is silent for success.
|
||||
chatty = flag.Bool("test.v", false, "verbose: print additional output")
|
||||
match = flag.String("test.run", "", "regular expression to select tests and examples to run")
|
||||
memProfile = flag.String("test.memprofile", "", "write a memory profile to the named file after execution")
|
||||
memProfileRate = flag.Int("test.memprofilerate", 0, "if >=0, sets runtime.MemProfileRate")
|
||||
cpuProfile = flag.String("test.cpuprofile", "", "write a cpu profile to the named file during execution")
|
||||
timeout = flag.Duration("test.timeout", 0, "if positive, sets an aggregate time limit for all tests")
|
||||
cpuListStr = flag.String("test.cpu", "", "comma-separated list of number of CPUs to use for each test")
|
||||
parallel = flag.Int("test.parallel", runtime.GOMAXPROCS(0), "maximum test parallelism")
|
||||
chatty = flag.Bool("test.v", false, "verbose: print additional output")
|
||||
match = flag.String("test.run", "", "regular expression to select tests and examples to run")
|
||||
memProfile = flag.String("test.memprofile", "", "write a memory profile to the named file after execution")
|
||||
memProfileRate = flag.Int("test.memprofilerate", 0, "if >=0, sets runtime.MemProfileRate")
|
||||
cpuProfile = flag.String("test.cpuprofile", "", "write a cpu profile to the named file during execution")
|
||||
blockProfile = flag.String("test.blockprofile", "", "write a goroutine blocking profile to the named file after execution")
|
||||
blockProfileRate = flag.Int("test.blockprofilerate", 1, "if >= 0, calls runtime.SetBlockProfileRate()")
|
||||
timeout = flag.Duration("test.timeout", 0, "if positive, sets an aggregate time limit for all tests")
|
||||
cpuListStr = flag.String("test.cpu", "", "comma-separated list of number of CPUs to use for each test")
|
||||
parallel = flag.Int("test.parallel", runtime.GOMAXPROCS(0), "maximum test parallelism")
|
||||
|
||||
haveExamples bool // are there examples?
|
||||
|
||||
|
|
@ -420,7 +422,9 @@ func before() {
|
|||
}
|
||||
// Could save f so after can call f.Close; not worth the effort.
|
||||
}
|
||||
|
||||
if *blockProfile != "" && *blockProfileRate >= 0 {
|
||||
runtime.SetBlockProfileRate(*blockProfileRate)
|
||||
}
|
||||
}
|
||||
|
||||
// after runs after all testing.
|
||||
|
|
@ -439,6 +443,17 @@ func after() {
|
|||
}
|
||||
f.Close()
|
||||
}
|
||||
if *blockProfile != "" && *blockProfileRate >= 0 {
|
||||
f, err := os.Create(*blockProfile)
|
||||
if err != nil {
|
||||
fmt.Fprintf(os.Stderr, "testing: %s", err)
|
||||
return
|
||||
}
|
||||
if err = pprof.Lookup("block").WriteTo(f, 0); err != nil {
|
||||
fmt.Fprintf(os.Stderr, "testing: can't write %s: %s", *blockProfile, err)
|
||||
}
|
||||
f.Close()
|
||||
}
|
||||
}
|
||||
|
||||
var timer *time.Timer
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue