zemse / hardhat-tracer

🕵️ allows you to see internal calls, events and storage operations in the console
MIT License
341 stars 35 forks source link

Add support for gas consumption logging #35

Closed Rubilmax closed 1 year ago

Rubilmax commented 1 year ago

It would be handy to be able to follow the gas consumption of each trace, just like foundry is doing:

image

In this case, foundry is logging the remaining gas of each context at the start of each line

zemse commented 1 year ago

Can you once try adding with this gasCost in hardhat config:

{
  tracer: {
    gasCost: true
  }
}

There were some issues with accuracy in v1 so I kept it optional, but in v2 I'm just using the gas used from the VM so it should be accurate. Let me know if that seems okay, then I can make the gasCost be printed by default.

Rubilmax commented 1 year ago

Wonderful! I think it's ok to keep it disabled by default, because it's unnecessarily overwhelming if you don't use it (anyway, choose what you prefer!) Just some documentation (I may have missed this) is enough

But seeing it made me think that adding contrast to the traces would have much benefit to ease reading them! For example, making the gas consumption gray by default would make them less overwhelming:

image

Or even better: provide a way to customize the colors?

Anyway, this plugin is already great and very useful as it is!

zemse commented 1 year ago

Yeah I should update the docs for this. And seems the color for the gasLimit and gasUsed is missing, adding this to the list of my todos.

The customization of colors through the hardhat config might need some refactoring work since they are hardcoded here. Just like naming variables, I think choosing colors is a difficult job for me lol, so I initially took inspiration from Javascript/Solidity code. If you have ideas about better coloring schemes or layout of the trace, please do let me know. Having more information available in a readable/less overwhelming manner would definitely be great.

Rubilmax commented 1 year ago

I'd be glad to dive into this and propose a PR to update the colors! You can assign me to this issue