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

Commit 8b412b4

Browse files
shawntabriziNikVolfgavofyork
authored
More Improvements to Benchmarking CLI + Generic WeightInfo (#7168)
* Generic WeightInfo, Output File Path * Make `WeightInfo` generic * Add support for header file * fix line width * add `--spaces` flag * Configurable trait and struct strings * make elections phragmen generic * Add date to generated file * Apply suggestions from code review Co-authored-by: Gavin Wood <gavin@parity.io> * fixes * add settings metadata to output Co-authored-by: nikvolf <nikvolf@gmail.com> Co-authored-by: Gavin Wood <gavin@parity.io>
1 parent 38d5bb3 commit 8b412b4

25 files changed

+583
-426
lines changed

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

HEADER

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// This file is part of Substrate.
2+
3+
// Copyright (C) 2020 Parity Technologies (UK) Ltd.
4+
// SPDX-License-Identifier: Apache-2.0
5+
6+
// Licensed under the Apache License, Version 2.0 (the "License");
7+
// you may not use this file except in compliance with the License.
8+
// You may obtain a copy of the License at
9+
//
10+
// http://www.apache.org/licenses/LICENSE-2.0
11+
//
12+
// Unless required by applicable law or agreed to in writing, software
13+
// distributed under the License is distributed on an "AS IS" BASIS,
14+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
// See the License for the specific language governing permissions and
16+
// limitations under the License.

bin/node/runtime/src/lib.rs

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -183,13 +183,13 @@ impl frame_system::Trait for Runtime {
183183
type AccountData = pallet_balances::AccountData<Balance>;
184184
type OnNewAccount = ();
185185
type OnKilledAccount = ();
186-
type SystemWeightInfo = weights::frame_system::WeightInfo;
186+
type SystemWeightInfo = weights::frame_system::WeightInfo<Runtime>;
187187
}
188188

189189
impl pallet_utility::Trait for Runtime {
190190
type Event = Event;
191191
type Call = Call;
192-
type WeightInfo = weights::pallet_utility::WeightInfo;
192+
type WeightInfo = weights::pallet_utility::WeightInfo<Runtime>;
193193
}
194194

195195
parameter_types! {
@@ -207,7 +207,7 @@ impl pallet_multisig::Trait for Runtime {
207207
type DepositBase = DepositBase;
208208
type DepositFactor = DepositFactor;
209209
type MaxSignatories = MaxSignatories;
210-
type WeightInfo = weights::pallet_multisig::WeightInfo;
210+
type WeightInfo = weights::pallet_multisig::WeightInfo<Runtime>;
211211
}
212212

213213
parameter_types! {
@@ -271,7 +271,7 @@ impl pallet_proxy::Trait for Runtime {
271271
type ProxyDepositBase = ProxyDepositBase;
272272
type ProxyDepositFactor = ProxyDepositFactor;
273273
type MaxProxies = MaxProxies;
274-
type WeightInfo = weights::pallet_proxy::WeightInfo;
274+
type WeightInfo = weights::pallet_proxy::WeightInfo<Runtime>;
275275
type MaxPending = MaxPending;
276276
type CallHasher = BlakeTwo256;
277277
type AnnouncementDepositBase = AnnouncementDepositBase;
@@ -291,7 +291,7 @@ impl pallet_scheduler::Trait for Runtime {
291291
type MaximumWeight = MaximumSchedulerWeight;
292292
type ScheduleOrigin = EnsureRoot<AccountId>;
293293
type MaxScheduledPerBlock = MaxScheduledPerBlock;
294-
type WeightInfo = weights::pallet_scheduler::WeightInfo;
294+
type WeightInfo = weights::pallet_scheduler::WeightInfo<Runtime>;
295295
}
296296

297297
parameter_types! {
@@ -331,7 +331,7 @@ impl pallet_indices::Trait for Runtime {
331331
type Currency = Balances;
332332
type Deposit = IndexDeposit;
333333
type Event = Event;
334-
type WeightInfo = weights::pallet_indices::WeightInfo;
334+
type WeightInfo = weights::pallet_indices::WeightInfo<Runtime>;
335335
}
336336

337337
parameter_types! {
@@ -348,7 +348,7 @@ impl pallet_balances::Trait for Runtime {
348348
type Event = Event;
349349
type ExistentialDeposit = ExistentialDeposit;
350350
type AccountStore = frame_system::Module<Runtime>;
351-
type WeightInfo = weights::pallet_balances::WeightInfo;
351+
type WeightInfo = weights::pallet_balances::WeightInfo<Runtime>;
352352
}
353353

354354
parameter_types! {
@@ -375,7 +375,7 @@ impl pallet_timestamp::Trait for Runtime {
375375
type Moment = Moment;
376376
type OnTimestampSet = Babe;
377377
type MinimumPeriod = MinimumPeriod;
378-
type WeightInfo = weights::pallet_timestamp::WeightInfo;
378+
type WeightInfo = weights::pallet_timestamp::WeightInfo<Runtime>;
379379
}
380380

381381
parameter_types! {
@@ -412,7 +412,7 @@ impl pallet_session::Trait for Runtime {
412412
type SessionHandler = <SessionKeys as OpaqueKeys>::KeyTypeIdProviders;
413413
type Keys = SessionKeys;
414414
type DisabledValidatorsThreshold = DisabledValidatorsThreshold;
415-
type WeightInfo = weights::pallet_session::WeightInfo;
415+
type WeightInfo = weights::pallet_session::WeightInfo<Runtime>;
416416
}
417417

418418
impl pallet_session::historical::Trait for Runtime {
@@ -469,7 +469,7 @@ impl pallet_staking::Trait for Runtime {
469469
type MinSolutionScoreBump = MinSolutionScoreBump;
470470
type MaxNominatorRewardedPerValidator = MaxNominatorRewardedPerValidator;
471471
type UnsignedPriority = StakingUnsignedPriority;
472-
type WeightInfo = weights::pallet_staking::WeightInfo;
472+
type WeightInfo = weights::pallet_staking::WeightInfo<Runtime>;
473473
}
474474

475475
parameter_types! {
@@ -518,7 +518,7 @@ impl pallet_democracy::Trait for Runtime {
518518
type Scheduler = Scheduler;
519519
type PalletsOrigin = OriginCaller;
520520
type MaxVotes = MaxVotes;
521-
type WeightInfo = weights::pallet_democracy::WeightInfo;
521+
type WeightInfo = weights::pallet_democracy::WeightInfo<Runtime>;
522522
}
523523

524524
parameter_types! {
@@ -536,7 +536,7 @@ impl pallet_collective::Trait<CouncilCollective> for Runtime {
536536
type MaxProposals = CouncilMaxProposals;
537537
type MaxMembers = CouncilMaxMembers;
538538
type DefaultVote = pallet_collective::PrimeDefaultVote;
539-
type WeightInfo = weights::pallet_collective::WeightInfo;
539+
type WeightInfo = weights::pallet_collective::WeightInfo<Runtime>;
540540
}
541541

542542
parameter_types! {
@@ -568,7 +568,7 @@ impl pallet_elections_phragmen::Trait for Runtime {
568568
type DesiredMembers = DesiredMembers;
569569
type DesiredRunnersUp = DesiredRunnersUp;
570570
type TermDuration = TermDuration;
571-
type WeightInfo = weights::pallet_elections_phragmen::WeightInfo;
571+
type WeightInfo = weights::pallet_elections_phragmen::WeightInfo<Runtime>;
572572
}
573573

574574
parameter_types! {
@@ -586,7 +586,7 @@ impl pallet_collective::Trait<TechnicalCollective> for Runtime {
586586
type MaxProposals = TechnicalMaxProposals;
587587
type MaxMembers = TechnicalMaxMembers;
588588
type DefaultVote = pallet_collective::PrimeDefaultVote;
589-
type WeightInfo = weights::pallet_collective::WeightInfo;
589+
type WeightInfo = weights::pallet_collective::WeightInfo<Runtime>;
590590
}
591591

592592
type EnsureRootOrHalfCouncil = EnsureOneOf<
@@ -654,7 +654,7 @@ impl pallet_treasury::Trait for Runtime {
654654
type BountyValueMinimum = BountyValueMinimum;
655655
type MaximumReasonLength = MaximumReasonLength;
656656
type BurnDestination = ();
657-
type WeightInfo = weights::pallet_treasury::WeightInfo;
657+
type WeightInfo = weights::pallet_treasury::WeightInfo<Runtime>;
658658
}
659659

660660
parameter_types! {
@@ -759,7 +759,7 @@ impl pallet_im_online::Trait for Runtime {
759759
type SessionDuration = SessionDuration;
760760
type ReportUnresponsiveness = Offences;
761761
type UnsignedPriority = ImOnlineUnsignedPriority;
762-
type WeightInfo = weights::pallet_im_online::WeightInfo;
762+
type WeightInfo = weights::pallet_im_online::WeightInfo<Runtime>;
763763
}
764764

765765
parameter_types! {
@@ -827,7 +827,7 @@ impl pallet_identity::Trait for Runtime {
827827
type Slashed = Treasury;
828828
type ForceOrigin = EnsureRootOrHalfCouncil;
829829
type RegistrarOrigin = EnsureRootOrHalfCouncil;
830-
type WeightInfo = weights::pallet_identity::WeightInfo;
830+
type WeightInfo = weights::pallet_identity::WeightInfo<Runtime>;
831831
}
832832

833833
parameter_types! {
@@ -884,7 +884,7 @@ impl pallet_vesting::Trait for Runtime {
884884
type Currency = Balances;
885885
type BlockNumberToBalance = ConvertInto;
886886
type MinVestedTransfer = MinVestedTransfer;
887-
type WeightInfo = weights::pallet_vesting::WeightInfo;
887+
type WeightInfo = weights::pallet_vesting::WeightInfo<Runtime>;
888888
}
889889

890890
construct_runtime!(

bin/node/runtime/src/weights/frame_system.rs

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,38 +19,39 @@
1919
2020
#![allow(unused_parens)]
2121

22-
use frame_support::weights::{Weight, constants::RocksDbWeight as DbWeight};
22+
use frame_support::{traits::Get, weights::Weight};
23+
use sp_std::marker::PhantomData;
2324

24-
pub struct WeightInfo;
25-
impl frame_system::WeightInfo for WeightInfo {
25+
pub struct WeightInfo<T>(PhantomData<T>);
26+
impl<T: frame_system::Trait> frame_system::WeightInfo for WeightInfo<T> {
2627
// WARNING! Some components were not used: ["b"]
2728
fn remark() -> Weight {
2829
(1305000 as Weight)
2930
}
3031
fn set_heap_pages() -> Weight {
3132
(2023000 as Weight)
32-
.saturating_add(DbWeight::get().writes(1 as Weight))
33+
.saturating_add(T::DbWeight::get().writes(1 as Weight))
3334
}
3435
// WARNING! Some components were not used: ["d"]
3536
fn set_changes_trie_config() -> Weight {
3637
(10026000 as Weight)
37-
.saturating_add(DbWeight::get().reads(1 as Weight))
38-
.saturating_add(DbWeight::get().writes(2 as Weight))
38+
.saturating_add(T::DbWeight::get().reads(1 as Weight))
39+
.saturating_add(T::DbWeight::get().writes(2 as Weight))
3940
}
4041
fn set_storage(i: u32, ) -> Weight {
4142
(0 as Weight)
4243
.saturating_add((656000 as Weight).saturating_mul(i as Weight))
43-
.saturating_add(DbWeight::get().writes((1 as Weight).saturating_mul(i as Weight)))
44+
.saturating_add(T::DbWeight::get().writes((1 as Weight).saturating_mul(i as Weight)))
4445
}
4546
fn kill_storage(i: u32, ) -> Weight {
4647
(4327000 as Weight)
4748
.saturating_add((478000 as Weight).saturating_mul(i as Weight))
48-
.saturating_add(DbWeight::get().writes((1 as Weight).saturating_mul(i as Weight)))
49+
.saturating_add(T::DbWeight::get().writes((1 as Weight).saturating_mul(i as Weight)))
4950
}
5051
fn kill_prefix(p: u32, ) -> Weight {
5152
(8349000 as Weight)
5253
.saturating_add((838000 as Weight).saturating_mul(p as Weight))
53-
.saturating_add(DbWeight::get().writes((1 as Weight).saturating_mul(p as Weight)))
54+
.saturating_add(T::DbWeight::get().writes((1 as Weight).saturating_mul(p as Weight)))
5455
}
5556
fn suicide() -> Weight {
5657
(29247000 as Weight)

bin/node/runtime/src/weights/mod.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,18 +17,18 @@
1717
1818
pub mod frame_system;
1919
pub mod pallet_balances;
20-
pub mod pallet_treasury;
2120
pub mod pallet_collective;
2221
pub mod pallet_democracy;
22+
pub mod pallet_elections_phragmen;
2323
pub mod pallet_identity;
24-
pub mod pallet_indices;
2524
pub mod pallet_im_online;
25+
pub mod pallet_indices;
2626
pub mod pallet_multisig;
2727
pub mod pallet_proxy;
2828
pub mod pallet_scheduler;
2929
pub mod pallet_session;
3030
pub mod pallet_staking;
3131
pub mod pallet_timestamp;
32+
pub mod pallet_treasury;
3233
pub mod pallet_utility;
3334
pub mod pallet_vesting;
34-
pub mod pallet_elections_phragmen;

bin/node/runtime/src/weights/pallet_balances.rs

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -15,33 +15,34 @@
1515

1616
//! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 2.0.0-rc5
1717
18-
use frame_support::weights::{Weight, constants::RocksDbWeight as DbWeight};
18+
use frame_support::{traits::Get, weights::Weight};
19+
use sp_std::marker::PhantomData;
1920

20-
pub struct WeightInfo;
21-
impl pallet_balances::WeightInfo for WeightInfo {
21+
pub struct WeightInfo<T>(PhantomData<T>);
22+
impl<T: frame_system::Trait> pallet_balances::WeightInfo for WeightInfo<T> {
2223
fn transfer() -> Weight {
2324
(65949000 as Weight)
24-
.saturating_add(DbWeight::get().reads(1 as Weight))
25-
.saturating_add(DbWeight::get().writes(1 as Weight))
25+
.saturating_add(T::DbWeight::get().reads(1 as Weight))
26+
.saturating_add(T::DbWeight::get().writes(1 as Weight))
2627
}
2728
fn transfer_keep_alive() -> Weight {
2829
(46665000 as Weight)
29-
.saturating_add(DbWeight::get().reads(1 as Weight))
30-
.saturating_add(DbWeight::get().writes(1 as Weight))
30+
.saturating_add(T::DbWeight::get().reads(1 as Weight))
31+
.saturating_add(T::DbWeight::get().writes(1 as Weight))
3132
}
3233
fn set_balance_creating() -> Weight {
3334
(27086000 as Weight)
34-
.saturating_add(DbWeight::get().reads(1 as Weight))
35-
.saturating_add(DbWeight::get().writes(1 as Weight))
35+
.saturating_add(T::DbWeight::get().reads(1 as Weight))
36+
.saturating_add(T::DbWeight::get().writes(1 as Weight))
3637
}
3738
fn set_balance_killing() -> Weight {
3839
(33424000 as Weight)
39-
.saturating_add(DbWeight::get().reads(1 as Weight))
40-
.saturating_add(DbWeight::get().writes(1 as Weight))
40+
.saturating_add(T::DbWeight::get().reads(1 as Weight))
41+
.saturating_add(T::DbWeight::get().writes(1 as Weight))
4142
}
4243
fn force_transfer() -> Weight {
4344
(65343000 as Weight)
44-
.saturating_add(DbWeight::get().reads(2 as Weight))
45-
.saturating_add(DbWeight::get().writes(2 as Weight))
45+
.saturating_add(T::DbWeight::get().reads(2 as Weight))
46+
.saturating_add(T::DbWeight::get().writes(2 as Weight))
4647
}
4748
}

0 commit comments

Comments
 (0)