0xPolygonMiden / miden-vm

STARK-based virtual machine
MIT License
610 stars 148 forks source link

Add tracing support to the VM #1375

Open hackaugusto opened 3 days ago

hackaugusto commented 3 days ago

Feature request

Allow setting up a callback to the VM, which is called on every instruction, after the instruction is executed

Feature description

This would allow lots of features:

Sample profiling

The callback would collect a sample every ith instruction, extract the frame from the source mapping, and generate a flame graph.

Tracing profiling

Get the current line from source mapping, increment a counter, and report the instruction count on a per line base

Coverage reports

Use the tracing feature to collect information of which lines of code are being hit during test execution, aggregate the data and generate a report in the CI to get coverage testing

Notes

It is probably best to have this feature behind a feature flag, since executing a callback on every instruction has a non trivial overhead cost.

hackaugusto commented 3 days ago

The proposal above is inspired by the tracing api in the CPython interpreter. I have used this API to implement the features I mentioned above, once the tracing API is in-place it is very trivial to implement tooling on top.