Skip to content
Snippets Groups Projects
Unverified Commit 8d7f0d31 authored by bgallois's avatar bgallois
Browse files

add extrinsic base weight overhead

parent c8d99448
No related branches found
No related tags found
No related merge requests found
Pipeline #35108 passed
...@@ -55,13 +55,13 @@ pub fn analyze_weight( ...@@ -55,13 +55,13 @@ pub fn analyze_weight(
) -> HashMap<String, HashMap<String, WeightInfo>> { ) -> HashMap<String, HashMap<String, WeightInfo>> {
let pallet_weights = read_pallet_weight(folder_path); let pallet_weights = read_pallet_weight(folder_path);
let db_weight = read_db_weight(folder_path); let db_weight = read_db_weight(folder_path);
let _overhead_weights = read_overhead_weight(folder_path); let overhead_weights = read_overhead_weight(folder_path);
// Initialize scope with db weights // Initialize scope with db weights
let mut scope = Scope::from_substrate(); let mut scope = Scope::from_substrate();
scope = scope.with_storage_weights(db_weight.weights.read, db_weight.weights.write); scope = scope.with_storage_weights(db_weight.weights.read, db_weight.weights.write);
process(pallet_weights, scope, max_block_weight) process(pallet_weights, scope, max_block_weight, &overhead_weights)
} }
fn read_pallet_weight(folder_path: &Path) -> Vec<Vec<ChromaticExtrinsic>> { fn read_pallet_weight(folder_path: &Path) -> Vec<Vec<ChromaticExtrinsic>> {
...@@ -87,7 +87,7 @@ fn read_db_weight(folder_path: &Path) -> Weights { ...@@ -87,7 +87,7 @@ fn read_db_weight(folder_path: &Path) -> Weights {
} }
fn read_overhead_weight(folder_path: &Path) -> Weight { fn read_overhead_weight(folder_path: &Path) -> Weight {
subweight_core::parse::overhead::parse_file(folder_path.join("block_weights.rs").as_path()) subweight_core::parse::overhead::parse_file(folder_path.join("extrinsic_weights.rs").as_path())
.expect("No overhead weight") .expect("No overhead weight")
} }
...@@ -95,6 +95,7 @@ fn evaluate_weight( ...@@ -95,6 +95,7 @@ fn evaluate_weight(
extrinsic: ChromaticExtrinsic, extrinsic: ChromaticExtrinsic,
scope: &mut Scope<Term<u128>>, scope: &mut Scope<Term<u128>>,
max_block_weight: &MaxBlockWeight, max_block_weight: &MaxBlockWeight,
overhead: &Weight,
) -> Result<(String, String, WeightInfo), String> { ) -> Result<(String, String, WeightInfo), String> {
// Extend the scope with the maximum value of the complexity parameter. // Extend the scope with the maximum value of the complexity parameter.
if let Some(params) = extrinsic.comp_ranges { if let Some(params) = extrinsic.comp_ranges {
...@@ -106,12 +107,22 @@ fn evaluate_weight( ...@@ -106,12 +107,22 @@ fn evaluate_weight(
} }
// Evaluate the weight // Evaluate the weight
let weight = extrinsic let mut weight = extrinsic
.term .term
.simplify(subweight_core::Dimension::Time) .simplify(subweight_core::Dimension::Time)
.expect("Can't evaluate") .expect("Can't evaluate")
.eval(scope) .eval(scope)
.unwrap(); .unwrap();
// Add base extrinsic overhead
if let Weight::ExtrinsicBase(i) = overhead {
weight += i
.simplify(subweight_core::Dimension::Time)
.expect("Can't evaluate")
.eval(scope)
.unwrap();
}
let relative_weight = (weight as f64) / max_block_weight * 100.; let relative_weight = (weight as f64) / max_block_weight * 100.;
Ok(( Ok((
extrinsic extrinsic
...@@ -134,12 +145,13 @@ fn process( ...@@ -134,12 +145,13 @@ fn process(
pallet_weights: Vec<Vec<ChromaticExtrinsic>>, pallet_weights: Vec<Vec<ChromaticExtrinsic>>,
mut scope: Scope<Term<u128>>, mut scope: Scope<Term<u128>>,
max_block_weight: &MaxBlockWeight, max_block_weight: &MaxBlockWeight,
overhead: &Weight,
) -> HashMap<String, HashMap<String, WeightInfo>> { ) -> HashMap<String, HashMap<String, WeightInfo>> {
let mut weight_by_pallet: HashMap<String, HashMap<String, WeightInfo>> = HashMap::new(); let mut weight_by_pallet: HashMap<String, HashMap<String, WeightInfo>> = HashMap::new();
for i in pallet_weights { for i in pallet_weights {
for j in i { for j in i {
let (pallet, extrinsic, weight) = let (pallet, extrinsic, weight) =
evaluate_weight(j, &mut scope, max_block_weight).unwrap(); evaluate_weight(j, &mut scope, max_block_weight, overhead).unwrap();
if let Some(i) = weight_by_pallet.get_mut(&pallet) { if let Some(i) = weight_by_pallet.get_mut(&pallet) {
i.insert(extrinsic, weight); i.insert(extrinsic, weight);
} else { } else {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment