MCPcopy Index your code
hub / github.com/maruel/panicparse / snapshot

Function snapshot

stack/webstack/webstack.go:98–127  ·  view source on GitHub ↗

snapshot returns a Context based on the snapshot of the stacks of the current process.

(maxmem int, opts *stack.Opts)

Source from the content-addressed store, hash-verified

96// snapshot returns a Context based on the snapshot of the stacks of the
97// current process.
98func snapshot(maxmem int, opts *stack.Opts) (*stack.Snapshot, error) {
99 // We don't know how big the buffer needs to be to collect all the
100 // goroutines. Start with 1 MB and try a few times, doubling each time. Give
101 // up and use a truncated trace if maxmem is not enough.
102 buf := make([]byte, 1<<20)
103 if maxmem < len(buf) {
104 maxmem = len(buf)
105 }
106 for i := 0; ; i++ {
107 n := runtime.Stack(buf, true)
108 if n < len(buf) {
109 buf = buf[:n]
110 break
111 }
112 if len(buf) >= maxmem {
113 break
114 }
115 l := len(buf) * 2
116 if l > maxmem {
117 l = maxmem
118 }
119 buf = make([]byte, l)
120 }
121 s, _, err := stack.ScanSnapshot(bytes.NewReader(buf), io.Discard, opts)
122 // That's expected.
123 if err == io.EOF {
124 err = nil
125 }
126 return s, err
127}

Callers 1

SnapshotHandlerFunction · 0.85

Calls 1

ScanSnapshotFunction · 0.92

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…