Skip to content

Commit

Permalink
Apply leaf cleanup to threadz samples
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
rauls5382 committed Mar 11, 2016
1 parent 7d7ed67 commit 4d8e0fa
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions profile/legacy_profile.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -936,6 +940,7 @@ func parseThread(b []byte) (*Profile, error) {
return nil, err
}

cleanupDuplicateLocations(p)
return p, nil
}

Expand Down

0 comments on commit 4d8e0fa

Please sign in to comment.