foundry-rs / foundry

Foundry is a blazing fast, portable and modular toolkit for Ethereum application development written in Rust.
https://getfoundry.sh
Apache License 2.0
7.94k stars 1.61k forks source link

feat(`forge`): add support for flamegraph #7761

Open zemse opened 3 months ago

zemse commented 3 months ago

Component

Forge

Describe the feature you would like

I was recently interested in flamegraphs, had to hack something locally and then over the weekend packaged it as a foundry plugin: forge-flamegraph. Here is a 4-minute video demo.

The features in brief:

After asking for some feedback, I've learned that there is friction because of typical solidity devs don't have Cargo installed as well as current flow of installation also requires users to build the plugin. I've created https://github.com/foundry-rs/foundry/issues/7760 to discuss potential remedies for this problem. The reason I went forward with a plugin instead of direct subcommand PR because I was mainly interested in the "debug trace flamegraph" which is very hacky and does not always work well, so I was not sure if having such experimental code in foundry codebase is fine.

But if this is helpful, I am interested to clean up the code and PR, so that these features are more accessible to people!

Additional context

No response

klkvr commented 1 month ago

Hi @zemse! Great work on this project, it would be great if we could get this into foundry natively :)

Do you have time for kicking off PR with this at the moment? We'd be happy to give you pointers and help with integrating everything into existing code

zemse commented 1 month ago

Sure I'll try making a PR over the weekend :)

klkvr commented 1 month ago

hey @zemse I've been playing around with internal fns tracking in https://github.com/foundry-rs/foundry/pull/8222 lately in context of displaying them in traces

it is based on using the CallTraceArena instead of DebugStep so should be easier to integrate as it does not require using debugger logic directly.

I believe it can be reused for flamegraphs as well so feel free to use it in your PR if you find it feasible to integrate

klkvr commented 1 month ago

hey @zemse! how's it going with the PR? do you need any help?

zemse commented 1 month ago

Sorry last weekend I was not in best health, couldn't start this.

I looked at your PR and it made sense. Aiming to make up something this weekend!