Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add and announce local gas profiling via CLI and VM in Aptos.dev #7457

Merged
merged 9 commits into from
Mar 30, 2023
Original file line number Diff line number Diff line change
Expand Up @@ -867,7 +867,45 @@ FAILURE proving 1 modules from package `hello_prover` in 0.067s
```
In this case, see [Install the dependencies of Move Prover](install-aptos-cli#step-3-optional-install-the-dependencies-of-move-prover).

### Debug and print stack trace
### Profiling gas usage

This *experimental* feature lets you [profile gas usage](https://github.com/aptos-labs/aptos-core/tree/main/aptos-move/aptos-gas-profiling) in the Aptos virtual machine locally rather than [simulating transactions](../../concepts/gas-txn-fee.md#estimating-the-gas-units-via-simulation) at the [fullnode](https://fullnode.devnet.aptoslabs.com/v1/spec#/operations/simulate_transaction). You may also use it to visualize gas usage in the form of a flame graph.

clay-aptos marked this conversation as resolved.
Show resolved Hide resolved
Run the gas profiler by appending the `--profile-gas` option to the Aptos CLI `move publish`, `move run` or `move run-script` command, for example:
```bash
aptos move publish --profile-gas
```

And receive output resembling:
```bash
Compiling, may take a little while to download git dependencies...
BUILDING empty_fun
package size 427 bytes
Simulating transaction locally with the gas profiler...
This is still experimental so results may be inaccurate.
Execution & IO Gas flamegraph saved to gas-profiling/txn-69e19ee4-0x1-code-publish_package_txn.exec_io.svg
Storage fee flamegraph saved to gas-profiling/txn-69e19ee4-0x1-code-publish_package_txn.storage.svg
{
"Result": {
"transaction_hash": "0x69e19ee4cc89cb1f84ee21a46e6b281bd8696115aa332275eca38c4857818dfe",
"gas_used": 1007,
"gas_unit_price": 100,
"sender": "dbcbe741d003a7369d87ec8717afb5df425977106497052f96f4e236372f7dd5",
"success": true,
"version": 473269362,
"vm_status": "status EXECUTED of type Execution"
}
}
```

Find the flame graphs in the newly created `gas-profiling/` directory. To interact with a graph, open the file in a web browser.

Note these limitations of the experimental gas profiling feature:

* It may produce results that are different from the simulation.
* The graphs may contain errors, and the numbers may not add up to the total gas cost as shown in the transaction output.

### Debugging and printing stack trace

In this example, we will use `DebugDemo` in [debug-move-example](https://github.com/aptos-labs/aptos-core/tree/main/crates/aptos/debug-move-example).

Expand Down
2 changes: 1 addition & 1 deletion developer-docs-site/docs/concepts/gas-txn-fee.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ In a transaction, for example, transaction A, you are transferring 1000 coins fr

## Estimating the gas units via simulation

The gas used for a transaction can be estimated by simulating the transaction. When simulating the transaction, the simulation results represent the **exact** amount that is needed at the **exact** state of the blockchain at the time of simulation. These gas units used may change based on the state of the chain. For this reason, any amount coming out of the simulation is only an estimate, and when setting the max gas amount, it should include an appropriate amount of headroom based upon your comfort-level and historical behaviors. Setting the max gas amount too low will result in the transaction aborting and the account being charged for whatever gas was consumed.
The gas used for a transaction can be estimated by simulating the transaction on chain as described here or locally via the [gas profiling](../cli-tools/aptos-cli-tool/use-aptos-cli.md#profiling-gas-use) feature of the Aptos CLI. The results of the simulated transaction represent the **exact** amount that is needed at the **exact** state of the blockchain at the time of the simulation. These gas units used may change based on the state of the chain. For this reason, any amount coming out of the simulation is only an estimate, and when setting the max gas amount, it should include an appropriate amount of headroom based upon your comfort-level and historical behaviors. Setting the max gas amount too low will result in the transaction aborting and the account being charged for whatever gas was consumed.

Transactions can be simulated with the [`SimulateTransaction`](https://fullnode.devnet.aptoslabs.com/v1/spec#/operations/simulate_transaction) API. This API will run the exact transaction that you plan to run.

Expand Down
1 change: 1 addition & 0 deletions developer-docs-site/docs/guides/move-guides/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ To efficiently write smart contracts in Aptos, we recommend you first:

Start here to learn how the Move language works on the Aptos blockchain.

- ### [Aptos CLI Move commands](../../cli-tools/aptos-cli-tool/use-aptos-cli.md#move-examples)
- ### [Aptos Move Book](book/SUMMARY.md)
- ### [Move on Aptos](./move-on-aptos.md)
- ### [Move Primitives Tutorial](https://github.com/aptos-labs/aptos-core/tree/main/aptos-move/move-examples/move-tutorial)
Expand Down
8 changes: 6 additions & 2 deletions developer-docs-site/docs/whats-new-in-docs.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,17 @@ slug: "whats-new-in-docs"

This page shows the key updates to the developer documentation on this site. Note, this site is built from the `main` upstream branch of GitHub and so therefore reflects the latest changes to Aptos. If you have checked out [another branch](https://github.com/aptos-labs/aptos-core/branches) to use a [specific network](guides/system-integrators-guide.md#choose-a-network), the code may not yet have all of the features described here.

## 28 March 2023

- Offered an experimental feature to [profile gas usage locally](./cli-tools/aptos-cli-tool/use-aptos-cli.md#profiling-gas-use) via the Aptos CLI that not only simulates use but also generates flame graphs for visualizing gas usage.

## 27 March 2023

- Described how to [Use the Remix IDE Plugin](./community/contributions/remix-ide-plugin.md) to deploy and run Move modules on the Remix IDE, a graphical interface for developing Move modules written by [0xhsy](https://github.com/0xhsy).
- Described how to [Use the Remix IDE Plugin](./community/contributions/remix-ide-plugin.md) to deploy and run Move modules on the Remix IDE, a graphical interface for developing Move modules written by [0xhsy](https://github.com/0xhsy) of [WELLDONE Studio](https://docs.welldonestudio.io/).

## 24 March 2023

- Added instructions to [Integrate with Aptos Names Service UI Package](./guides/aptos-name-service-connector.md) that offers developers a customizable button and modal to enable users to search for and mint Aptos names directly from their website.
- Added instructions to [Integrate with Aptos Names Service](./guides/aptos-name-service-connector.md) that offers developers a customizable button and modal to enable users to search for and mint Aptos names directly from their website.

## 23 March 2023

Expand Down