Skip to content

Instantly share code, notes, and snippets.

@felixge
Last active December 28, 2021 20:25
Show Gist options
  • Save felixge/f2db51659ad2e36274377698b206eaae to your computer and use it in GitHub Desktop.
Save felixge/f2db51659ad2e36274377698b206eaae to your computer and use it in GitHub Desktop.
diff --git a/src/runtime/pprof/pprof_test.go b/src/runtime/pprof/pprof_test.go
index 1947edf44a..f474036ccf 100644
--- a/src/runtime/pprof/pprof_test.go
+++ b/src/runtime/pprof/pprof_test.go
@@ -1435,49 +1435,25 @@ func TestLabelSystemstack(t *testing.T) {
// Two conditions to check:
// * labelHog should always be labeled.
// * The label should _only_ appear on labelHog and the Do call above.
- for _, s := range p.Sample {
+ _true, _false := true, false
+ for i, s := range p.Sample {
isLabeled := s.Label != nil && contains(s.Label["key"], "value")
- var mayBeLabeled bool
- var mustBeLabeled bool
+ var wantLabeled *bool
for _, loc := range s.Location {
for _, l := range loc.Line {
switch l.Function.Name {
case "runtime/pprof.labelHog", "runtime/pprof.parallelLabelHog":
- mustBeLabeled = true
- case "runtime/pprof.Do":
- // Do sets the labels, so samples may
- // or may not be labeled depending on
- // which part of the function they are
- // at.
- mayBeLabeled = true
- case "runtime.execute":
- // execute sets up a goroutine to begin
- // execution. It sets get().m.curg to
- // the user goroutine and is thus pprof
- // samples will be labeled with the
- // user labels.
- mayBeLabeled = true
- case "runtime.morestack":
- // We can't always trace past morestack.
- mayBeLabeled = true
- case "gosave_systemstack_switch":
- // This is the systemstack critical
- // switch function, and we can't do a
- // full traceback from this location to
- // see where the labels came from.
- mayBeLabeled = true
+ wantLabeled = &_true
+ case "runtime.gcBgMarkWorker":
+ wantLabeled = &_false
}
}
}
- if isLabeled != mustBeLabeled {
- var buf bytes.Buffer
- fprintStack(&buf, s.Location)
- t.Errorf("Sample labeled got %v want %v: %s", isLabeled, mustBeLabeled, buf.String())
- }
- if isLabeled && !(mayBeLabeled || mustBeLabeled) {
+
+ if wantLabeled != nil && *wantLabeled != isLabeled {
var buf bytes.Buffer
fprintStack(&buf, s.Location)
- t.Errorf("Sample labeled got %v want false: %s", isLabeled, buf.String())
+ t.Errorf("Sample %d labeled got %v want %v: %s", i, isLabeled, *wantLabeled, buf.String())
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment