Skip to content

Commit 1b9dc3e

Browse files
felixgeaclements
authored andcommitted
runtime: increase profiling stack depth to 128
The current stack depth limit for alloc, mutex, block, threadcreate and goroutine profiles of 32 frequently leads to truncated stack traces in production applications. Increase the limit to 128 which is the same size used by the execution tracer. Create internal/profilerecord to define variants of the runtime's StackRecord, MemProfileRecord and BlockProfileRecord types that can hold arbitrarily big stack traces. Implement internal profiling APIs based on these new types and use them for creating protobuf profiles and to act as shims for the public profiling APIs using the old types. This will lead to an increase in memory usage for applications that use the impacted profile types and have stack traces exceeding the current limit of 32. Those applications will also experience a slight increase in CPU usage, but this will hopefully soon be mitigated via CL 540476 and 533258 which introduce frame pointer unwinding for the relevant profile types. For #43669. Change-Id: Ie53762e65d0f6295f5d4c7d3c87172d5a052164e Reviewed-on: https://go-review.googlesource.com/c/go/+/572396 LUCI-TryBot-Result: Go LUCI <[email protected]> Reviewed-by: Austin Clements <[email protected]> Reviewed-by: Cherry Mui <[email protected]>
1 parent 47187a4 commit 1b9dc3e

File tree

12 files changed

+310
-110
lines changed

12 files changed

+310
-110
lines changed
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
The maximum stack depth for alloc, mutex, block, threadcreate and goroutine
2+
profiles has been raised from 32 to 128 frames.

src/cmd/internal/objabi/pkgspecial.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ var runtimePkgs = []string{
5858
"internal/godebugs",
5959
"internal/goexperiment",
6060
"internal/goos",
61+
"internal/profilerecord",
6162
"internal/stringslite",
6263
}
6364

src/go/build/deps_test.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ var depsRules = `
4545
internal/goarch, internal/godebugs,
4646
internal/goexperiment, internal/goos, internal/byteorder,
4747
internal/goversion, internal/nettrace, internal/platform,
48-
internal/trace/traceviewer/format,
48+
internal/profilerecord, internal/trace/traceviewer/format,
4949
log/internal,
5050
unicode/utf8, unicode/utf16, unicode,
5151
unsafe;
@@ -65,7 +65,8 @@ var depsRules = `
6565
internal/goarch,
6666
internal/godebugs,
6767
internal/goexperiment,
68-
internal/goos
68+
internal/goos,
69+
internal/profilerecord
6970
< internal/bytealg
7071
< internal/stringslite
7172
< internal/itoa
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
// Copyright 2024 The Go Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style
3+
// license that can be found in the LICENSE file.
4+
5+
// Package profilerecord holds internal types used to represent profiling
6+
// records with deep stack traces.
7+
//
8+
// TODO: Consider moving this to internal/runtime, see golang.org/issue/65355.
9+
package profilerecord
10+
11+
type StackRecord struct {
12+
Stack []uintptr
13+
}
14+
15+
type MemProfileRecord struct {
16+
AllocBytes, FreeBytes int64
17+
AllocObjects, FreeObjects int64
18+
Stack []uintptr
19+
}
20+
21+
func (r *MemProfileRecord) InUseBytes() int64 { return r.AllocBytes - r.FreeBytes }
22+
func (r *MemProfileRecord) InUseObjects() int64 { return r.AllocObjects - r.FreeObjects }
23+
24+
type BlockProfileRecord struct {
25+
Count int64
26+
Cycles int64
27+
Stack []uintptr
28+
}

src/runtime/cpuprof.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -209,8 +209,8 @@ func CPUProfile() []byte {
209209
panic("CPUProfile no longer available")
210210
}
211211

212-
//go:linkname runtime_pprof_runtime_cyclesPerSecond runtime/pprof.runtime_cyclesPerSecond
213-
func runtime_pprof_runtime_cyclesPerSecond() int64 {
212+
//go:linkname pprof_cyclesPerSecond
213+
func pprof_cyclesPerSecond() int64 {
214214
return ticksPerSecond()
215215
}
216216

0 commit comments

Comments
 (0)