mirror of
https://github.com/golang/go
synced 2024-11-17 15:54:39 -07:00
[dev.link] cmd/link: record per-phase memory profile
We already have an option to record per-phase CPU profiles. If we're in "mem" benchmark mode, then it also makes sense to collect a heap profile of the live heap at the end of a phase. This CL adds that profile and changes the extensions of the profiles to "cpuprof" and "memprof" to make the distinction clear. Change-Id: Ia05b7fa18bccad954a875f7a55d9cff5ad8dfaaf Reviewed-on: https://go-review.googlesource.com/c/go/+/224617 Run-TryBot: Austin Clements <austin@google.com> Reviewed-by: Than McIntosh <thanm@google.com> Reviewed-by: Cherry Zhang <cherryyz@google.com> TryBot-Result: Gobot Gobot <gobot@golang.org>
This commit is contained in:
parent
7055f01e12
commit
105053fa19
@ -116,7 +116,7 @@ func (m *Metrics) Start(name string) {
|
||||
m.curMark = &mark{name: name}
|
||||
// Unlikely we need to a GC here, as one was likely just done in closeMark.
|
||||
if m.shouldPProf() {
|
||||
f, err := os.Create(makePProfFilename(m.filebase, name))
|
||||
f, err := os.Create(makePProfFilename(m.filebase, name, "cpuprof"))
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
@ -143,6 +143,25 @@ func (m *Metrics) closeMark() {
|
||||
pprof.StopCPUProfile()
|
||||
m.pprofFile.Close()
|
||||
m.pprofFile = nil
|
||||
if m.gc == GC {
|
||||
// Collect a profile of the live heap. Do a
|
||||
// second GC to force sweep completion so we
|
||||
// get a complete snapshot of the live heap at
|
||||
// the end of this phase.
|
||||
runtime.GC()
|
||||
f, err := os.Create(makePProfFilename(m.filebase, m.curMark.name, "memprof"))
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
err = pprof.WriteHeapProfile(f)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
err = f.Close()
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
}
|
||||
m.marks = append(m.marks, m.curMark)
|
||||
m.curMark = nil
|
||||
@ -171,6 +190,6 @@ func makeBenchString(name string) string {
|
||||
return string(ret)
|
||||
}
|
||||
|
||||
func makePProfFilename(filebase, name string) string {
|
||||
return fmt.Sprintf("%s_%s.profile", filebase, makeBenchString(name))
|
||||
func makePProfFilename(filebase, name, typ string) string {
|
||||
return fmt.Sprintf("%s_%s.%s", filebase, makeBenchString(name), typ)
|
||||
}
|
||||
|
@ -39,8 +39,8 @@ func TestPProfFlag(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestPProfNames(t *testing.T) {
|
||||
want := "foo_BenchmarkTest.profile"
|
||||
if v := makePProfFilename("foo", "test"); v != want {
|
||||
want := "foo_BenchmarkTest.cpuprof"
|
||||
if v := makePProfFilename("foo", "test", "cpuprof"); v != want {
|
||||
t.Errorf("makePProfFilename() == %q, want %q", v, want)
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user