From 14ff889d607635083a030fc73d76b0263759be83 Mon Sep 17 00:00:00 2001 From: Vincent Ambo Date: Sun, 4 Sep 2022 19:38:26 +0300 Subject: feat(tvix/eval): implement runtime tracing methods for Observer These methods make it possible to trace the runtime execution of the VM through an observer. Change-Id: I90e26853ba2fe44748613e7f761ed5c1c5fc9ff7 Reviewed-on: https://cl.tvl.fyi/c/depot/+/6452 Reviewed-by: sterni Tested-by: BuildkiteCI --- tvix/eval/src/observer.rs | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) (limited to 'tvix/eval/src/observer.rs') diff --git a/tvix/eval/src/observer.rs b/tvix/eval/src/observer.rs index 62312a74ad..427fc2c399 100644 --- a/tvix/eval/src/observer.rs +++ b/tvix/eval/src/observer.rs @@ -10,8 +10,9 @@ use std::rc::Rc; use tabwriter::TabWriter; use crate::chunk::Chunk; -use crate::opcode::CodeIdx; +use crate::opcode::{CodeIdx, OpCode}; use crate::value::Lambda; +use crate::Value; /// Implemented by types that wish to observe internal happenings of /// Tvix. @@ -33,6 +34,22 @@ pub trait Observer { /// Called when the compiler finishes compilation of a thunk. fn observe_compiled_thunk(&mut self, _: &Rc) {} + + /// Called when the runtime enters a new call frame. + fn observe_enter_frame(&mut self, _arg_count: usize, _: &Rc, _call_depth: usize) {} + + /// Called when the runtime exits a call frame. + fn observe_exit_frame(&mut self, _frame_at: usize) {} + + /// Called when the runtime enters a builtin. + fn observe_enter_builtin(&mut self, _name: &'static str) {} + + /// Called when the runtime exits a builtin. + fn observe_exit_builtin(&mut self, _name: &'static str) {} + + /// Called when the runtime *begins* executing an instruction. The + /// provided stack is the state at the beginning of the operation. + fn observe_execute_op(&mut self, _ip: usize, _: &OpCode, _: &[Value]) {} } #[derive(Default)] -- cgit 1.4.1