snarkVM icon indicating copy to clipboard operation
snarkVM copied to clipboard

[Feature] Add `tracing::instrument` to allow generating flame graphs

Open kaimast opened this issue 4 months ago • 3 comments

Motivation

Generating flamegraphs using stack-based profilers, such as perftools or cargo flamegraph is great to measure CPU-bound synchronous workloads. For asynchronous or I/O bound-code tracing allows emitting information ("spans") about when a certain async function was started and finished, even if that function started/stopped multiple times, was waiting for a system call, or moved between threads.

The tracing spans can then be passed to different backends. I am particular interested in flamegraph/flamechart generation for my use case, but it also works with, for example, real-time profilers, such as tracy.

Proposed Changes

This PR adds tracing::instrument to various performance-critical functions when the instrumentation feature is enabled.

This allows, for example, generating flame graphs as is done in snarkOS PR #3916

kaimast avatar Aug 22 '25 16:08 kaimast

@vicsn I added a short motivation to the PR description.

kaimast avatar Oct 31 '25 20:10 kaimast

@vicsn I added a short motivation to the PR description.

Thank you, that seems valuable. Would this approach be able to replace https://github.com/ProvableHQ/snarkOS/pull/3930 and create a similar graph? Or will we get a different representation? I'm happy to delay merging snarkOS PR 3930 until we hone in on the specific method we want to support long-term

vicsn avatar Nov 02 '25 09:11 vicsn

I think there are ways to generate similar graphs with tracing. However, I should be fine to keep both for now, and we can revise it later.

kaimast avatar Nov 07 '25 03:11 kaimast