Skip to content
Snippets Groups Projects
Unverified Commit 18309c93 authored by Shaopeng Wang's avatar Shaopeng Wang Committed by GitHub
Browse files

Update benchmarking macro. (#259)

parent 0cb94a5a
No related branches found
No related tags found
No related merge requests found
...@@ -19,6 +19,9 @@ frame-support = { version = "2.0.0-rc6", default-features = false } ...@@ -19,6 +19,9 @@ frame-support = { version = "2.0.0-rc6", default-features = false }
frame-system = { version = "2.0.0-rc6", default-features = false } frame-system = { version = "2.0.0-rc6", default-features = false }
frame-benchmarking = { version = "2.0.0-rc6", default-features = false } frame-benchmarking = { version = "2.0.0-rc6", default-features = false }
[dev-dependencies]
hex-literal = "0.2.1"
[features] [features]
default = [ "std" ] default = [ "std" ]
std = [ std = [
......
...@@ -7,6 +7,7 @@ mod tests; ...@@ -7,6 +7,7 @@ mod tests;
pub use frame_benchmarking::{ pub use frame_benchmarking::{
benchmarking, BenchmarkBatch, BenchmarkParameter, BenchmarkResults, Benchmarking, BenchmarkingSetup, benchmarking, BenchmarkBatch, BenchmarkParameter, BenchmarkResults, Benchmarking, BenchmarkingSetup,
TrackedStorageKey,
}; };
#[cfg(feature = "std")] #[cfg(feature = "std")]
pub use frame_benchmarking::{Analysis, BenchmarkSelector}; pub use frame_benchmarking::{Analysis, BenchmarkSelector};
...@@ -718,7 +719,7 @@ macro_rules! impl_benchmark { ...@@ -718,7 +719,7 @@ macro_rules! impl_benchmark {
highest_range_values: &[u32], highest_range_values: &[u32],
steps: &[u32], steps: &[u32],
repeat: u32, repeat: u32,
whitelist: &[Vec<u8>] whitelist: &[$crate::TrackedStorageKey]
) -> Result<Vec<$crate::BenchmarkResults>, &'static str> { ) -> Result<Vec<$crate::BenchmarkResults>, &'static str> {
// Map the input to the selected benchmark. // Map the input to the selected benchmark.
let extrinsic = sp_std::str::from_utf8(extrinsic) let extrinsic = sp_std::str::from_utf8(extrinsic)
...@@ -757,8 +758,8 @@ macro_rules! impl_benchmark { ...@@ -757,8 +758,8 @@ macro_rules! impl_benchmark {
>::instance(&selected_benchmark, &c)?; >::instance(&selected_benchmark, &c)?;
// Set the block number to at least 1 so events are deposited. // Set the block number to at least 1 so events are deposited.
if $crate::Zero::is_zero(&frame_system::Module::<T>::block_number()) { if $crate::Zero::is_zero(&frame_system::Module::<$runtime>::block_number()) {
frame_system::Module::<T>::set_block_number(1u8.into()); frame_system::Module::<$runtime>::set_block_number(1u8.into());
} }
// Commit the externalities to the database, flushing the DB cache. // Commit the externalities to the database, flushing the DB cache.
...@@ -937,35 +938,42 @@ macro_rules! impl_benchmark_test { ...@@ -937,35 +938,42 @@ macro_rules! impl_benchmark_test {
/// let params = (&pallet, &benchmark, &lowest_range_values, &highest_range_values, &steps, repeat, &whitelist); /// let params = (&pallet, &benchmark, &lowest_range_values, &highest_range_values, &steps, repeat, &whitelist);
/// ``` /// ```
/// ///
/// The `whitelist` is a `Vec<Vec<u8>>` of storage keys that you would like to /// The `whitelist` is a parameter you pass to control the DB read/write
/// skip for DB tracking. For example: /// tracking. We use a vector of [TrackedStorageKey], which is a simple struct
/// used to set if a key has been read or written to.
/// ///
/// ```ignore /// For values that should be skipped entirely, we can just pass `key.into()`.
/// let whitelist: Vec<Vec<u8>> = vec![ /// For example:
///
/// ```
/// use frame_benchmarking::TrackedStorageKey;
/// use hex_literal;
/// let whitelist: Vec<TrackedStorageKey> = vec![
/// // Block Number /// // Block Number
/// hex_literal::hex!("26aa394eea5630e07c48ae0c9558cef702a5c1b19ab7a04f536c519aca4983ac").to_vec(), /// hex_literal::hex!("26aa394eea5630e07c48ae0c9558cef702a5c1b19ab7a04f536c519aca4983ac").to_vec().into(),
/// // Total Issuance /// // Total Issuance
/// hex_literal::hex!("c2261276cc9d1f8598ea4b6a74b15c2f57c875e4cff74148e4628f264b974c80").to_vec(), /// hex_literal::hex!("c2261276cc9d1f8598ea4b6a74b15c2f57c875e4cff74148e4628f264b974c80").to_vec().into(),
/// // Execution Phase /// // Execution Phase
/// hex_literal::hex!("26aa394eea5630e07c48ae0c9558cef7ff553b5a9862a516939d82b3d3d8661a").to_vec(), /// hex_literal::hex!("26aa394eea5630e07c48ae0c9558cef7ff553b5a9862a516939d82b3d3d8661a").to_vec().into(),
/// // Event Count /// // Event Count
/// hex_literal::hex!("26aa394eea5630e07c48ae0c9558cef70a98fdbe9ce6c55837576c60c7af3850").to_vec(), /// hex_literal::hex!("26aa394eea5630e07c48ae0c9558cef70a98fdbe9ce6c55837576c60c7af3850").to_vec().into(),
/// ]; /// ];
/// ```
/// ///
/// Then define a mutable local variable to hold your `BenchmarkBatch` object: /// Then define a mutable local variable to hold your `BenchmarkBatch` object:
/// ```ignore /// ```ignore
/// let mut batches = Vec::<BenchmarkBatch>::new(); /// let mut batches = Vec::<BenchmarkBatch>::new();
/// ```` /// ````
/// ///
/// Then add the pallets you want to benchmark to this object, using their crate name and generated /// Then add the pallets you want to benchmark to this object, using their crate
/// module struct: /// name and generated module struct:
/// ```ignore /// ```ignore
/// add_benchmark!(params, batches, pallet_balances, Balances); /// add_benchmark!(params, batches, pallet_balances, Balances);
/// add_benchmark!(params, batches, pallet_session, SessionBench::<Runtime>); /// add_benchmark!(params, batches, pallet_session, SessionBench::<Runtime>);
/// add_benchmark!(params, batches, frame_system, SystemBench::<Runtime>); /// add_benchmark!(params, batches, frame_system, SystemBench::<Runtime>);
/// ... /// ...
/// ``` /// ```
/// ///
/// At the end of `dispatch_benchmark`, you should return this batches object. /// At the end of `dispatch_benchmark`, you should return this batches object.
#[macro_export] #[macro_export]
macro_rules! add_benchmark { macro_rules! add_benchmark {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment