runtime/pprof: fix errors in pprof_test

I think the original depth-1 argument to allocDeep was correct.
Reverted that, and also the change to maxSkip in mprof.go, which was
also incorrect. I think before we were usually passing accidentally in
the loop over matched stacks when we really should usually have been
passing in the previous loop.

Change-Id: I6a6a696463e2baf045b66f418d7afbfcb49258e4
Reviewed-on: https://go-review.googlesource.com/c/go/+/712100
Reviewed-by: Michael Matloob <matloob@google.com>
TryBot-Bypass: Michael Matloob <matloob@golang.org>
Reviewed-by: Michael Knyszek <mknyszek@google.com>
This commit is contained in:
matloob 2025-10-15 12:52:47 -04:00 committed by Michael Matloob
parent 5c9a26c7f8
commit bb5eb51715
2 changed files with 3 additions and 5 deletions

View file

@ -49,7 +49,7 @@ const (
// desired maximum number of frames after expansion. // desired maximum number of frames after expansion.
// This should be at least as large as the largest skip value // This should be at least as large as the largest skip value
// used for profiling; otherwise stacks may be truncated inconsistently // used for profiling; otherwise stacks may be truncated inconsistently
maxSkip = 8 maxSkip = 6
// maxProfStackDepth is the highest valid value for debug.profstackdepth. // maxProfStackDepth is the highest valid value for debug.profstackdepth.
// It's used for the bucket.stk func. // It's used for the bucket.stk func.

View file

@ -2549,9 +2549,6 @@ func TestProfilerStackDepth(t *testing.T) {
for _, test := range tests { for _, test := range tests {
t.Run(test.profiler, func(t *testing.T) { t.Run(test.profiler, func(t *testing.T) {
if test.profiler == "heap" {
testenv.SkipFlaky(t, 74029)
}
var buf bytes.Buffer var buf bytes.Buffer
if err := Lookup(test.profiler).WriteTo(&buf, 0); err != nil { if err := Lookup(test.profiler).WriteTo(&buf, 0); err != nil {
t.Fatalf("failed to write heap profile: %v", err) t.Fatalf("failed to write heap profile: %v", err)
@ -2586,6 +2583,7 @@ func TestProfilerStackDepth(t *testing.T) {
t.Logf("matched stack=%s", stk) t.Logf("matched stack=%s", stk)
if len(stk) != depth { if len(stk) != depth {
t.Errorf("want stack depth = %d, got %d", depth, len(stk)) t.Errorf("want stack depth = %d, got %d", depth, len(stk))
continue
} }
if rootFn, wantFn := stk[depth-1], "runtime/pprof.allocDeep"; rootFn != wantFn { if rootFn, wantFn := stk[depth-1], "runtime/pprof.allocDeep"; rootFn != wantFn {
@ -2663,7 +2661,7 @@ func goroutineDeep(t *testing.T, n int) {
// guaranteed to have exactly the desired depth with produceProfileEvents as // guaranteed to have exactly the desired depth with produceProfileEvents as
// their root frame which is expected by TestProfilerStackDepth. // their root frame which is expected by TestProfilerStackDepth.
func produceProfileEvents(t *testing.T, depth int) { func produceProfileEvents(t *testing.T, depth int) {
allocDeep(depth + 1) // +1 for produceProfileEvents, ** allocDeep(depth - 1) // -1 for produceProfileEvents, **
blockChanDeep(t, depth-2) // -2 for produceProfileEvents, **, chanrecv1 blockChanDeep(t, depth-2) // -2 for produceProfileEvents, **, chanrecv1
blockMutexDeep(t, depth-2) // -2 for produceProfileEvents, **, Unlock blockMutexDeep(t, depth-2) // -2 for produceProfileEvents, **, Unlock
memSink = nil memSink = nil