Gas Profiling
Last updated
Last updated
The Endless Gas Profiler is a powerful tool that can help you understand the gas usage of Endless transactions. Once activated, it will simulate transactions using an instrumented VM, and generate a web-based report. [Sample]
The gas profiler can also double as a debugger since the report also includes a full execution trace.
The gas profiler can be invoked by appending the --profile-gas
option to Endless CLIβs move publish
, move run
or move run-script
commands.
Here is an example using the . First, cd
into the package directory.
Then, we can simulate module publishing with the extra option --profile-gas
.
Notice that you do need to have your CLI profile set up properly and bind the named addresses correctly. Please refer to CLI Configuration for more details.
This will result in some terminal output that looks like this:
Again, it should be emphasized that even though the live chain-state is being used, this is a simulation so the module has NOT really been published to the target network.
You can then find the generated gas report in the directory gas-profiling
:
index.html is the main page of the report, and you can view it in your web browser.
The gas report consists of three parts, enabling you to understand the gas usage through different lenses.
The first section consists of visualization of the gas usage in the form of two flamegraphs: one for execution & IO, the other for storage. The reason why we need two graphs is that these are measured in different units: one in gas units, and the other in EDS.
It is possible to interact with various elements in the graph. If you hover your cursor over an item, it will show you the precise cost and percentage.
If you click on an item, you can zoom into it and see the child items more clearly. You can reset the view by clicking the "Reset Zoom" button in the top-left corner.
There is also "Search" button in the top-right corner that allows to match certain items and highlight them.
The second section is a detailed break-down of all gas costs. Data presented in this section is categorized, aggregated and sorted. This can be especially helpful if you know what numbers to look at.
For example, the following tables show the IO costs of all storage operations. The percentage here is relative to the total cost of the belonging category (Exec + IO in this case).
The final section of the gas report is the full execution trace of the transaction that looks like this:
The left column lists all Move instructions and operations being executed, with each level of indentation indicating a function call.
The middle column represents the gas costs associated with the operations.
There is also a special notation @number
that represents a jump to a particular location in the byte code. This is purely informational and to help understand the control flow.
We plan to extend the gas profiler with the following features:
Ability to replay historical transactions that have been committed (on mainnet, testnet etc.).
Ability to annotate source files.
Feedbacks and feature requests are welcome! Please kindly submit them by creating GitHub issues .