Skip to content
Snippets Groups Projects

Automatic weights documentation

Merged Benjamin Gallois requested to merge bgallois/duniter-v2s:weight-visualisation into master
1 file
+ 13
3
Compare changes
  • Side-by-side
  • Inline
@@ -2,6 +2,7 @@ use glob::glob;
use std::path::Path;
use subweight_core::parse::overhead::Weight;
use subweight_core::parse::pallet::ChromaticExtrinsic;
use subweight_core::parse::pallet::ComponentRange;
use subweight_core::parse::storage::Weights;
use subweight_core::scope::Scope;
use subweight_core::term::Term;
@@ -16,10 +17,9 @@ fn main() {
scope = scope.with_storage_weights(db_weight.weights.read, db_weight.weights.write);
// Test
// TODO Fix subweight-core parser not working with parameters
for i in pallet_weights {
for j in i {
let (pallet, extrinsic, weight) = evaluate_weight(j, &scope).unwrap();
let (pallet, extrinsic, weight) = evaluate_weight(j, &mut scope).unwrap();
println!(
"Pallet: {:?} ; Extrinsic: {:?} ; Weight: {:?}",
pallet, extrinsic, weight
@@ -58,8 +58,18 @@ fn read_overhead_weight() -> Weight {
fn evaluate_weight(
extrinsic: ChromaticExtrinsic,
scope: &Scope<Term<u128>>,
scope: &mut Scope<Term<u128>>,
) -> Result<(String, String, u128), String> {
// Extend the scope with the maximum value of the complexity parameter.
if let Some(params) = extrinsic.comp_ranges {
params
.iter()
.for_each(|(key, val): (&String, &ComponentRange)| {
scope.put_var(key.as_str(), Term::Scalar(val.max.into()));
});
}
// Evaluate the weight
let weight = extrinsic
.term
.simplify(subweight_core::Dimension::Time)
Loading