diff --git a/resources/weight_analyzer/src/lib.rs b/resources/weight_analyzer/src/lib.rs index b289cfcba6dc42ab6598145652cb03af8847d73d..b8c6bffd0cd0c041e0e4b43eff8c396e194a8b89 100644 --- a/resources/weight_analyzer/src/lib.rs +++ b/resources/weight_analyzer/src/lib.rs @@ -55,13 +55,13 @@ pub fn analyze_weight( ) -> HashMap<String, HashMap<String, WeightInfo>> { let pallet_weights = read_pallet_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 let mut scope = Scope::from_substrate(); 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>> { @@ -87,7 +87,7 @@ fn read_db_weight(folder_path: &Path) -> Weights { } 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") } @@ -95,6 +95,7 @@ fn evaluate_weight( extrinsic: ChromaticExtrinsic, scope: &mut Scope<Term<u128>>, max_block_weight: &MaxBlockWeight, + overhead: &Weight, ) -> Result<(String, String, WeightInfo), String> { // Extend the scope with the maximum value of the complexity parameter. if let Some(params) = extrinsic.comp_ranges { @@ -106,12 +107,22 @@ fn evaluate_weight( } // Evaluate the weight - let weight = extrinsic + let mut weight = extrinsic .term .simplify(subweight_core::Dimension::Time) .expect("Can't evaluate") .eval(scope) .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.; Ok(( extrinsic @@ -134,12 +145,13 @@ fn process( pallet_weights: Vec<Vec<ChromaticExtrinsic>>, mut scope: Scope<Term<u128>>, max_block_weight: &MaxBlockWeight, + overhead: &Weight, ) -> HashMap<String, HashMap<String, WeightInfo>> { let mut weight_by_pallet: HashMap<String, HashMap<String, WeightInfo>> = HashMap::new(); for i in pallet_weights { for j in i { 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) { i.insert(extrinsic, weight); } else {