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

add weights computation from weight files

parent 08fae8df
No related branches found
No related tags found
No related merge requests found
This commit is part of merge request !222. Comments created here will be created in the context of that merge request.
[package]
name = "weight-analyzer"
authors = ['Axiom-Team Developers <https://axiom-team.fr>']
description = 'Crypto-currency software (based on Substrate framework) to operate Ğ1 libre currency'
edition = "2021"
homepage = 'https://duniter.org'
license = 'AGPL-3.0'
repository = 'https://git.duniter.org/nodes/rust/duniter-v2s'
version = '0.0.0'
[workspace]
[dependencies]
subweight-core = "3.3.1"
glob = "0.3.1"
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;
use subweight_core::term::Term;
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
// 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();
println!(
"Pallet: {:?} ; Extrinsic: {:?} ; Weight: {:?}",
pallet, extrinsic, weight
);
}
}
}
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")
}
fn evaluate_weight(
extrinsic: ChromaticExtrinsic,
scope: &Scope<Term<u128>>,
) -> Result<(String, String, u128), String> {
let weight = extrinsic
.term
.simplify(subweight_core::Dimension::Time)
.expect("Can't evaluate")
.eval(scope)
.unwrap();
Ok((extrinsic.pallet, extrinsic.name, weight))
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment