Skip to content
Snippets Groups Projects

Automatic weights documentation

Merged Benjamin Gallois requested to merge bgallois/duniter-v2s:weight-visualisation into master
Compare and
2 files
+ 63
0
Compare changes
  • Side-by-side
  • Inline
Files
2
+ 48
0
use glob::glob;
use std::path::Path;
use subweight_core::parse::overhead::Weight;
use subweight_core::parse::pallet::ChromaticExtrinsic;
use subweight_core::parse::storage::Weights;
use subweight_core::scope::Scope;
fn main() {
let pallet_weights = read_pallet_weight();
let db_weight = read_db_weight();
let overhead_weight = read_overhead_weight();
// Initialize scope
let mut scope = Scope::from_substrate();
scope = scope.with_storage_weights(db_weight.weights.read, db_weight.weights.write);
// Test
let test = pallet_weights[0][1].term;
println!("{:?}", test.eval(&scope));
}
fn read_pallet_weight() -> Vec<Vec<ChromaticExtrinsic>> {
let mut parsed_files = Vec::new();
for path in glob("../../runtime/common/src/weights/pallet_*")
.expect("No pallet found")
.filter_map(Result::ok)
{
let file = subweight_core::parse::pallet::parse_file(&path);
if let Ok(file) = file {
parsed_files.push(file);
}
}
parsed_files
}
fn read_db_weight() -> Weights {
subweight_core::parse::storage::parse_file(Path::new(
"../../runtime/common/src/weights/paritydb_weights.rs",
))
.expect("No DB weights")
}
fn read_overhead_weight() -> Weight {
subweight_core::parse::overhead::parse_file(Path::new(
"../../runtime/common/src/weights/block_weights.rs",
))
.expect("No overhead weight")
}
Loading