Skip to main content

pezframe_benchmarking_cli/
lib.rs

1// This file is part of Bizinikiwi.
2
3// Copyright (C) Parity Technologies (UK) Ltd. and Dijital Kurdistan Tech Institute
4// SPDX-License-Identifier: Apache-2.0
5
6// Licensed under the Apache License, Version 2.0 (the "License");
7// you may not use this file except in compliance with the License.
8// You may obtain a copy of the License at
9//
10// 	http://www.apache.org/licenses/LICENSE-2.0
11//
12// Unless required by applicable law or agreed to in writing, software
13// distributed under the License is distributed on an "AS IS" BASIS,
14// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15// See the License for the specific language governing permissions and
16// limitations under the License.
17
18//! Contains the root [`BenchmarkCmd`] command and exports its sub-commands.
19
20mod block;
21mod extrinsic;
22mod machine;
23mod overhead;
24mod pezpallet;
25mod shared;
26#[cfg(feature = "storage-benchmark")]
27mod storage;
28
29pub use block::BlockCmd;
30pub use extrinsic::{ExtrinsicBuilder, ExtrinsicCmd, ExtrinsicFactory};
31pub use machine::{MachineCmd, BIZINIKIWI_REFERENCE_HARDWARE};
32pub use overhead::{
33	remark_builder::{BizinikiwiRemarkBuilder, DynamicRemarkBuilder},
34	OpaqueBlock, OverheadCmd,
35};
36pub use pezpallet::PalletCmd;
37pub use pezsc_service::BasePath;
38#[cfg(feature = "storage-benchmark")]
39pub use storage::StorageCmd;
40
41use pezsc_cli::{
42	CliConfiguration, DatabaseParams, ImportParams, PruningParams, Result, SharedParams,
43};
44
45/// The root `benchmarking` command.
46///
47/// Has no effect itself besides printing a help menu of the sub-commands.
48#[derive(Debug, clap::Subcommand)]
49pub enum BenchmarkCmd {
50	Pezpallet(PalletCmd),
51	#[cfg(feature = "storage-benchmark")]
52	Storage(StorageCmd),
53	Overhead(OverheadCmd),
54	Block(BlockCmd),
55	Machine(MachineCmd),
56	Extrinsic(ExtrinsicCmd),
57}
58
59/// Unwraps a [`BenchmarkCmd`] into its concrete sub-command.
60macro_rules! unwrap_cmd {
61	{
62		$self:expr,
63		$cmd:ident,
64		$code:expr
65	} => {
66		match $self {
67			BenchmarkCmd::Pezpallet($cmd) => $code,
68			#[cfg(feature = "storage-benchmark")]
69			BenchmarkCmd::Storage($cmd) => $code,
70			BenchmarkCmd::Overhead($cmd) => $code,
71			BenchmarkCmd::Block($cmd) => $code,
72			BenchmarkCmd::Machine($cmd) => $code,
73			BenchmarkCmd::Extrinsic($cmd) => $code,
74		}
75	}
76}
77
78/// Forward the [`CliConfiguration`] trait implementation.
79///
80/// Each time a sub-command exposes a new config option, it must be added here.
81impl CliConfiguration for BenchmarkCmd {
82	fn shared_params(&self) -> &SharedParams {
83		unwrap_cmd! {
84			self, cmd, cmd.shared_params()
85		}
86	}
87
88	fn import_params(&self) -> Option<&ImportParams> {
89		unwrap_cmd! {
90			self, cmd, cmd.import_params()
91		}
92	}
93
94	fn database_params(&self) -> Option<&DatabaseParams> {
95		unwrap_cmd! {
96			self, cmd, cmd.database_params()
97		}
98	}
99
100	fn base_path(&self) -> Result<Option<BasePath>> {
101		let inner = unwrap_cmd! {
102			self, cmd, cmd.base_path()
103		};
104
105		// If the base path was not provided, benchmark command shall use temporary path. Otherwise
106		// we may end up using shared path, which may be inappropriate for benchmarking.
107		match inner {
108			Ok(None) => Some(BasePath::new_temp_dir()).transpose().map_err(|e| e.into()),
109			e => e,
110		}
111	}
112
113	fn pruning_params(&self) -> Option<&PruningParams> {
114		unwrap_cmd! {
115			self, cmd, cmd.pruning_params()
116		}
117	}
118
119	fn trie_cache_maximum_size(&self) -> Result<Option<usize>> {
120		unwrap_cmd! {
121			self, cmd, cmd.trie_cache_maximum_size()
122		}
123	}
124
125	fn chain_id(&self, is_dev: bool) -> Result<String> {
126		unwrap_cmd! {
127			self, cmd, cmd.chain_id(is_dev)
128		}
129	}
130}