aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorRhys Hiltner <rhys@justin.tv>2023-10-24 13:10:13 -0700
committerGopher Robot <gobot@golang.org>2023-10-25 17:37:34 +0000
commit9cdcb01320d9a866e46a2daedb9bde16e0d51278 (patch)
tree0de8efae82f1d513f70ef8bfa63e52a035114990 /src
parent884c93a6df07eb62efeaa44265b58936d3084dd7 (diff)
downloadgo-9cdcb01320d9a866e46a2daedb9bde16e0d51278.tar.xz
runtime/pprof: include labels for caller of goroutine profile
The goroutine profile has close to three code paths for adding a goroutine record to the goroutine profile: one for the goroutine that requested the profile, one for every other goroutine, plus some special handling for the finalizer goroutine. The first of those captured the goroutine stack, but neglected to include that goroutine's labels. Update the tests to check for the inclusion of labels for all three types of goroutines, and include labels for the creator of the goroutine profile. For #63712 Change-Id: Id5387a5f536d3c37268c240e0b6db3d329a3d632 Reviewed-on: https://go-review.googlesource.com/c/go/+/537515 LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Michael Pratt <mpratt@google.com> Auto-Submit: Rhys Hiltner <rhys@justin.tv> Reviewed-by: David Chase <drchase@google.com>
Diffstat (limited to 'src')
-rw-r--r--src/runtime/mprof.go3
-rw-r--r--src/runtime/pprof/pprof_test.go37
2 files changed, 37 insertions, 3 deletions
diff --git a/src/runtime/mprof.go b/src/runtime/mprof.go
index 937194a238..146f1aaa52 100644
--- a/src/runtime/mprof.go
+++ b/src/runtime/mprof.go
@@ -930,6 +930,9 @@ func goroutineProfileWithLabelsConcurrent(p []StackRecord, labels []unsafe.Point
systemstack(func() {
saveg(pc, sp, ourg, &p[0])
})
+ if labels != nil {
+ labels[0] = ourg.labels
+ }
ourg.goroutineProfiled.Store(goroutineProfileSatisfied)
goroutineProfile.offset.Store(1)
diff --git a/src/runtime/pprof/pprof_test.go b/src/runtime/pprof/pprof_test.go
index 029a362cb4..6b299e59bf 100644
--- a/src/runtime/pprof/pprof_test.go
+++ b/src/runtime/pprof/pprof_test.go
@@ -1419,6 +1419,23 @@ func TestGoroutineCounts(t *testing.T) {
}
})
+ SetGoroutineLabels(WithLabels(context.Background(), Labels("self-label", "self-value")))
+ defer SetGoroutineLabels(context.Background())
+
+ garbage := new(*int)
+ fingReady := make(chan struct{})
+ runtime.SetFinalizer(garbage, func(v **int) {
+ Do(context.Background(), Labels("fing-label", "fing-value"), func(ctx context.Context) {
+ close(fingReady)
+ <-c
+ })
+ })
+ garbage = nil
+ for i := 0; i < 2; i++ {
+ runtime.GC()
+ }
+ <-fingReady
+
var w bytes.Buffer
goroutineProf := Lookup("goroutine")
@@ -1428,8 +1445,22 @@ func TestGoroutineCounts(t *testing.T) {
labels := labelMap{"label": "value"}
labelStr := "\n# labels: " + labels.String()
- if !containsInOrder(prof, "\n50 @ ", "\n44 @", labelStr,
- "\n40 @", "\n36 @", labelStr, "\n10 @", "\n9 @", labelStr, "\n1 @") {
+ selfLabel := labelMap{"self-label": "self-value"}
+ selfLabelStr := "\n# labels: " + selfLabel.String()
+ fingLabel := labelMap{"fing-label": "fing-value"}
+ fingLabelStr := "\n# labels: " + fingLabel.String()
+ orderedPrefix := []string{
+ "\n50 @ ",
+ "\n44 @", labelStr,
+ "\n40 @",
+ "\n36 @", labelStr,
+ "\n10 @",
+ "\n9 @", labelStr,
+ "\n1 @"}
+ if !containsInOrder(prof, append(orderedPrefix, selfLabelStr)...) {
+ t.Errorf("expected sorted goroutine counts with Labels:\n%s", prof)
+ }
+ if !containsInOrder(prof, append(orderedPrefix, fingLabelStr)...) {
t.Errorf("expected sorted goroutine counts with Labels:\n%s", prof)
}
@@ -1450,7 +1481,7 @@ func TestGoroutineCounts(t *testing.T) {
36: {"label": "value"},
10: {},
9: {"label": "value"},
- 1: {},
+ 1: {"self-label": "self-value", "fing-label": "fing-value"},
}
if !containsCountsLabels(p, expectedLabels) {
t.Errorf("expected count profile to contain goroutines with counts and labels %v, got %v",