Skip to content
Snippets Groups Projects
lib.rs 34.2 KiB
Newer Older
  • Learn to ignore specific revisions
  • 					for (_, (name, low, high)) in components.iter().enumerate() {
    						// Test only the low and high value, assuming values in the middle won't break
    						for component_value in vec![low, high] {
    							// Select the max value for all the other components.
    							let c: Vec<($crate::BenchmarkParameter, u32)> = components.iter()
    								.enumerate()
    								.map(|(_, (n, _, h))|
    									if n == name {
    										(*n, *component_value)
    									} else {
    										(*n, *h)
    									}
    								)
    								.collect();
    
    							// Set up the verification state
    							let closure_to_verify = <SelectedBenchmark as $crate::BenchmarkingSetupInstance<$runtime, _>>::verify(&selected_benchmark, &c)?;
    
    							// Set the block number to at least 1 so events are deposited.
    							if $crate::Zero::is_zero(&frame_system::Module::<$runtime>::block_number()) {
    								frame_system::Module::<$runtime>::set_block_number(1.into());
    							}
    
    							// Run verification
    							closure_to_verify()?;
    
    							// Reset the state
    							$crate::benchmarking::wipe_db();
    						}
    					}
    					Ok(())
    				}
    			}
    		)*
    	};
    }
    
    /// This macro adds pallet benchmarks to a `Vec<BenchmarkBatch>` object.
    ///
    /// First create an object that holds in the input parameters for the benchmark:
    ///
    /// ```ignore
    /// let params = (&pallet, &benchmark, &lowest_range_values, &highest_range_values, &steps, repeat);
    /// ```
    ///
    /// Then define a mutable local variable to hold your `BenchmarkBatch` object:
    ///
    /// ```ignore
    /// let mut batches = Vec::<BenchmarkBatch>::new();
    /// ````
    ///
    /// Then add the pallets you want to benchmark to this object, including the string
    /// you want to use target a particular pallet:
    ///
    /// ```ignore
    /// add_benchmark!(params, batches, b"balances", Balances);
    /// add_benchmark!(params, batches, b"identity", Identity);
    /// add_benchmark!(params, batches, b"session", SessionBench::<Runtime>);
    /// ...
    /// ```
    ///
    /// At the end of `dispatch_benchmark`, you should return this batches object.
    #[macro_export]
    macro_rules! add_benchmark {
    	( $params:ident, $batches:ident, $name:literal, $( $location:tt )* ) => (
    		let (pallet, benchmark, lowest_range_values, highest_range_values, steps, repeat) = $params;
    		if &pallet[..] == &$name[..] || &pallet[..] == &b"*"[..] {
    			if &pallet[..] == &b"*"[..] || &benchmark[..] == &b"*"[..] {
    				for benchmark in $( $location )*::Benchmark::benchmarks().into_iter() {
    					$batches.push($crate::BenchmarkBatch {
    						results: $( $location )*::Benchmark::run_benchmark(
    							benchmark,
    							&lowest_range_values[..],
    							&highest_range_values[..],
    							&steps[..],
    							repeat,
    						)?,
    						pallet: $name.to_vec(),
    						benchmark: benchmark.to_vec(),
    					});
    				}
    			} else {
    				$batches.push($crate::BenchmarkBatch {
    					results: $( $location )*::Benchmark::run_benchmark(
    						&benchmark[..],
    						&lowest_range_values[..],
    						&highest_range_values[..],
    						&steps[..],
    						repeat,
    					)?,
    					pallet: $name.to_vec(),
    					benchmark: benchmark.clone(),
    				});
    			}
    		}
    	)
    }