Skip to content

Conversation

@rob-stacks
Copy link
Contributor

@rob-stacks rob-stacks commented Nov 13, 2025

Description

Add a profiler based on linux perf_events api (only x86-64 for now). This is the base for starting the optimization work on the clarity vm.

The patch exposes a new rust feature for the stackslib crate.

cargo build --features stackslib/profiler

Will add to the blockreplay endpoint the ability to profile the cpu costs of every transaction in a block (currently the number of cpu instructions, cycles and ref cycles are reported)

To enable the feature you need to pass ?profiler=1 in the query string of the endpoint.

Note that the endpoint is protected by authentication.

Note 2: the linux perf_events api could be protected on your system. To allow non-privileged use you can run:

echo 0 | sudo tee /proc/sys/kernel/perf_event_paranoid

(this will allow unprivileged access to the perf_event api)

Note 3: currently the system works only on linux x86-64

Applicable issues

  • fixes #

Additional info (benefits, drawbacks, caveats)

Checklist

  • Test coverage for new or modified code paths
  • Changelog is updated
  • Required documentation changes (e.g., docs/rpc/openapi.yaml and rpc-endpoints.md for v2 endpoints, event-dispatcher.md for new events)
  • New clarity functions have corresponding PR in clarity-benchmarking repo

@rob-stacks rob-stacks changed the title added blockreplay profiler WIP - added blockreplay profiler Nov 13, 2025
@rob-stacks rob-stacks changed the title WIP - added blockreplay profiler WIP - Added blockreplay profiler Nov 13, 2025
Copy link
Contributor

@aaronb-stacks aaronb-stacks left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks good to me, I just think we should further separate the cfg flag dependent code into a new struct so that the actual logic of the RPC endpoint is free of flags.

@rob-stacks rob-stacks changed the title WIP - Added blockreplay profiler Added blockreplay profiler Nov 19, 2025
@rob-stacks rob-stacks marked this pull request as ready for review November 19, 2025 14:31
@rob-stacks rob-stacks requested review from a team as code owners November 19, 2025 14:31
Copy link
Contributor

@adriano-stacks adriano-stacks left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am comment (instead of approving) just because of the Clippy warnings. Everything else is nits, feel free to address or ignore.

txs_receipts.push(tx_result.receipt);
txs_receipts.push((
tx_result.receipt,
profiler_result.cpu_instructions,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a nit: do we consider the profiler results "receipts"?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also is there a reason to pass the three members instead of profiler_result?

events,
post_condition_aborted: receipt.post_condition_aborted,
vm_error: receipt.vm_error.clone(),
cpu_instructions: cpu_instructions.clone(),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like Clippy doesn't like these lines :)

@aldur aldur removed their request for review November 21, 2025 08:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants