Closed zerosnacks closed 3 weeks ago
I think this is part of a larger issue we should think about holistically - all commands should output the same information with --json
as rendered to stdout and be aware of the context of other flags. Passing --json
to forge test
with --gas-report
has a different expectation of output than without --gas-report
.
Would be very interesting such feature, because we can link follow up the metrics of gas usage in the contract as per commit basis, specially when running tasks on CI, and git hooks.
Suggestion for the output format: https://bencher.dev/docs/reference/bencher-metric-format/
Additional info: https://bencher.dev/docs/how-to/track-custom-benchmarks/
Not sure if there are other standards out there, but using this format would allow for an easy adapter to Bencher.
@beeb Looks good.
Would be good if gas snapshot and gas report become a single file, as their information are complementary. I mean, gas-snapshot is the summary of gas costs for the tests, while gas-report is the individual cost of each operation on the smart contracts used by the tests.
I think that this feature would help us detect bad efficiencies in the code.
Yes, it would be good if the result of gas report can be written to a single file. I love this feature.
The proposed JSON output in https://github.com/foundry-rs/foundry/pull/9063 looks as follows:
{
"gas":106715,
"size":277,
"functions":{
"increment":{
"increment()":{
"calls":1,
"min":43404,
"mean":43404,
"median":43404,
"max":43404
}
},
"number":{
"number()":{
"calls":257,
"min":283,
"mean":283,
"median":283,
"max":283
}
},
"setNumber":{
"setNumber(uint256)":{
"calls":258,
"min":23582,
"mean":43384,
"median":43542,
"max":43866
}
}
}
}
Equivalent to:
| src/Counter.sol:Counter contract | | | | | |
|----------------------------------|-----------------|-------|--------|-------|---------|
| Deployment Cost | Deployment Size | | | | |
| 106715 | 277 | | | | |
| Function Name | min | avg | median | max | # calls |
| increment | 43404 | 43404 | 43404 | 43404 | 1 |
| number | 283 | 283 | 283 | 283 | 257 |
| setNumber | 23582 | 43224 | 43554 | 43866 | 258 |
Each test suite is rendered on a new line and can easily be parsed with jq
for next steps or piped to a file
Component
Forge
Have you ensured that all of these are up to date?
What version of Foundry are you on?
forge 0.2.0 (d75318c 2024-09-02T00:21:21.377809037Z)
What command(s) is the bug in?
forge test --gas-report --json
Operating System
Linux
Describe the bug
forge test --gas-report
yields:Whereas
forge test --gas-report --json | jq
yields:Which are the results of running the test whereas I would assume
--json
would yield a JSON representation of the table layout:This would address the feature raised in https://github.com/foundry-rs/foundry/issues/8781
A possible format could be: