[Feature] Add `tracing::instrument` to allow generating flame graphs
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
@vicsn I added a short motivation to the PR description.
@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
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.