Skip to content
This repository was archived by the owner on Nov 15, 2023. It is now read-only.
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
c13b500
extract repeat out of benchmark
shawntabrizi Jul 19, 2021
c309539
remove r
shawntabrizi Jul 19, 2021
e909b9d
unused
shawntabrizi Jul 19, 2021
6e70861
cargo run --quiet --release --features=runtime-benchmarks --manifest-…
Jul 19, 2021
30e9e5f
cargo run --quiet --release --features=runtime-benchmarks --manifest-…
Jul 19, 2021
66c1dbb
cargo run --quiet --release --features=runtime-benchmarks --manifest-…
Jul 19, 2021
cd01587
use linked map to keep order
shawntabrizi Jul 21, 2021
8c42f39
Merge branch 'master' of https://github.com/paritytech/substrate into…
Jul 21, 2021
d0184a0
cargo run --quiet --release --features=runtime-benchmarks --manifest-…
Jul 21, 2021
31810d9
Delete pallet_balances.rs
shawntabrizi Jul 21, 2021
1ab0066
Delete out
shawntabrizi Jul 21, 2021
257fbbb
cargo run --quiet --release --features=runtime-benchmarks --manifest-…
Jul 21, 2021
ca5cdc5
steps and repeat to tuple (current_*, total_*)
shawntabrizi Jul 22, 2021
f42d16f
idea for list command
shawntabrizi Jul 22, 2021
8a0ed37
Merge branch 'master' into shawntabrizi-refactor-benchmarks
shawntabrizi Jul 29, 2021
81a7e77
fmt
shawntabrizi Jul 29, 2021
9467179
use benchmark list in cli
shawntabrizi Jul 30, 2021
e760e3e
handle steps in cli
shawntabrizi Jul 30, 2021
4d28ebe
Move client consensus parts out of primitives and into client/consens…
gilescope Jul 30, 2021
630ab7a
move log update to cli
shawntabrizi Jul 30, 2021
d4b3f9d
fmt
shawntabrizi Jul 30, 2021
39bd8c0
remove old todo
shawntabrizi Jul 30, 2021
fb8fc17
line width
shawntabrizi Jul 30, 2021
0f713c7
Merge branch 'master' of https://github.com/paritytech/substrate into…
Jul 30, 2021
5627eba
cargo run --quiet --release --features=runtime-benchmarks --manifest-…
Jul 30, 2021
ced0514
benchmark metadata function
shawntabrizi Jul 30, 2021
1945af5
don't need this warm up
shawntabrizi Jul 30, 2021
b243b02
cargo run --quiet --release --features=runtime-benchmarks --manifest-…
Jul 30, 2021
14a4342
fix warnings
shawntabrizi Jul 30, 2021
ee3b2f7
fix node-template
shawntabrizi Jul 30, 2021
0ae6038
fix
shawntabrizi Jul 30, 2021
90c495c
Try merge shawntabrizi-refactor-benchmarks
emostov Jul 30, 2021
83289aa
save
emostov Jul 30, 2021
44875c5
cargo run --quiet --release --features=runtime-benchmarks --manifest-…
Jul 30, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
steps and repeat to tuple (current_*, total_*)
  • Loading branch information
