Skip to content

Commit

Permalink
feat: skeleton code for storage benchmarking
Browse files Browse the repository at this point in the history
  • Loading branch information
chungquantin committed Mar 10, 2025
1 parent d08a749 commit 4cf733c
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 3 deletions.
5 changes: 5 additions & 0 deletions crates/pop-cli/src/commands/bench/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ use clap::{Args, Subcommand};
use pallet::BenchmarkPallet;

mod pallet;
mod storage;

/// Arguments for benchmarking a project.
#[derive(Args)]
Expand All @@ -23,6 +24,9 @@ pub enum Command {
/// Benchmark the extrinsic weight of FRAME Pallets
#[clap(alias = "p")]
Pallet(BenchmarkPallet),
/// Benchmark the execution overhead per-block and per-extrinsic.
#[clap(alias = "s")]
Overhead(storage::BenchmarkStorage),
}

impl Command {
Expand All @@ -31,6 +35,7 @@ impl Command {
let mut cli = cli::Cli;
match args.command {
Command::Pallet(mut cmd) => cmd.execute(&mut cli).await,
Command::Overhead(mut cmd) => cmd.execute(&mut cli).await,
}
}
}
42 changes: 42 additions & 0 deletions crates/pop-cli/src/commands/bench/storage.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
use crate::{
cli::{self},
common::prompt::display_message,
};
use clap::Args;
use frame_benchmarking_cli::StorageCmd;
use pop_parachains::generate_storage_benchmarks;

#[derive(Args)]
pub struct BenchmarkStorage {
#[clap(flatten)]
pub command: StorageCmd,

/// If this is set to true, no interactive prompts will be shown.
#[clap(short = 'i', long)]
pub skip_all: bool,
}

impl BenchmarkStorage {
pub(crate) async fn execute(&mut self, cli: &mut impl cli::traits::Cli) -> anyhow::Result<()> {
cli.intro("Benchmarking the storage speed of a chain snapshot")?;

cli.warning("NOTE: this may take some time...")?;
cli.info("Benchmarking and generating weight file...")?;

if let Err(e) = self.run().await {
return display_message(&e.to_string(), false, cli);
}
display_message("Benchmark completed successfully!", true, cli)?;
Ok(())
}

async fn run(&self) -> anyhow::Result<()> {
generate_storage_benchmarks(StorageCmd {
shared_params: self.command.shared_params.clone(),
database_params: self.command.database_params.clone(),
pruning_params: self.command.pruning_params.clone(),
params: self.command.params.clone(),
})
.await
}
}
10 changes: 9 additions & 1 deletion crates/pop-parachains/src/bench/mod.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// SPDX-License-Identifier: GPL-3.0

use clap::Parser;
use frame_benchmarking_cli::PalletCmd;
use frame_benchmarking_cli::{PalletCmd, StorageCmd};
use sc_chain_spec::GenesisConfigBuilderRuntimeCaller;
use sp_runtime::traits::BlakeTwo256;
use std::{
Expand Down Expand Up @@ -98,6 +98,14 @@ pub fn generate_benchmarks(args: Vec<String>) -> anyhow::Result<()> {
.map_err(|e| anyhow::anyhow!("Failed to run benchmarking: {}", e))
}

/// Run command for storage benchmarking.
///
/// # Arguments
/// * `cmd` - Command to benchmark the storage speed of a chain snapshot.
pub async fn generate_storage_benchmarks(_cmd: StorageCmd) -> anyhow::Result<()> {
unimplemented!()
}

/// Loads a mapping of pallets and their associated extrinsics from the runtime binary.
///
/// # Arguments
Expand Down
5 changes: 3 additions & 2 deletions crates/pop-parachains/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,9 @@ mod up;
mod utils;

pub use bench::{
binary::*, generate_benchmarks, get_preset_names, get_runtime_path, load_pallet_extrinsics,
GenesisBuilderPolicy, PalletExtrinsicsRegistry, GENESIS_BUILDER_DEV_PRESET,
binary::*, generate_benchmarks, generate_storage_benchmarks, get_preset_names,
get_runtime_path, load_pallet_extrinsics, GenesisBuilderPolicy, PalletExtrinsicsRegistry,
GENESIS_BUILDER_DEV_PRESET,
};
pub use build::{
binary_path, build_parachain, build_project, export_wasm_file, generate_genesis_state_file,
Expand Down

0 comments on commit 4cf733c

Please sign in to comment.