@@ -1009,6 +1009,7 @@ func mutexevent(cycles int64, skip int) {
10091009// A StackRecord describes a single execution stack.
10101010type StackRecord struct {
10111011 Stack0 [32 ]uintptr // stack trace for this record; ends at first 0 entry
1012+ goid uint64 // Goroutine ID for the first record (or 0 if undefined by the struct creator).
10121013}
10131014
10141015// Stack returns the stack trace associated with the record,
@@ -1022,6 +1023,11 @@ func (r *StackRecord) Stack() []uintptr {
10221023 return r .Stack0 [0 :]
10231024}
10241025
1026+ // GoID returns an identifier for the Goroutine this stack was captured for, or zero if undefined.
1027+ func (r * StackRecord ) GoID () uint64 {
1028+ return r .goid
1029+ }
1030+
10251031// MemProfileRate controls the fraction of memory allocations
10261032// that are recorded and reported in the memory profile.
10271033// The profiler aims to sample an average of
@@ -1707,6 +1713,7 @@ func GoroutineProfile(p []StackRecord) (n int, ok bool) {
17071713 }
17081714 for i , mr := range records [0 :n ] {
17091715 copy (p [i ].Stack0 [:], mr .Stack )
1716+ p [i ].goid = mr .GoID
17101717 }
17111718 return
17121719}
@@ -1735,6 +1742,7 @@ func saveg(pc, sp uintptr, gp *g, r *profilerecord.StackRecord, pcbuf []uintptr)
17351742 n := tracebackPCs (& u , 0 , pcbuf )
17361743 r .Stack = make ([]uintptr , n )
17371744 copy (r .Stack , pcbuf )
1745+ r .GoID = gp .goid
17381746}
17391747
17401748// Stack formats a stack trace of the calling goroutine into buf
0 commit comments