shawntabrizi committed Jul 22, 2021
commit ca5cdc5092ecf99f5fefb856ee349e36d59464d1
29 changes: 16 additions & 13 deletions frame/benchmarking/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -702,7 +702,8 @@ macro_rules! impl_benchmark {
extrinsic: &[u8],
lowest_range_values: &[u32],
highest_range_values: &[u32],
steps: &[u32],
steps: (u32, u32),
repeat: (u32, u32),
whitelist: &[$crate::TrackedStorageKey],
verify: bool,
) -> Result<$crate::Vec<$crate::BenchmarkResults>, &'static str> {
Expand Down Expand Up @@ -733,8 +734,6 @@ macro_rules! impl_benchmark {
>::components(&selected_benchmark);

let mut progress = $crate::benchmarking::current_time();
// Default number of steps for a component.
let mut prev_steps = 10;

let mut do_benchmark = |
c: &[($crate::BenchmarkParameter, u32)],
Expand Down Expand Up @@ -848,19 +847,15 @@ macro_rules! impl_benchmark {
// Select the component we will be benchmarking. Each component will be benchmarked.
for (idx, (name, low, high)) in components.iter().enumerate() {
// Get the number of steps for this component.
let steps = steps.get(idx).cloned().unwrap_or(prev_steps);
prev_steps = steps;

// Skip this loop if steps is zero
if steps == 0 { continue }
let (_current_step, total_steps) = steps;

let lowest = lowest_range_values.get(idx).cloned().unwrap_or(*low);
let highest = highest_range_values.get(idx).cloned().unwrap_or(*high);

let diff = highest - lowest;

// Create up to `STEPS` steps for that component between high and low.
let step_size = (diff / steps).max(1);
let step_size = (diff / total_steps).max(1);
let num_of_steps = diff / step_size + 1;

for s in 0..num_of_steps {
Expand Down Expand Up @@ -1235,7 +1230,8 @@ pub fn show_benchmark_debug_info(
benchmark: &[u8],
lowest_range_values: &sp_std::prelude::Vec<u32>,
highest_range_values: &sp_std::prelude::Vec<u32>,
steps: &sp_std::prelude::Vec<u32>,
steps: &(u32, u32),
repeat: &(u32, u32),
verify: &bool,
error_message: &str,
) -> sp_runtime::RuntimeString {
Expand All @@ -1245,6 +1241,7 @@ pub fn show_benchmark_debug_info(
* Lowest_range_values: {:?}\n\
* Highest_range_values: {:?}\n\
* Steps: {:?}\n\
* Repeat: {:?}\n\
* Verify: {:?}\n\
* Error message: {}",
sp_std::str::from_utf8(instance_string)
Expand All @@ -1253,7 +1250,8 @@ pub fn show_benchmark_debug_info(
.expect("it's all just strings ran through the wasm interface. qed"),
lowest_range_values,
highest_range_values,
steps,
steps.1,
repeat.1,
verify,
error_message,
)
Expand Down Expand Up @@ -1334,6 +1332,7 @@ macro_rules! add_benchmark {
lowest_range_values,
highest_range_values,
steps,
repeat,
verify,
extra,
} = config;
Expand All @@ -1348,7 +1347,8 @@ macro_rules! add_benchmark {
benchmark,
&lowest_range_values[..],
&highest_range_values[..],
&steps[..],
*steps,
*repeat,
whitelist,
*verify,
).map_err(|e| {
Expand All @@ -1358,6 +1358,7 @@ macro_rules! add_benchmark {
lowest_range_values,
highest_range_values,
steps,
repeat,
verify,
e,
)
Expand All @@ -1373,7 +1374,8 @@ macro_rules! add_benchmark {
&benchmark[..],
&lowest_range_values[..],
&highest_range_values[..],
&steps[..],
*steps,
*repeat,
whitelist,
*verify,
).map_err(|e| {
Expand All @@ -1383,6 +1385,7 @@ macro_rules! add_benchmark {
lowest_range_values,
highest_range_values,
steps,
repeat,
verify,
e,
)
Expand Down
19 changes: 15 additions & 4 deletions frame/benchmarking/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,10 @@ pub struct BenchmarkConfig {
pub lowest_range_values: Vec<u32>,
/// An optional manual override to the highest values used in the `steps` range.
pub highest_range_values: Vec<u32>,
/// The number of samples to take across the range of values for components.
pub steps: Vec<u32>,
/// The number of samples to take across the range of values for components. (current_step, total_steps)
pub steps: (u32, u32),
/// The number times to repeat each benchmark to increase accuracy of results. (current_repeat, total_repeat)
pub repeat: (u32, u32),
/// Enable an extra benchmark iteration which runs the verification logic for a benchmark.
pub verify: bool,
/// Enable benchmarking of "extra" extrinsics, i.e. those that are not directly used in a pallet.
Expand All @@ -89,6 +91,13 @@ pub struct BenchmarkConfig {
sp_api::decl_runtime_apis! {
/// Runtime api for benchmarking a FRAME runtime.
pub trait Benchmark {
/// Get the benchmarks available for this runtime.
///
/// Parameters
/// - `extra`: Also return benchmarks marked "extra" which would otherwise not be
/// needed for weight calculation.
//fn benchmarks(extra: bool) -> Vec<(&'static [u8], Vec<&'static [u8])>;

/// Dispatch the given benchmark.
fn dispatch_benchmark(config: BenchmarkConfig)
-> Result<(Vec<BenchmarkBatch>, Vec<StorageInfo>), sp_runtime::RuntimeString>;
Expand Down Expand Up @@ -188,14 +197,16 @@ pub trait Benchmarking<T> {
/// Parameters
/// - `name`: The name of extrinsic function or benchmark you want to benchmark encoded as
/// bytes.
/// - `steps`: The number of sample points you want to take across the range of parameters.
/// - `lowest_range_values`: The lowest number for each range of parameters.
/// - `highest_range_values`: The highest number for each range of parameters.
/// - `steps`: The number of sample points you want to take across the range of parameters. (current_step, total_steps)
/// - `repeat`: The total number times to repeat each benchmark to increase accuracy of results. (current_repeat, total_repeats)
fn run_benchmark(
name: &[u8],
lowest_range_values: &[u32],
highest_range_values: &[u32],
steps: &[u32],
steps: (u32, u32),
repeat: (u32, u32),
whitelist: &[TrackedStorageKey],
verify: bool,
) -> Result<Vec<T>, &'static str>;
Expand Down
5 changes: 3 additions & 2 deletions utils/frame/benchmarking-cli/src/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ impl BenchmarkCmd {
let mut batches = Vec::new();
let mut storage_info = Vec::new();

for _r in 0 .. self.repeat {
for r in 0 .. self.repeat {
let mut extensions = Extensions::default();
extensions.register(KeystoreExt(Arc::new(KeyStore::new()) as SyncCryptoStorePtr));
let (offchain, _) = TestOffchainExt::new();
Expand All @@ -120,7 +120,8 @@ impl BenchmarkCmd {
&self.extrinsic,
self.lowest_range_values.clone(),
self.highest_range_values.clone(),
self.steps.clone(),
(self.steps, self.steps),
(r, self.repeat),
!self.no_verify,
self.extra,
).encode(),
Expand Down
4 changes: 2 additions & 2 deletions utils/frame/benchmarking-cli/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ pub struct BenchmarkCmd {
pub extrinsic: String,

/// Select how many samples we should take across the variable components.
#[structopt(short, long, use_delimiter = true)]
pub steps: Vec<u32>,
#[structopt(short, long, default_value = "1")]
pub steps: u32,

/// Indicates lowest values for each of the component ranges.
#[structopt(long = "low", use_delimiter = true)]
Expand Down
2 changes: 1 addition & 1 deletion utils/frame/benchmarking-cli/src/writer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ struct BenchmarkData {
// This forwards some specific metadata from the `BenchmarkCmd`
#[derive(Serialize, Default, Debug, Clone)]
struct CmdData {
steps: Vec<u32>,
steps: u32,
repeat: u32,
lowest_range_values: Vec<u32>,
highest_range_values: Vec<u32>,
Expand Down