mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-13 14:01:06 +00:00
Use Handlebars Template for Benchmark CLI Output (#7390)
* add_handlebar_template_to_benchmark - add benchmark-cli arg to take in a handlebar-template file * update to always use template * rewrite writer for handlebars * polish * pass cmd data * update docs * support custom filename output * Update command.rs * Create frame-weight-template.hbs * use a vector to maintain benchmark order * fix tests * Custom string serializer, remove feature flag * update docs * docs on public objects * small fix Co-authored-by: Ezadkiel Marbella <zadkiel.m@gmail.com>
This commit is contained in:
@@ -116,10 +116,15 @@ need to move into your node's binary folder. For example, with the Substrate rep
|
||||
you would test the Balances pallet's benchmarks:
|
||||
|
||||
```bash
|
||||
cd bin/node/cli
|
||||
cargo test -p pallet-balances --features runtime-benchmarks
|
||||
```
|
||||
|
||||
> NOTE: Substrate uses a virtual workspace which does not allow you to compile with feature flags.
|
||||
> ```
|
||||
> error: --features is not allowed in the root of a virtual workspace`
|
||||
> ```
|
||||
> To solve this, navigate to the folder of the node (`cd bin/node/cli`) or pallet (`cd frame/pallet`) and run the command there.
|
||||
|
||||
## Adding Benchmarks
|
||||
|
||||
The benchmarks included with each pallet are not automatically added to your node. To actually
|
||||
@@ -163,14 +168,14 @@ Then you can run a benchmark like so:
|
||||
|
||||
```bash
|
||||
./target/release/substrate benchmark \
|
||||
--chain dev \ # Configurable Chain Spec
|
||||
--execution=wasm \ # Always test with Wasm
|
||||
--wasm-execution=compiled \ # Always used `wasm-time`
|
||||
--pallet pallet_balances \ # Select the pallet
|
||||
--extrinsic transfer \ # Select the extrinsic
|
||||
--steps 50 \ # Number of samples across component ranges
|
||||
--repeat 20 \ # Number of times we repeat a benchmark
|
||||
--output \ # Output benchmark results into a Rust file
|
||||
--chain dev \ # Configurable Chain Spec
|
||||
--execution=wasm \ # Always test with Wasm
|
||||
--wasm-execution=compiled \ # Always used `wasm-time`
|
||||
--pallet pallet_balances \ # Select the pallet
|
||||
--extrinsic transfer \ # Select the extrinsic
|
||||
--steps 50 \ # Number of samples across component ranges
|
||||
--repeat 20 \ # Number of times we repeat a benchmark
|
||||
--output <path> \ # Output benchmark results into a folder or file
|
||||
```
|
||||
|
||||
This will output a file `pallet_name.rs` which implements the `WeightInfo` trait you should include
|
||||
@@ -179,6 +184,19 @@ implementation of the `WeightInfo` trait. This means that you will be able to us
|
||||
Substrate pallets while still keeping your network safe for your specific configuration and
|
||||
requirements.
|
||||
|
||||
The benchmarking CLI uses a Handlebars template to format the final output file. You can optionally
|
||||
pass the flag `--template` pointing to a custom template that can be used instead. Within the
|
||||
template, you have access to all the data provided by the `TemplateData` struct in the
|
||||
[benchmarking CLI writer](../../utils/frame/benchmarking-cli/src/writer.rs). You can find the
|
||||
default template used [here](../../utils/frame/benchmarking-cli/src/template.hbs).
|
||||
|
||||
There are some custom Handlebars helpers included with our output generation:
|
||||
|
||||
* `underscore`: Add an underscore to every 3rd character from the right of a string. Primarily to be
|
||||
used for delimiting large numbers.
|
||||
* `join`: Join an array of strings into a space-separated string for the template. Primarily to be
|
||||
used for joining all the arguments passed to the CLI.
|
||||
|
||||
To get a full list of available options when running benchmarks, run:
|
||||
|
||||
```bash
|
||||
|
||||
Reference in New Issue
Block a user