Endless
  • πŸš€README
  • Discovery
    • πŸš€Endless Web3 Genesis Cloud
    • πŸ’ŽBusiness Model
    • 🎯Vision
    • ✈️Roadmap
    • πŸͺ™Economics
    • πŸ‘€Team
      • Yu Xiong
      • Amit Kumar Jaiswal
      • Ned
      • 0xfun
      • Scott Trowbridge
      • Neeraj Sharma LLB
      • Amjad Suleman
      • Binu Paul
      • Eduard Romulus GOEAN
    • ❀️Developer Community
  • Endless Chain
    • Tech Docs
      • Account Address Format
      • Endless Account
      • Endless Coin(EDS)
      • Sponsored Transaction
      • On-Chain Multisig
      • Randomness
      • Safety Transaction
      • Token Locking & Distribution
    • Start
      • Learn about Endless
        • Accounts
        • Resources
        • Events
        • Transactions and States
        • Gas and Storage Fees
        • Computing Transaction Gas
        • Blocks
        • Staking
          • Delegated Staking
        • Governance
        • Endless Blockchain Deep Dive
          • Validator Nodes Overview
          • Fullnodes Overview
          • Node Networks and Synchronization
        • Move - A Web3 Language and Runtime
      • Explore Endless
      • Latest Endless Releases
      • Networks
    • Build
      • Tutorials
        • Your First Transaction
        • Your First Fungible Asset
        • Your First NFT
        • Your First Move Module
        • Your First Multisig
      • Learn the Move Language
        • The Move Book
          • Getting Started
            • Introduction
            • Modules and Scripts
          • Primitive Types
            • Move Tutorial
            • Integers
            • Bool
            • Address
            • Vector
            • Signer
            • References
            • Tuples and Unit
          • Basic Concepts
            • Local Variables and Scope
            • Equality
            • Abort and Assert
            • Conditionals
            • While, For, and Loop
            • Functions
            • Structs and Resources
            • Constants
            • Generics
            • Abilities
            • Uses and Aliases
            • Friends
            • Packages
            • Package Upgrades
            • Unit Tests
          • Global Storage
            • Global Storage - Structure
            • Global Storage - Operators
          • Reference
            • Libraries
            • Move Coding Conventions
        • Advanced Move Guides
          • Objects
            • Creating Objects
            • Configuring objects
            • Using objects
          • Move Scripts
            • Writing Move Scripts
            • Compiling Move Scripts
            • Running Move Scripts
            • Move Scripts Tutorial
          • Resource Accounts
          • Modules on Endless
          • Cryptography
          • Gas Profiling
          • Security
      • Endless Standards
        • Object
        • Endless Fungible Asset Standard
        • Endless Digital Asset Standard
        • Endless Wallet Standard
      • Endless APIs
        • Fullnode Rest API
        • Indexer Restful API
          • Indexer Installation
        • GRPC Transaction Stream
          • Running Locally
          • Custom Processors
            • End-to-End Tutorial
            • Parsing Transactions
          • Self-Hosted Transaction Stream Service
      • Endless SDKs
        • TypeScript SDK
          • Account
          • SDK Configuration
          • Fetch data from chain
          • Transaction Builder
          • HTTP Client
          • Move Types
          • Testing
          • Typescript
        • Rust SDK
        • Go SDK
      • Endless CLI
        • Install the Endless CLI
          • Install On Mac
          • Install On Alibaba Cloud
          • Install On Linux
          • Install On Windows
        • CLI Configuration
        • Use Endless CLI
          • Working With Move Contracts
            • Arguments in JSON Tutorial
          • Trying Things On-Chain
            • Look Up On-Chain Account Info
            • Create Test Accounts
          • Running A Local Network
            • Running a Public Network
          • Managing a Network Node
      • Integrate with Endless
        • Endless Token Overview
        • Application Integration Guide
      • Endless VSCode extension
      • Advanced Builder Guides
        • Develop Locally
          • Running a Local Network
          • Run a Localnet with Validator
    • Nodes
      • Learn about Nodes
      • Run a Validator and VFN
        • Node Requirements
        • Deploy Nodes
          • Using Docker
          • Using AWS
          • Using Azure
          • Using GCP
        • Connect Nodes
          • Connect to a Network
        • Verify Nodes
          • Node Health
          • Validator Leaderboard
      • Run a Public Fullnode
        • PFN Requirements
        • Deploy a PFN
          • Using Pre-compiled Binary
          • Using Docker
          • Using GCP 🚧 (under_construction)
        • Verify a PFN
        • Modify a PFN
          • Upgrade your PFN
          • Generate a PFN Identity
          • Customize PFN Networks
      • Bootstrap a Node
        • Bootstrap from a Snapshot
        • Bootstrap from a Backup
      • Configure a Node
        • State Synchronization
        • Data Pruning
        • Telemetry
        • Locating Node Files
          • Files For Mainnet
          • Files For Testnet
          • Files For Devnet
      • Monitor a Node
        • Node Inspection Service
        • Important Node Metrics
        • Node Health Checker
    • Reference
      • Endless Error Codes
      • Move Reference Documentation
      • Endless Glossary
    • FAQs
  • Endless Bridge
    • Intro to Endless Bridge
    • How to use bridge
    • Liquidity Management
    • Faucet
    • Developer Integration
      • Contract Integration
        • Message Contract
        • Execute Contract
      • Server-Side Integration
        • Message Sender
        • Example of Message Listener Service (Rust)
        • Example of Token Cross-Chain (JS)
  • Endless Wallet
    • User Guide
    • Basic Tutorial
    • FAQs
    • MultiAccount
    • SDK
      • Functions
      • Events
  • GameFi
    • Intro
    • GameFi & Endless
  • Endless Modules
    • Stacks
    • Storage
    • Module List
  • Endless Ecosystem
    • Intro
    • Show Cases
    • App Demo
  • Whitepaper
  • Endless SCAN
    • User Guide
  • MULTI-SIGNATURE
    • Multi-Signature User Guide
  • Regulations
    • Privacy Policy
    • Terms of Service
    • Funding Terms - Disclaimer
