Skip to content

Commit 69bf6e3

Browse files
dkegel-fastlydeadprogram
authored andcommitted
interp: show breadcrumbs to help developer find slow init functions; raise timeout.
1 parent 8f8d83b commit 69bf6e3

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

interp/interpreter.go

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,7 @@ func (r *runner) run(fn *function, params []value, parentMem *memoryView, indent
1717
locals := make([]value, len(fn.locals))
1818
r.callsExecuted++
1919

20-
if time.Since(r.start) > time.Minute {
21-
// Running for more than a minute. This should never happen.
22-
return nil, mem, r.errorAt(fn.blocks[0].instructions[0], fmt.Errorf("interp: running for more than a minute, timing out (executed calls: %d)", r.callsExecuted))
23-
}
20+
t0 := time.Since(r.start)
2421

2522
// Parameters are considered a kind of local values.
2623
for i, param := range params {
@@ -106,6 +103,17 @@ func (r *runner) run(fn *function, params []value, parentMem *memoryView, indent
106103
}
107104
switch inst.opcode {
108105
case llvm.Ret:
106+
t1 := time.Since(r.start)
107+
if t1-t0 > time.Second {
108+
// Provide some breadcrumbs for user trying to find their slow init functions.
109+
fmt.Fprintln(os.Stderr, "interp: slow: startms", int(t0.Milliseconds()), "endms", int(t1.Milliseconds()), "func", fn.name)
110+
}
111+
const maxInterpSeconds = 90
112+
if t0 > maxInterpSeconds*time.Second {
113+
// Running for more than maxInterpSeconds seconds. This should never happen.
114+
return nil, mem, r.errorAt(fn.blocks[0].instructions[0], fmt.Errorf("interp: running for more than %d seconds, timing out (executed calls: %d)", maxInterpSeconds, r.callsExecuted))
115+
}
116+
109117
if len(operands) != 0 {
110118
if r.debug {
111119
fmt.Fprintln(os.Stderr, indent+"ret", operands[0])

0 commit comments

Comments
 (0)