Skip to content

Commit

Permalink
trace/ptrace: handle region ends without matching region begins
Browse files Browse the repository at this point in the history
  • Loading branch information
dominikh committed Apr 17, 2024
1 parent b8d0ba9 commit c167bd1
Showing 1 changed file with 10 additions and 9 deletions.
19 changes: 10 additions & 9 deletions trace/ptrace/ptrace.go
Original file line number Diff line number Diff line change
Expand Up @@ -636,16 +636,17 @@ func processEvents(r *exptrace.Reader, tr *Trace, progress func(float64)) error
case exptrace.EventRegionEnd:
gid := ev.Goroutine()
g := getG(gid)
// XXX can we see a region end without seeing the start? Right now we can't because that crashes
// exptrace.
d := userRegionDepths[gid] - 1
ss := g.UserRegions[d]
ss[len(ss)-1].EndEvent = evID
ss[len(ss)-1].End = ev.Time()
if d > 0 {
userRegionDepths[gid] = d
} else {
delete(userRegionDepths, gid)
// We can see a region end without a region start if the two occured in different traces.
if d >= 0 {
ss := g.UserRegions[d]
ss[len(ss)-1].EndEvent = evID
ss[len(ss)-1].End = ev.Time()
if d > 0 {
userRegionDepths[gid] = d
} else {
delete(userRegionDepths, gid)
}
}
case exptrace.EventStackSample:
tr.CPUSamples = append(tr.CPUSamples, evID)
Expand Down

0 comments on commit c167bd1

Please sign in to comment.