frame_benchmarking_cli/
lib.rs1mod block;
21mod extrinsic;
22mod machine;
23mod overhead;
24mod pallet;
25mod shared;
26mod storage;
27
28pub use block::BlockCmd;
29pub use extrinsic::{ExtrinsicBuilder, ExtrinsicCmd, ExtrinsicFactory};
30pub use machine::{MachineCmd, SUBSTRATE_REFERENCE_HARDWARE};
31pub use overhead::{
32 remark_builder::{DynamicRemarkBuilder, SubstrateRemarkBuilder},
33 OpaqueBlock, OverheadCmd,
34};
35pub use pallet::PalletCmd;
36pub use sc_service::BasePath;
37pub use storage::StorageCmd;
38
39use sc_cli::{CliConfiguration, DatabaseParams, ImportParams, PruningParams, Result, SharedParams};
40
41#[derive(Debug, clap::Subcommand)]
45pub enum BenchmarkCmd {
46 Pallet(PalletCmd),
47 Storage(StorageCmd),
48 Overhead(OverheadCmd),
49 Block(BlockCmd),
50 Machine(MachineCmd),
51 Extrinsic(ExtrinsicCmd),
52}
53
54macro_rules! unwrap_cmd {
56 {
57 $self:expr,
58 $cmd:ident,
59 $code:expr
60 } => {
61 match $self {
62 BenchmarkCmd::Pallet($cmd) => $code,
63 BenchmarkCmd::Storage($cmd) => $code,
64 BenchmarkCmd::Overhead($cmd) => $code,
65 BenchmarkCmd::Block($cmd) => $code,
66 BenchmarkCmd::Machine($cmd) => $code,
67 BenchmarkCmd::Extrinsic($cmd) => $code,
68 }
69 }
70}
71
72impl CliConfiguration for BenchmarkCmd {
76 fn shared_params(&self) -> &SharedParams {
77 unwrap_cmd! {
78 self, cmd, cmd.shared_params()
79 }
80 }
81
82 fn import_params(&self) -> Option<&ImportParams> {
83 unwrap_cmd! {
84 self, cmd, cmd.import_params()
85 }
86 }
87
88 fn database_params(&self) -> Option<&DatabaseParams> {
89 unwrap_cmd! {
90 self, cmd, cmd.database_params()
91 }
92 }
93
94 fn base_path(&self) -> Result<Option<BasePath>> {
95 let inner = unwrap_cmd! {
96 self, cmd, cmd.base_path()
97 };
98
99 match inner {
102 Ok(None) => Some(BasePath::new_temp_dir()).transpose().map_err(|e| e.into()),
103 e => e,
104 }
105 }
106
107 fn pruning_params(&self) -> Option<&PruningParams> {
108 unwrap_cmd! {
109 self, cmd, cmd.pruning_params()
110 }
111 }
112
113 fn trie_cache_maximum_size(&self) -> Result<Option<usize>> {
114 unwrap_cmd! {
115 self, cmd, cmd.trie_cache_maximum_size()
116 }
117 }
118
119 fn chain_id(&self, is_dev: bool) -> Result<String> {
120 unwrap_cmd! {
121 self, cmd, cmd.chain_id(is_dev)
122 }
123 }
124}