Powered by GitBook
On this page
  • Gas Profiling
  • Using the Gas Profiler
  • Understanding the Gas Report
  • Future Plans
Export as PDF
  1. Endless Chain
  2. Build
  3. Learn the Move Language
  4. Advanced Move Guides

Gas Profiling

PreviousCryptographyNextSecurity

Last updated 2 months ago

Gas Profiling

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.

Using the Gas Profiler

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.

$ cd endless-move/move-examples/hello_blockchain

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.

$ endless move publish --named-addresses hello_blockchain=default --profile-gas

This will result in some terminal output that looks like this:

Compiling, may take a little while to download git dependencies...
INCLUDING DEPENDENCY EndlessFramework
INCLUDING DEPENDENCY EndlessStdlib
INCLUDING DEPENDENCY MoveStdlib
BUILDING Examples
package size 1755 bytes

Simulating transaction locally with the gas profiler...
{
  "Result": {
    "transaction_hash": "0x26cc23d11070e6756c6b2ae0ea7d3fc4c791b59cf821f268ba0f03eebb487543",
    "gas_used": 1039,
    "gas_unit_price": 100,
    "sender": "dbcbe741d003a7369d87ec8717afb5df425977106497052f96f4e236372f7dd5",
    "success": true,
    "version": 762354147,
    "vm_status": "status EXECUTED of type Execution"
  }
}

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:

- hello_blockchain
  - gas-profiling
    - txn-xxxxxxxx-0x1-code-publish_package_txn
      - assets
      - index.html
  - sources
  - Move.toml

index.html is the main page of the report, and you can view it in your web browser.

Understanding the Gas Report

The gas report consists of three parts, enabling you to understand the gas usage through different lenses.

Flamegraphs

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.

Cost Break-down

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).

Full Execution Trace

The final section of the gas report is the full execution trace of the transaction that looks like this:

execution & IO (gas unit, full trace)                        106.45206    100.00%
    intrinsic                                                3.94         3.70%
    0x1::code::publish_package_txn                           100.02706    93.96%
        move_loc                                             0.0024       0.00%
        move_loc                                             0.0024       0.00%
        call_generic                                         0.024        0.02%
        0x1::util::from_bytes<0x1::code::PackageMetadata>    0.1094       0.10%
        move_loc                                             0.0024       0.00%
        call                                                 0.064        0.06%
        0x1::code::publish_package                           99.82126     93.77%
            call                                             0.02         0.02%
            0x1::code::upgrade_policy_arbitrary              0.0076       0.01%
                ld_u8                                        0.0012       0.00%
                pack                                         0.0052       0.00%
                ret                                          0.0012       0.00%
            st_loc                                           0.0024       0.00%
            imm_borrow_loc                                   0.0012       0.00%
            imm_borrow_field                                 0.004        0.00%
            imm_borrow_field                                 0.004        0.00%
            read_ref                                         0.0072       0.01%
            imm_borrow_loc                                   0.0012       0.00%
            imm_borrow_field                                 0.004        0.00%
            read_ref                                         0.0072       0.01%
            gt                                               0.0032       0.00%
            br_false                                         0.0024       0.00%
            branch                                           0.0016       0.00%
            @17
...

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.

Future Plans

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 .

hello_blockchain package from move examples
here