delete(gs.activeRanges, name)
}
-func lastFunc(s trace.Stack) string {
- var last trace.StackFrame
- s.Frames()(func(f trace.StackFrame) bool {
- last = f
- return true
- })
- return last.Func
+func lastFunc(s trace.Stack) (fn string) {
+ for frame := range s.Frames() {
+ fn = frame.Func
+ }
+ return
}
prof := make([]traceviewer.ProfileRecord, 0, len(m.stacks))
for stack, record := range m.stacks {
rec := *record
- i := 0
- stack.Frames()(func(frame trace.StackFrame) bool {
+ for i, frame := range slices.Collect(stack.Frames()) {
rec.Stack = append(rec.Stack, &trace.Frame{
PC: frame.PC,
Fn: frame.Func,
File: frame.File,
Line: int(frame.Line),
})
- i++
// Cut this off at pprofMaxStack because that's as far
// as our deduplication goes.
- return i < pprofMaxStack
- })
+ if i >= pprofMaxStack {
+ break
+ }
+ }
prof = append(prof, rec)
}
return prof
// pcsForStack extracts the first pprofMaxStack PCs from stack into pcs.
func pcsForStack(stack trace.Stack, pcs *[pprofMaxStack]uint64) {
- i := 0
- stack.Frames()(func(frame trace.StackFrame) bool {
+ for i, frame := range slices.Collect(stack.Frames()) {
pcs[i] = frame.PC
- i++
- return i < len(pcs)
- })
+ if i >= len(pcs) {
+ break
+ }
+ }
}
func regionTopStackFrame(r *trace.UserRegionSummary) trace.StackFrame {
var frame trace.StackFrame
if r.Start != nil && r.Start.Stack() != trace.NoStack {
- r.Start.Stack().Frames()(func(f trace.StackFrame) bool {
+ for f := range r.Start.Stack().Frames() {
frame = f
- return false
- })
+ }
}
return frame
}
// used to store the frames to reduce allocations.
func viewerFrames(stk trace.Stack) []*trace.Frame {
var frames []*trace.Frame
- stk.Frames()(func(f trace.StackFrame) bool {
+ for f := range stk.Frames() {
frames = append(frames, &trace.Frame{
PC: f.PC,
Fn: f.Func,
File: f.File,
Line: int(f.Line),
})
- return true
- })
+ }
return frames
}
if s.Stack != NoStack {
fmt.Fprintln(&sb)
fmt.Fprintln(&sb, "TransitionStack=")
- s.Stack.Frames()(func(f StackFrame) bool {
+ for f := range s.Stack.Frames() {
fmt.Fprintf(&sb, "\t%s @ 0x%x\n", f.Func, f.PC)
fmt.Fprintf(&sb, "\t\t%s:%d\n", f.File, f.Line)
- return true
- })
+ }
}
case EventExperimental:
r := e.Experimental()
if stk := e.Stack(); stk != NoStack {
fmt.Fprintln(&sb)
fmt.Fprintln(&sb, "Stack=")
- stk.Frames()(func(f StackFrame) bool {
+ for f := range stk.Frames() {
fmt.Fprintf(&sb, "\t%s @ 0x%x\n", f.Func, f.PC)
fmt.Fprintf(&sb, "\t\t%s:%d\n", f.File, f.Line)
- return true
- })
+ }
}
return sb.String()
}
// This root frame will be identical for all transitions on this
// goroutine, because it represents its immutable start point.
if g.Name == "" {
- stk := st.Stack
- if stk != NoStack {
- var frame StackFrame
- var ok bool
- stk.Frames()(func(f StackFrame) bool {
- frame = f
- ok = true
- return true
- })
- if ok {
- // NB: this PC won't actually be consistent for
- // goroutines which existed at the start of the
- // trace. The UI doesn't use it directly; this
- // mainly serves as an indication that we
- // actually saw a call stack for the goroutine
- g.PC = frame.PC
- g.Name = frame.Func
- }
+ for frame := range st.Stack.Frames() {
+ // NB: this PC won't actually be consistent for
+ // goroutines which existed at the start of the
+ // trace. The UI doesn't use it directly; this
+ // mainly serves as an indication that we
+ // actually saw a call stack for the goroutine
+ g.PC = frame.PC
+ g.Name = frame.Func
}
}
func checkStack(e *errAccumulator, stk trace.Stack) {
// Check for non-empty values, but we also check for crashes due to incorrect validation.
- i := 0
- stk.Frames()(func(f trace.StackFrame) bool {
+ for i, f := range slices.Collect(stk.Frames()) {
if i == 0 {
// Allow for one fully zero stack.
//
// TODO(mknyszek): Investigate why that happens.
- return true
+ continue
}
if f.Func == "" || f.File == "" || f.PC == 0 || f.Line == 0 {
e.Errorf("invalid stack frame %#v: missing information", f)
}
- i++
- return true
- })
+ }
}
type errAccumulator struct {
"os"
"path/filepath"
"runtime"
+ "slices"
"strings"
"testing"
)
if hogRegion != nil && ev.Goroutine() == hogRegion.Goroutine() {
traceSamples++
var fns []string
- ev.Stack().Frames()(func(frame trace.StackFrame) bool {
+ for frame := range ev.Stack().Frames() {
if frame.Func != "runtime.goexit" {
fns = append(fns, fmt.Sprintf("%s:%d", frame.Func, frame.Line))
}
- return true
- })
+ }
stack := strings.Join(fns, "|")
traceStacks[stack]++
}
}...)
}
stackMatches := func(stk trace.Stack, frames []frame) bool {
- i := 0
- match := true
- stk.Frames()(func(f trace.StackFrame) bool {
+ for i, f := range slices.Collect(stk.Frames()) {
if f.Func != frames[i].fn {
- match = false
return false
}
if line := uint64(frames[i].line); line != 0 && line != f.Line {
- match = false
return false
}
- i++
- return true
- })
- return match
+ }
+ return true
}
r, err := trace.NewReader(bytes.NewReader(tb))
if err != nil {
// dumpStack returns e.Stack() as a string.
func dumpStackV2(e *trace.Event) string {
var buf bytes.Buffer
- e.Stack().Frames()(func(f trace.StackFrame) bool {
+ for f := range e.Stack().Frames() {
file := strings.TrimPrefix(f.File, runtime.GOROOT())
fmt.Fprintf(&buf, "%s\n\t%s:%d\n", f.Func, file, f.Line)
- return true
- })
+ }
return buf.String()
}