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

Benchmarks Writer CLI #6567

Merged
40 commits merged into from
Jul 6, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
7468464
initial mockup
shawntabrizi Jun 17, 2020
947d68c
add and wipe
shawntabrizi Jun 17, 2020
9c77f50
track writes
shawntabrizi Jun 17, 2020
2f198b9
start to add to pipeline
shawntabrizi Jun 18, 2020
12395ae
return all reads/writes
shawntabrizi Jun 18, 2020
69f137d
Log reads and writes from bench db
shawntabrizi Jun 18, 2020
60f22c3
causes panic
shawntabrizi Jun 18, 2020
e08ffef
Allow multiple commits
arkpar Jun 18, 2020
86ecbeb
commit before ending benchmark
shawntabrizi Jun 18, 2020
f7305a2
Merge branch 'master' into shawntabrizi-bench-db-tracking
shawntabrizi Jun 18, 2020
004bea1
doesn't work???
shawntabrizi Jun 18, 2020
1b25a8b
fix
shawntabrizi Jun 18, 2020
c995215
Update lib.rs
shawntabrizi Jun 18, 2020
2eef7fa
switch to struct for `BenchmarkResults`
shawntabrizi Jun 18, 2020
473f492
add to output
shawntabrizi Jun 18, 2020
0ae5300
fix test
shawntabrizi Jun 18, 2020
fd99bda
line width
shawntabrizi Jun 18, 2020
79cd015
@kianenigma review
shawntabrizi Jun 18, 2020
9464475
Add Whitelist to DB Tracking in Benchmarks Pipeline (#6405)
shawntabrizi Jun 20, 2020
956cda1
Add regression analysis to DB Tracking (#6475)
shawntabrizi Jun 22, 2020
962a3f5
initial idea
shawntabrizi Jun 23, 2020
c3e9639
use all benchmarks
shawntabrizi Jun 23, 2020
87dfc19
broken
shawntabrizi Jun 23, 2020
6f82848
working without trait
shawntabrizi Jun 23, 2020
78ca73e
Make work for multiple pallets
shawntabrizi Jun 23, 2020
decc972
Merge branch 'master' into shawntabrizi-output-benchmarks
shawntabrizi Jun 27, 2020
b38d82e
Fix merge issues
shawntabrizi Jun 27, 2020
ccff2e1
writer appends to file
shawntabrizi Jun 28, 2020
02f69ff
implement () for balances weight trait
shawntabrizi Jul 2, 2020
e51814a
Merge branch 'master' into shawntabrizi-output-benchmarks
shawntabrizi Jul 2, 2020
aa17f5c
update name of trait
shawntabrizi Jul 2, 2020
c83c7fb
Weights to WeightInfo
shawntabrizi Jul 2, 2020
b29eef1
auto trait writer
shawntabrizi Jul 2, 2020
102a463
Heap pages are configurable
shawntabrizi Jul 3, 2020
8456e12
clean out runtime changes
shawntabrizi Jul 3, 2020
0b22d50
more clean up
shawntabrizi Jul 3, 2020
ace2d6d
Fix string generation
shawntabrizi Jul 3, 2020
761626b
Update comments
shawntabrizi Jul 3, 2020
db401bb
Merge branch 'master' into shawntabrizi-benchmarks-writer
shawntabrizi Jul 4, 2020
eb0ae88
Update bin/node/runtime/src/lib.rs
shawntabrizi Jul 6, 2020
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
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

39 changes: 19 additions & 20 deletions bin/node/runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1118,7 +1118,6 @@ impl_runtime_apis! {

let whitelist: Vec<Vec<u8>> = vec![
// Block Number
// frame_system::Number::<Runtime>::hashed_key().to_vec(),
hex_literal::hex!("26aa394eea5630e07c48ae0c9558cef702a5c1b19ab7a04f536c519aca4983ac").to_vec(),
// Total Issuance
hex_literal::hex!("c2261276cc9d1f8598ea4b6a74b15c2f57c875e4cff74148e4628f264b974c80").to_vec(),
Expand All @@ -1137,25 +1136,25 @@ impl_runtime_apis! {
let mut batches = Vec::<BenchmarkBatch>::new();
let params = (&pallet, &benchmark, &lowest_range_values, &highest_range_values, &steps, repeat, &whitelist);

add_benchmark!(params, batches, b"babe", Babe);
add_benchmark!(params, batches, b"balances", Balances);
add_benchmark!(params, batches, b"collective", Council);
add_benchmark!(params, batches, b"democracy", Democracy);
add_benchmark!(params, batches, b"elections", Elections);
add_benchmark!(params, batches, b"identity", Identity);
add_benchmark!(params, batches, b"im-online", ImOnline);
add_benchmark!(params, batches, b"indices", Indices);
add_benchmark!(params, batches, b"multisig", Multisig);
add_benchmark!(params, batches, b"offences", OffencesBench::<Runtime>);
add_benchmark!(params, batches, b"proxy", Proxy);
add_benchmark!(params, batches, b"scheduler", Scheduler);
add_benchmark!(params, batches, b"session", SessionBench::<Runtime>);
add_benchmark!(params, batches, b"staking", Staking);
add_benchmark!(params, batches, b"system", SystemBench::<Runtime>);
add_benchmark!(params, batches, b"timestamp", Timestamp);
add_benchmark!(params, batches, b"treasury", Treasury);
add_benchmark!(params, batches, b"utility", Utility);
add_benchmark!(params, batches, b"vesting", Vesting);
add_benchmark!(params, batches, pallet_babe, Babe);
add_benchmark!(params, batches, pallet_balances, Balances);
add_benchmark!(params, batches, pallet_collective, Council);
add_benchmark!(params, batches, pallet_democracy, Democracy);
add_benchmark!(params, batches, pallet_elections_phragmen, Elections);
add_benchmark!(params, batches, pallet_identity, Identity);
add_benchmark!(params, batches, pallet_im_online, ImOnline);
add_benchmark!(params, batches, pallet_indices, Indices);
add_benchmark!(params, batches, pallet_multisig, Multisig);
add_benchmark!(params, batches, pallet_offences, OffencesBench::<Runtime>);
add_benchmark!(params, batches, pallet_proxy, Proxy);
add_benchmark!(params, batches, pallet_scheduler, Scheduler);
add_benchmark!(params, batches, pallet_session, SessionBench::<Runtime>);
add_benchmark!(params, batches, pallet_staking, Staking);
add_benchmark!(params, batches, frame_system, SystemBench::<Runtime>);
add_benchmark!(params, batches, pallet_timestamp, Timestamp);
add_benchmark!(params, batches, pallet_treasury, Treasury);
add_benchmark!(params, batches, pallet_utility, Utility);
add_benchmark!(params, batches, pallet_vesting, Vesting);

if batches.is_empty() { return Err("Benchmark not found for this pallet.".into()) }
Ok(batches)
Expand Down
10 changes: 5 additions & 5 deletions frame/benchmarking/src/analysis.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@ use linregress::{FormulaRegressionBuilder, RegressionDataBuilder, RegressionMode
use crate::BenchmarkResults;

pub struct Analysis {
base: u128,
slopes: Vec<u128>,
names: Vec<String>,
value_dists: Option<Vec<(Vec<u32>, u128, u128)>>,
model: Option<RegressionModel>,
pub base: u128,
pub slopes: Vec<u128>,
pub names: Vec<String>,
pub value_dists: Option<Vec<(Vec<u32>, u128, u128)>>,
pub model: Option<RegressionModel>,
}

pub enum BenchmarkSelector {
Expand Down
35 changes: 25 additions & 10 deletions frame/benchmarking/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1158,31 +1158,46 @@ macro_rules! impl_benchmark_test {
/// 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);
/// 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 skip for DB tracking. For example:
///
/// ```ignore
/// let whitelist: Vec<Vec<u8>> = vec![
/// // Block Number
/// hex_literal::hex!("26aa394eea5630e07c48ae0c9558cef702a5c1b19ab7a04f536c519aca4983ac").to_vec(),
/// // Total Issuance
/// hex_literal::hex!("c2261276cc9d1f8598ea4b6a74b15c2f57c875e4cff74148e4628f264b974c80").to_vec(),
/// // Execution Phase
/// hex_literal::hex!("26aa394eea5630e07c48ae0c9558cef7ff553b5a9862a516939d82b3d3d8661a").to_vec(),
/// // Event Count
/// hex_literal::hex!("26aa394eea5630e07c48ae0c9558cef70a98fdbe9ce6c55837576c60c7af3850").to_vec(),
/// ];
///
/// 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:
/// Then add the pallets you want to benchmark to this object, using their crate name and generated
/// module struct:
///
/// ```ignore
/// add_benchmark!(params, batches, b"balances", Balances);
/// add_benchmark!(params, batches, b"identity", Identity);
/// add_benchmark!(params, batches, b"session", SessionBench::<Runtime>);
/// add_benchmark!(params, batches, pallet_balances, Balances);
/// add_benchmark!(params, batches, pallet_session, SessionBench::<Runtime>);
/// add_benchmark!(params, batches, frame_system, SystemBench::<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 )* ) => (
( $params:ident, $batches:ident, $name:ident, $( $location:tt )* ) => (
let name_string = stringify!($name).as_bytes();
let (pallet, benchmark, lowest_range_values, highest_range_values, steps, repeat, whitelist) = $params;
if &pallet[..] == &$name[..] || &pallet[..] == &b"*"[..] {
if &pallet[..] == &name_string[..] || &pallet[..] == &b"*"[..] {
if &pallet[..] == &b"*"[..] || &benchmark[..] == &b"*"[..] {
for benchmark in $( $location )*::benchmarks().into_iter() {
$batches.push($crate::BenchmarkBatch {
Expand All @@ -1194,7 +1209,7 @@ macro_rules! add_benchmark {
repeat,
whitelist,
)?,
pallet: $name.to_vec(),
pallet: name_string.to_vec(),
benchmark: benchmark.to_vec(),
});
}
Expand All @@ -1208,7 +1223,7 @@ macro_rules! add_benchmark {
repeat,
whitelist,
)?,
pallet: $name.to_vec(),
pallet: name_string.to_vec(),
benchmark: benchmark.clone(),
});
}
Expand Down
1 change: 1 addition & 0 deletions utils/frame/benchmarking-cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ description = "CLI for benchmarking FRAME"
targets = ["x86_64-unknown-linux-gnu"]

[dependencies]
Inflector = "0.11.4"
frame-benchmarking = { version = "2.0.0-rc4", path = "../../../frame/benchmarking" }
sp-core = { version = "2.0.0-rc4", path = "../../../primitives/core" }
sc-service = { version = "0.8.0-rc4", default-features = false, path = "../../../client/service" }
Expand Down
12 changes: 11 additions & 1 deletion utils/frame/benchmarking-cli/src/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ impl BenchmarkCmd {
let state = BenchmarkingState::<BB>::new(genesis_storage, cache_size)?;
let executor = NativeExecutor::<ExecDispatch>::new(
wasm_method,
None, // heap pages
self.heap_pages,
2, // The runtime instances cache size.
);

Expand Down Expand Up @@ -89,6 +89,16 @@ impl BenchmarkCmd {
let results = <std::result::Result<Vec<BenchmarkBatch>, String> as Decode>::decode(&mut &result[..])
.map_err(|e| format!("Failed to decode benchmark results: {:?}", e))?;

if self.output {
if self.weight_trait {
let mut file = crate::writer::open_file("traits.rs")?;
crate::writer::write_trait(&mut file, results.clone())?;
} else {
let mut file = crate::writer::open_file("benchmarks.rs")?;
crate::writer::write_results(&mut file, results.clone())?;
}
}

match results {
Ok(batches) => for batch in batches.into_iter() {
// Print benchmark metadata
Expand Down
13 changes: 13 additions & 0 deletions utils/frame/benchmarking-cli/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
// limitations under the License.

mod command;
mod writer;

use sc_cli::{ExecutionStrategy, WasmExecutionMethod};
use std::fmt::Debug;
Expand Down Expand Up @@ -59,6 +60,18 @@ pub struct BenchmarkCmd {
#[structopt(long)]
pub no_min_squares: bool,

/// Output the benchmarks to a Rust file.
#[structopt(long)]
pub output: bool,

/// Output the trait definition to a Rust file.
#[structopt(long)]
pub weight_trait: bool,

/// Set the heap pages while running benchmarks.
#[structopt(long)]
pub heap_pages: Option<u64>,

#[allow(missing_docs)]
#[structopt(flatten)]
pub shared_params: sc_cli::SharedParams,
Expand Down
Loading