Skip to content
This repository was archived by the owner on Nov 15, 2023. It is now read-only.

Commit 39f60e0

Browse files
committed
Update from parent 'origin/master' (conflicts)
Commit: 6b27391 Parent branch: origin/master Forked at: 2afecf8
2 parents aaf4b48 + 6b27391 commit 39f60e0

File tree

5 files changed

+81
-16
lines changed

5 files changed

+81
-16
lines changed

bin/node/runtime/src/lib.rs

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -820,15 +820,35 @@ impl_runtime_apis! {
820820
fn dispatch_benchmark(
821821
module: Vec<u8>,
822822
extrinsic: Vec<u8>,
823+
lowest_range_values: Vec<u32>,
824+
highest_range_values: Vec<u32>,
823825
steps: Vec<u32>,
824826
repeat: u32,
825827
) -> Result<Vec<frame_benchmarking::BenchmarkResults>, RuntimeString> {
826828
use frame_benchmarking::Benchmarking;
827829

828830
let result = match module.as_slice() {
829-
b"pallet-balances" | b"balances" => Balances::run_benchmark(extrinsic, steps, repeat),
830-
b"pallet-identity" | b"identity" => Identity::run_benchmark(extrinsic, steps, repeat),
831-
b"pallet-timestamp" | b"timestamp" => Timestamp::run_benchmark(extrinsic, steps, repeat),
831+
b"pallet-balances" | b"balances" => Balances::run_benchmark(
832+
extrinsic,
833+
lowest_range_values,
834+
highest_range_values,
835+
steps,
836+
repeat,
837+
),
838+
b"pallet-identity" | b"identity" => Identity::run_benchmark(
839+
extrinsic,
840+
lowest_range_values,
841+
highest_range_values,
842+
steps,
843+
repeat,
844+
),
845+
b"pallet-timestamp" | b"timestamp" => Timestamp::run_benchmark(
846+
extrinsic,
847+
lowest_range_values,
848+
highest_range_values,
849+
steps,
850+
repeat,
851+
),
832852
_ => Err("Benchmark not found for this pallet."),
833853
};
834854

frame/benchmarking/src/lib.rs

Lines changed: 28 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,13 @@ macro_rules! impl_benchmark {
140140
$( $name:ident ),*
141141
) => {
142142
impl<T: Trait> $crate::Benchmarking<$crate::BenchmarkResults> for Module<T> {
143-
fn run_benchmark(extrinsic: Vec<u8>, steps: Vec<u32>, repeat: u32) -> Result<Vec<$crate::BenchmarkResults>, &'static str> {
143+
fn run_benchmark(
144+
extrinsic: Vec<u8>,
145+
lowest_range_values: Vec<u32>,
146+
highest_range_values: Vec<u32>,
147+
steps: Vec<u32>,
148+
repeat: u32,
149+
) -> Result<Vec<$crate::BenchmarkResults>, &'static str> {
144150
// Map the input to the selected benchmark.
145151
let extrinsic = sp_std::str::from_utf8(extrinsic.as_slice())
146152
.map_err(|_| "Could not find extrinsic")?;
@@ -157,26 +163,38 @@ macro_rules! impl_benchmark {
157163
let mut results: Vec<$crate::BenchmarkResults> = Vec::new();
158164

159165
// Default number of steps for a component.
160-
let mut prev_steps = &10;
166+
let mut prev_steps = 10;
161167

162168
// Select the component we will be benchmarking. Each component will be benchmarked.
163169
for (idx, (name, low, high)) in components.iter().enumerate() {
164170
// Get the number of steps for this component.
165-
let steps = steps.get(idx).unwrap_or(&prev_steps);
171+
let steps = steps.get(idx).cloned().unwrap_or(prev_steps);
166172
prev_steps = steps;
167173

174+
let lowest = lowest_range_values.get(idx).cloned().unwrap_or(*low);
175+
let highest = highest_range_values.get(idx).cloned().unwrap_or(*high);
176+
177+
let diff = highest - lowest;
178+
168179
// Create up to `STEPS` steps for that component between high and low.
169-
let step_size = ((high - low) / steps).max(1);
170-
let num_of_steps = (high - low) / step_size + 1;
180+
let step_size = (diff / steps).max(1);
181+
let num_of_steps = diff / step_size + 1;
182+
171183
for s in 0..num_of_steps {
172184
// This is the value we will be testing for component `name`
173-
let component_value = low + step_size * s;
185+
let component_value = lowest + step_size * s;
174186

175-
// Select the mid value for all the other components.
187+
// Select the max value for all the other components.
176188
let c: Vec<($crate::BenchmarkParameter, u32)> = components.iter()
177-
.map(|(n, l, h)|
178-
(*n, if n == name { component_value } else { *h })
179-
).collect();
189+
.enumerate()
190+
.map(|(idx, (n, l, h))|
191+
if n == name {
192+
(*n, component_value)
193+
} else {
194+
(*n, *highest_range_values.get(idx).unwrap_or(h))
195+
}
196+
)
197+
.collect();
180198

181199
// Run the benchmark `repeat` times.
182200
for _ in 0..repeat {

frame/benchmarking/src/utils.rs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@ sp_api::decl_runtime_apis! {
4141
fn dispatch_benchmark(
4242
module: Vec<u8>,
4343
extrinsic: Vec<u8>,
44+
lowest_range_values: Vec<u32>,
45+
highest_range_values: Vec<u32>,
4446
steps: Vec<u32>,
4547
repeat: u32,
4648
) -> Result<Vec<BenchmarkResults>, RuntimeString>;
@@ -78,8 +80,16 @@ pub trait Benchmarking<T> {
7880
/// Parameters
7981
/// - `extrinsic`: The name of extrinsic function you want to benchmark encoded as bytes.
8082
/// - `steps`: The number of sample points you want to take across the range of parameters.
83+
/// - `lowest_range_values`: The lowest number for each range of parameters.
84+
/// - `highest_range_values`: The highest number for each range of parameters.
8185
/// - `repeat`: The number of times you want to repeat a benchmark.
82-
fn run_benchmark(extrinsic: Vec<u8>, steps: Vec<u32>, repeat: u32) -> Result<Vec<T>, &'static str>;
86+
fn run_benchmark(
87+
extrinsic: Vec<u8>,
88+
lowest_range_values: Vec<u32>,
89+
highest_range_values: Vec<u32>,
90+
steps: Vec<u32>,
91+
repeat: u32,
92+
) -> Result<Vec<T>, &'static str>;
8393
}
8494

8595
/// The required setup for creating a benchmark.

utils/frame/benchmarking-cli/src/command.rs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,14 @@ impl BenchmarkCmd {
5959
&mut changes,
6060
&executor,
6161
"Benchmark_dispatch_benchmark",
62-
&(&self.pallet, &self.extrinsic, self.steps.clone(), self.repeat).encode(),
62+
&(
63+
&self.pallet,
64+
&self.extrinsic,
65+
self.lowest_range_values.clone(),
66+
self.highest_range_values.clone(),
67+
self.steps.clone(),
68+
self.repeat,
69+
).encode(),
6370
Default::default(),
6471
)
6572
.execute(strategy.into())
@@ -72,9 +79,11 @@ impl BenchmarkCmd {
7279
Ok(results) => {
7380
// Print benchmark metadata
7481
println!(
75-
"Pallet: {:?}, Extrinsic: {:?}, Steps: {:?}, Repeat: {:?}",
82+
"Pallet: {:?}, Extrinsic: {:?}, Lowest values: {:?}, Highest values: {:?}, Steps: {:?}, Repeat: {:?}",
7683
self.pallet,
7784
self.extrinsic,
85+
self.lowest_range_values,
86+
self.highest_range_values,
7887
self.steps,
7988
self.repeat,
8089
);

utils/frame/benchmarking-cli/src/lib.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,14 @@ pub struct BenchmarkCmd {
3434
#[structopt(short, long, use_delimiter = true)]
3535
pub steps: Vec<u32>,
3636

37+
/// Indicates lowest values for each of the component ranges.
38+
#[structopt(long, use_delimiter = true)]
39+
pub lowest_range_values: Vec<u32>,
40+
41+
/// Indicates highest values for each of the component ranges.
42+
#[structopt(long, use_delimiter = true)]
43+
pub highest_range_values: Vec<u32>,
44+
3745
/// Select how many repetitions of this benchmark should run.
3846
#[structopt(short, long, default_value = "1")]
3947
pub repeat: u32,

0 commit comments

Comments
 (0)