diff options
author | gVisor bot <gvisor-bot@google.com> | 2020-10-29 01:29:16 +0000 |
---|---|---|
committer | gVisor bot <gvisor-bot@google.com> | 2020-10-29 01:29:16 +0000 |
commit | a50cfffd384c07e11b5d3ad21f3a096bf1ff4521 (patch) | |
tree | 9a0f389bd874a44d32d9729c118e4f338d92d198 /pkg/refs | |
parent | 0cc41c9357ae7c1db41ad74f2830253c42b007ce (diff) | |
parent | 3b4674ffe0e6ef1b016333ee726293ecf70c4e4e (diff) |
Merge release-20201019.0-95-g3b4674ffe (automated)
Diffstat (limited to 'pkg/refs')
-rw-r--r-- | pkg/refs/refcounter.go | 10 |
1 files changed, 6 insertions, 4 deletions
diff --git a/pkg/refs/refcounter.go b/pkg/refs/refcounter.go index 699ea8ac3..6992e1de8 100644 --- a/pkg/refs/refcounter.go +++ b/pkg/refs/refcounter.go @@ -319,7 +319,8 @@ func makeStackKey(pcs []uintptr) stackKey { return key } -func recordStack() []uintptr { +// RecordStack constructs and returns the PCs on the current stack. +func RecordStack() []uintptr { pcs := make([]uintptr, maxStackFrames) n := runtime.Callers(1, pcs) if n == 0 { @@ -342,7 +343,8 @@ func recordStack() []uintptr { return v } -func formatStack(pcs []uintptr) string { +// FormatStack converts the given stack into a readable format. +func FormatStack(pcs []uintptr) string { frames := runtime.CallersFrames(pcs) var trace bytes.Buffer for { @@ -367,7 +369,7 @@ func (r *AtomicRefCount) finalize() { if n := r.ReadRefs(); n != 0 { msg := fmt.Sprintf("%sAtomicRefCount %p owned by %q garbage collected with ref count of %d (want 0)", note, r, r.name, n) if len(r.stack) != 0 { - msg += ":\nCaller:\n" + formatStack(r.stack) + msg += ":\nCaller:\n" + FormatStack(r.stack) } else { msg += " (enable trace logging to debug)" } @@ -392,7 +394,7 @@ func (r *AtomicRefCount) EnableLeakCheck(name string) { case NoLeakChecking: return case LeaksLogTraces: - r.stack = recordStack() + r.stack = RecordStack() } r.name = name runtime.SetFinalizer(r, (*AtomicRefCount).finalize) |