interp: show breadcrumbs to help developer find slow init functions; raise timeout.

Этот коммит содержится в:
Dan Kegel 2022-01-10 16:04:46 -08:00 коммит произвёл Ron Evans
родитель 8f8d83bffe
коммит 69bf6e3c89

Просмотреть файл

@ -17,10 +17,7 @@ func (r *runner) run(fn *function, params []value, parentMem *memoryView, indent
locals := make([]value, len(fn.locals)) locals := make([]value, len(fn.locals))
r.callsExecuted++ r.callsExecuted++
if time.Since(r.start) > time.Minute { t0 := time.Since(r.start)
// Running for more than a minute. This should never happen.
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))
}
// Parameters are considered a kind of local values. // Parameters are considered a kind of local values.
for i, param := range params { for i, param := range params {
@ -106,6 +103,17 @@ func (r *runner) run(fn *function, params []value, parentMem *memoryView, indent
} }
switch inst.opcode { switch inst.opcode {
case llvm.Ret: case llvm.Ret:
t1 := time.Since(r.start)
if t1-t0 > time.Second {
// Provide some breadcrumbs for user trying to find their slow init functions.
fmt.Fprintln(os.Stderr, "interp: slow: startms", int(t0.Milliseconds()), "endms", int(t1.Milliseconds()), "func", fn.name)
}
const maxInterpSeconds = 90
if t0 > maxInterpSeconds*time.Second {
// Running for more than maxInterpSeconds seconds. This should never happen.
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))
}
if len(operands) != 0 { if len(operands) != 0 {
if r.debug { if r.debug {
fmt.Fprintln(os.Stderr, indent+"ret", operands[0]) fmt.Fprintln(os.Stderr, indent+"ret", operands[0])