]> Cypherpunks repositories - gostls13.git/commitdiff
runtime/pprof: track locations for goroutine profiles
authorRaul Silvera <rsilvera@google.com>
Wed, 7 Dec 2016 23:36:22 +0000 (15:36 -0800)
committerMichael Matloob <matloob@golang.org>
Fri, 9 Dec 2016 19:14:26 +0000 (19:14 +0000)
Must add locations to the profile when generating a profile.proto.
This fixes #18229

Change-Id: I49cd63a30759d3fe8960d7b7c8bd5a554907f8d1
Reviewed-on: https://go-review.googlesource.com/34028
Reviewed-by: Michael Matloob <matloob@golang.org>
Run-TryBot: Michael Matloob <matloob@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>

src/runtime/pprof/pprof.go

index aed5b8da9c628d1665e163a9e0ce68f725dba941..871fba0e5f99a1eae9257ad92bedc9f053afcf08 100644 (file)
@@ -386,12 +386,22 @@ func printCountProfile(w io.Writer, debug int, name string, p countProfile) erro
                Sample:     make([]*profile.Sample, 0, len(keys)),
                SampleType: []*profile.ValueType{{Type: name, Unit: "count"}},
        }
+       locMap := make(map[uintptr]*profile.Location)
        for _, k := range keys {
                stk := p.Stack(index[k])
                c := count[k]
                locs := make([]*profile.Location, len(stk))
                for i, addr := range stk {
-                       locs[i] = &profile.Location{Address: uint64(addr) - 1}
+                       loc := locMap[addr]
+                       if loc == nil {
+                               loc = &profile.Location{
+                                       ID:      uint64(len(locMap) + 1),
+                                       Address: uint64(addr - 1),
+                               }
+                               prof.Location = append(prof.Location, loc)
+                               locMap[addr] = loc
+                       }
+                       locs[i] = loc
                }
                prof.Sample = append(prof.Sample, &profile.Sample{
                        Location: locs,