Gas Profiler
Gas Profiler gives you a breakdown of gas consumption, revealing how each function within a contract uses gas during execution. When combined with Debugger and Simulator, Gas Profiler makes up the core of the Developer Explorer.
Getting started with Gas Profiler
-
Open any transaction from the transaction listing page. Try this example transaction.
-
Navigate to Gas Profiler in the top menu to access an interactive flame chart with detailed gas usage breakdowns for each called function, including internal transactions.
-
Click on any function to reveal a detailed view of its gas usage.
-
For deeper insights, open the transaction in Debugger to pinpoint the exact line of code in the Solidity file responsible for execution.
Optimizing gas usage
-
Clicking on a function call in the flame chart displays detailed gas usage information in the lower pane.
-
If you suspect a function requires gas optimization, click the View in Debugger button to dive into the code and optimize it to reduce gas usage.
-
To verify that the changes help reduce gas usage, you can simulate the same transaction with the changed code and compare the gas profiling result.
Total gas vs actual gas
Total Gas represents the overall gas cost of execution, encompassing the sum of gas costs associated with all invoked opcodes.
Actual Gas denotes the net gas cost of the execution. When multiplied by the gas_price
, it provides the exact amount you would pay for this execution in wei.
The formula for calculating Actual Gas: actual_gas_used = total_gas - gas_refund
.
Blockchain users receive rewards for clearing up storage, manifested in the form of gas refunds for SSTORE
invocations that effectively “delete” existing stored data. These gas refunds are subtracted from the Total Gas, resulting in the Actual Gas used.