From 4d8e0fa166dc47325bf4693865075669b4e09fcd Mon Sep 17 00:00:00 2001 From: Raul Silvera Date: Thu, 10 Mar 2016 18:27:58 -0800 Subject: [PATCH] Apply leaf cleanup to threadz samples The legacy profilez parser handles duplicate leaf samples that are a common artifact of satck unwinding. Apply the same technique to threadz profiles where duplicate samples also occur. --- profile/legacy_profile.go | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/profile/legacy_profile.go b/profile/legacy_profile.go index 964d28d..0ce0f80 100644 --- a/profile/legacy_profile.go +++ b/profile/legacy_profile.go @@ -373,6 +373,15 @@ func cpuProfile(b []byte, period int64, parse func(b []byte) (uint64, []byte)) ( } } + if err := p.ParseMemoryMap(bytes.NewBuffer(b)); err != nil { + return nil, err + } + + cleanupDuplicateLocations(p) + return p, nil +} + +func cleanupDuplicateLocations(p *Profile) { // The profile handler may duplicate the leaf frame, because it gets // its address both from stack unwinding and from the signal // context. Detect this and delete the duplicate, which has been @@ -383,11 +392,6 @@ func cpuProfile(b []byte, period int64, parse func(b []byte) (uint64, []byte)) ( s.Location = append(s.Location[:1], s.Location[2:]...) } } - - if err := p.ParseMemoryMap(bytes.NewBuffer(b)); err != nil { - return nil, err - } - return p, nil } // parseCPUSamples parses a collection of profilez samples from a @@ -936,6 +940,7 @@ func parseThread(b []byte) (*Profile, error) { return nil, err } + cleanupDuplicateLocations(p) return p, nil }