Skip to content

update bencher deps #872

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jan 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
3 changes: 3 additions & 0 deletions Cargo.dev.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ members = [
"auction",
"authority",
"bencher",
"bencher/test",
"benchmarking",
"currencies",
"gradually-update",
Expand All @@ -26,6 +27,8 @@ members = [
"payments"
]

exclude = ["bencher/test"]

resolver = "2"

[profile.dev]
Expand Down
4 changes: 3 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,11 @@ dev-check: Cargo.toml check

dev-check-tests: Cargo.toml
cargo check --tests --all
cargo check --tests --features=bench --package=orml-weight-meter --package=orml-bencher-test

dev-test: Cargo.toml
cargo test --all --features runtime-benchmarks
cargo test --all --features=runtime-benchmarks
cargo test --features=bench --package=orml-weight-meter --package=orml-bencher-test

# run benchmarks via Acala node
benchmark-all:
Expand Down
10 changes: 5 additions & 5 deletions bencher/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,15 @@ edition = "2021"
[dependencies]
paste = "1.0.7"
build-helper = { version = "0.1.1", optional = true }
cargo_metadata = { version = "0.14.1", optional = true }
cargo_metadata = { version = "0.15.2", optional = true }
tempfile = { version = "3.2.0", optional = true }
toml = { version = "0.5.8", optional = true }
walkdir = { version = "2.3.1", optional = true }
ansi_term = { version = "0.12.1", optional = true }
wasm-gc-api = { version = "0.1.11", optional = true }
rand = {version = "0.8.3", optional = true }
linregress = { version = "0.4.4", optional = true }
parking_lot = { version = "0.12.0", optional = true }
linregress = { version = "0.5.0", optional = true }
parking_lot = { version = "0.12.1", optional = true }
thiserror = { version = "1.0", optional = true }
serde = { version = "1.0.136", optional = true, features = ['derive'] }
serde_json = {version = "1.0.68", optional = true }
Expand All @@ -35,7 +35,7 @@ sc-executor = { git = "https://github.com/paritytech/substrate", default-feature
sc-executor-common = { git = "https://github.com/paritytech/substrate", optional = true , branch = "polkadot-v0.9.36" }
sc-client-db = { git = "https://github.com/paritytech/substrate", default-features = false, features = ["rocksdb"], optional = true , branch = "polkadot-v0.9.36" }
sp-maybe-compressed-blob = { git = "https://github.com/paritytech/substrate", default-features = false, optional = true , branch = "polkadot-v0.9.36" }
frame-benchmarking = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.36" }
frame-support = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.36" }
sp-externalities = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.36" }
sp-storage = { git = "https://github.com/paritytech/substrate", default-features = false, optional = true , branch = "polkadot-v0.9.36" }

Expand Down Expand Up @@ -67,7 +67,7 @@ std = [
"sc-executor-common",
"sc-client-db",
"sp-maybe-compressed-blob",
"frame-benchmarking/std",
"frame-support/std",
"sp-externalities/std",
"sp-storage/std",
]
Expand Down
8 changes: 2 additions & 6 deletions bencher/src/bench_runner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,14 @@ use super::{
bench_ext::BenchExt,
tracker::{BenchTracker, BenchTrackerExt},
};
use frame_benchmarking::frame_support::sp_runtime::traits::Block;
use frame_support::sp_runtime::traits::Block;
use sc_executor::{WasmExecutionMethod, WasmExecutor, WasmtimeInstantiationStrategy};
use sc_executor_common::runtime_blob::RuntimeBlob;
use sp_externalities::Extensions;
use sp_state_machine::{Ext, OverlayedChanges, StorageTransactionCache};
use sp_std::sync::Arc;

type ComposeHostFunctions = (
sp_io::SubstrateHostFunctions,
frame_benchmarking::benchmarking::HostFunctions,
super::bench::HostFunctions,
);
type ComposeHostFunctions = (sp_io::SubstrateHostFunctions, super::bench::HostFunctions);

/// Run benches
pub fn run<B: Block>(wasm_code: Vec<u8>) -> std::result::Result<Vec<u8>, sc_executor_common::error::Error> {
Expand Down
10 changes: 5 additions & 5 deletions bencher/src/bencher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ impl Bencher {
pub fn before_run(&self) {
#[cfg(not(feature = "std"))]
{
frame_benchmarking::benchmarking::commit_db();
frame_benchmarking::benchmarking::wipe_db();
crate::bench::commit_db();
crate::bench::wipe_db();
}
}

Expand All @@ -56,8 +56,8 @@ impl Bencher {
{
#[cfg(not(feature = "std"))]
{
frame_benchmarking::benchmarking::commit_db();
frame_benchmarking::benchmarking::reset_read_write_count();
crate::bench::commit_db();
crate::bench::reset_read_write_count();
crate::bench::start_timer();
}

Expand All @@ -68,7 +68,7 @@ impl Bencher {
let elapsed = crate::bench::end_timer().saturating_sub(crate::bench::redundant_time());
self.current.elapses.push(elapsed);

frame_benchmarking::benchmarking::commit_db();
crate::bench::commit_db();

// changed keys
self.current.keys = crate::bench::read_written_keys();
Expand Down
11 changes: 5 additions & 6 deletions bencher/src/handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use crate::{
BenchResult,
};
use codec::Decode;
use frame_benchmarking::frame_support::traits::StorageInfo;
use frame_support::traits::StorageInfo;
use linregress::{FormulaRegressionBuilder, RegressionDataBuilder};
use serde::{Deserialize, Serialize};
use sp_core::hexdisplay::HexDisplay;
Expand Down Expand Up @@ -66,14 +66,13 @@ pub fn handle(output: Vec<u8>, storage_infos: Vec<StorageInfo>) {

comments.sort();

let intercepted_value = model.parameters()[0] as u64;

println!(
"{} {:<40} {:>20} storage: {:<20}",
green_bold("Bench"),
cyan(&name),
green_bold(&format!(
"{:?}",
Duration::from_nanos(model.parameters.intercept_value as u64)
)),
green_bold(&format!("{:?}", Duration::from_nanos(intercepted_value))),
green_bold(&format!(
"[r: {}, w: {}]",
&total_reads.to_string(),
Expand All @@ -83,7 +82,7 @@ pub fn handle(output: Vec<u8>, storage_infos: Vec<StorageInfo>) {

BenchData {
name,
weight: model.parameters.intercept_value as u64 * 1_000,
weight: intercepted_value * 1_000,
reads: total_reads,
writes: total_writes,
comments,
Expand Down
2 changes: 1 addition & 1 deletion bencher/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#![cfg_attr(not(feature = "std"), no_std)]

#[doc(hidden)]
pub extern crate frame_benchmarking;
pub extern crate frame_support;
#[doc(hidden)]
pub extern crate paste;
#[doc(hidden)]
Expand Down
2 changes: 1 addition & 1 deletion bencher/src/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ macro_rules! run_benches {
) => {
#[cfg(all(feature = "std", feature = "bench"))]
pub fn main() -> std::io::Result<()> {
use $crate::frame_benchmarking::frame_support::traits::StorageInfoTrait;
use $crate::frame_support::traits::StorageInfoTrait;
let wasm = $crate::build_wasm::build()?;
let storage_info = $all_pallets_with_system::storage_info();
match $crate::bench_runner::run::<$block>(wasm) {
Expand Down
12 changes: 12 additions & 0 deletions bencher/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,18 @@ pub trait Bench {
println!("{}", msg);
}

fn commit_db(&mut self) {
self.commit()
}

fn wipe_db(&mut self) {
self.wipe()
}

fn reset_read_write_count(&mut self) {
self.reset_read_write_count()
}

fn start_timer(&mut self) {
let tracker = &***self
.extension::<BenchTrackerExt>()
Expand Down
7 changes: 2 additions & 5 deletions bencher/test/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,18 +32,15 @@ std = [
"serde",
"scale-info/std",
"codec/std",
"orml-bencher/std",
"frame-support/std",
"frame-system/std",
"sp-runtime/std",
"sp-std/std",
"sp-core/std",
"sp-std/std",
"orml-bencher/std",
"orml-weight-meter/std",
]
bench = [
"orml-bencher/bench",
"orml-weight-meter/bench",
"frame-support/runtime-benchmarks",
"sp-runtime/runtime-benchmarks",
"frame-system/runtime-benchmarks",
]
8 changes: 1 addition & 7 deletions bencher/test/src/benches.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,4 @@ fn whitelist(b: &mut Bencher) {
});
}

benches!(
whitelist,
set_value,
set_foo,
remove_all_bar,
remove_all_bar_with_limit
);
benches!(whitelist, set_value, set_foo, remove_all_bar, remove_all_bar_with_limit);
10 changes: 5 additions & 5 deletions bencher/test/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,9 @@ pub mod pallet {
impl<T: Config> Pallet<T> {
#[pallet::call_index(0)]
#[pallet::weight(0)]
#[orml_weight_meter::start(ModuleWeights::<T>::set_value())]
#[orml_weight_meter::start(ModuleWeights::<T>::set_value().ref_time())]
pub fn set_value(origin: OriginFor<T>, n: u32) -> DispatchResultWithPostInfo {
let _sender = frame_system::ensure_signed(origin)?;
frame_system::ensure_signed(origin)?;
Value::<T>::get();
Value::<T>::put(n);
Value::<T>::put(n + 1);
Expand All @@ -53,14 +53,14 @@ pub mod pallet {
#[pallet::call_index(1)]
#[pallet::weight(0)]
pub fn dummy(origin: OriginFor<T>, _n: u32) -> DispatchResult {
let _sender = frame_system::ensure_none(origin)?;
frame_system::ensure_none(origin)?;
Foo::<T>::put(1);
Ok(())
}
}

impl<T: Config> Pallet<T> {
#[orml_weight_meter::weight(ModuleWeights::<T>::set_foo())]
#[orml_weight_meter::weight(ModuleWeights::<T>::set_foo().ref_time())]
pub(crate) fn set_foo() -> frame_support::dispatch::DispatchResult {
Value::<T>::put(2);

Expand All @@ -87,4 +87,4 @@ pub mod pallet {
_ = Bar::<T>::clear(10, None);
}
}
}
}
2 changes: 1 addition & 1 deletion bencher/test/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ pub type Header = sp_runtime::generic::Header<BlockNumber, BlakeTwo256>;

pub type SignedExtra = (frame_system::CheckWeight<Runtime>,);

pub type UncheckedExtrinsic = sp_runtime::generic::UncheckedExtrinsic<Address, Call, Signature, SignedExtra>;
pub type UncheckedExtrinsic = sp_runtime::generic::UncheckedExtrinsic<Address, RuntimeCall, Signature, SignedExtra>;

pub type Block = sp_runtime::generic::Block<Header, UncheckedExtrinsic>;

Expand Down
29 changes: 22 additions & 7 deletions bencher/test/src/weights.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,27 +10,42 @@ use sp_std::marker::PhantomData;

pub struct ModuleWeights<T>(PhantomData<T>);
impl<T: frame_system::Config> ModuleWeights<T> {
// Storage access info
//
// Test::Bar (r: 0, w: 1)
pub fn whitelist() -> Weight {
Weight::from_ref_time(5_356_000)
.saturating_add(T::DbWeight::get().writes(1))
}
// Storage access info
//
// Test::Value (r: 1, w: 1)
// Unknown 0x3a7472616e73616374696f6e5f6c6576656c3a (r: 1, w: 1)
pub fn set_value() -> Weight {
(5_236_000 as Weight)
.saturating_add(T::DbWeight::get().reads(1 as Weight))
.saturating_add(T::DbWeight::get().writes(1 as Weight))
Weight::from_ref_time(3_919_000)
.saturating_add(T::DbWeight::get().reads(2))
.saturating_add(T::DbWeight::get().writes(2))
}
// Storage access info
//
// Test::Bar (r: 1, w: 2)
// Test::Foo (r: 0, w: 1)
// Test::Value (r: 0, w: 1)
pub fn set_foo() -> Weight {
(13_274_000 as Weight)
.saturating_add(T::DbWeight::get().reads(1 as Weight))
.saturating_add(T::DbWeight::get().writes(4 as Weight))
Weight::from_ref_time(5_133_000)
.saturating_add(T::DbWeight::get().reads(1))
.saturating_add(T::DbWeight::get().writes(4))
}
// Storage access info
//
pub fn remove_all_bar() -> Weight {
(3_449_000 as Weight)
Weight::from_ref_time(1_533_000)
}
// Storage access info
//
// Test::Bar (r: 0, w: 10)
pub fn remove_all_bar_with_limit() -> Weight {
Weight::from_ref_time(1_600_000)
.saturating_add(T::DbWeight::get().writes(10))
}
}
2 changes: 2 additions & 0 deletions weight-meter/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ frame-support = { git = "https://github.com/paritytech/substrate", branch = "pol
frame-system = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.36" }
pallet-balances = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.36" }

orml-bencher = { path = "../bencher" }

[features]
default = ["std"]
std = [
Expand Down