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 gasProfile() method to run Move gas profiling #584

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,15 @@ All notable changes to the Aptos TypeScript SDK will be captured in this file. T

# Unreleased

- Add `gasProfile` function to `Move` class to allow for gas profiling of Aptos Move functions

# 1.33.0 (2024-11-13)

- Allow optional provision of public keys in transaction simulation
- Update the multisig v2 example to demonstrate a new way to pre-check a multisig payload before it is created on-chain

# 1.32.1 (2024-11-11)

- Add support for Firebase issuers in the `updateFederatedKeylessJwkSetTransaction` function
- [`Breaking`] Revert new `scriptComposer` api in transactionSubmission api to allower SDK callers to invoke multiple Move functions inside a same transaction and compose the calls dynamically.

Expand Down
15 changes: 15 additions & 0 deletions examples/typescript/local_node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,18 @@ async function stopLocalNode() {
}
}

async function profileGas() {
try {
console.log("running gas profiling");
await move.gasProfile({
network: "mainnet",
transactionId: "1702334345",
});
} catch (error) {
console.error("error running gas profiling", error);
}
}

async function run() {
// start the localnet
await runLocalNode();
Expand All @@ -182,6 +194,9 @@ async function run() {

// stop the localnet
await stopLocalNode();

// run gas profiling
await profileGas();
}

run();
16 changes: 16 additions & 0 deletions src/cli/move.ts
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,22 @@ export class Move {
return this.runCommand(cliArgs, showStdout);
}

async gasProfile(args: {
network: string;
transactionId: string;
extraArguments?: Array<string>;
showStdout?: boolean;
}): Promise<{ output: string; result?: any }> {
const { network, transactionId, extraArguments, showStdout } = args;
const cliArgs = ["aptos", "move", "replay", "--profile-gas", "--network", network, "--txn-id", transactionId];
Comment on lines +313 to +320
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh interesting didn't know it works on historical transactions.

Maybe rename it to gasProfileExistingTransaction or something like that?

Or just leave room in this function to take a different input that also allows gas profiling new transactions.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh interesting didn't know it works on historical transactions.

Maybe rename it to gasProfileExistingTransaction or something like that?

Or just leave room in this function to take a different input that also allows gas profiling new transactions.

hmm wdym? the command profiling a committed transaction

aptos move replay --profile-gas --help
Replay a comitted transaction using a local VM

Usage: aptos move replay [OPTIONS] --network <NETWORK> --txn-id <TXN_ID>


if (extraArguments) {
cliArgs.push(...extraArguments);
}

return this.runCommand(cliArgs, showStdout);
}

/**
* Run a command with the specified arguments and return the output.
*
Expand Down
Loading