Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Duniter v2S
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Monitor
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
nodes
rust
Duniter v2S
Commits
1457b101
Unverified
Commit
1457b101
authored
1 year ago
by
bgallois
Browse files
Options
Downloads
Patches
Plain Diff
rework at a lib
parent
0da77060
No related branches found
No related tags found
No related merge requests found
Pipeline
#35041
failed
1 year ago
Stage: labels
Stage: quality
Stage: build
Stage: tests
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
resources/weight_analyzer/Cargo.toml
+4
-0
4 additions, 0 deletions
resources/weight_analyzer/Cargo.toml
resources/weight_analyzer/src/lib.rs
+54
-22
54 additions, 22 deletions
resources/weight_analyzer/src/lib.rs
with
58 additions
and
22 deletions
resources/weight_analyzer/Cargo.toml
+
4
−
0
View file @
1457b101
...
...
@@ -10,6 +10,10 @@ version = '0.0.0'
[workspace]
[lib]
name
=
"weightanalyzer"
path
=
"src/lib.rs"
[dependencies]
subweight-core
=
"3.3.1"
glob
=
"0.3.1"
This diff is collapsed.
Click to expand it.
resources/weight_analyzer/src/
main
.rs
→
resources/weight_analyzer/src/
lib
.rs
+
54
−
22
View file @
1457b101
...
...
@@ -17,45 +17,63 @@ pub struct WeightInfo {
pub
relative_weight
:
f64
,
}
fn
main
()
{
let
pallet_weights
=
read_pallet_weight
();
let
db_weight
=
read_db_weight
();
let
_overhead_weights
=
read_overhead_weight
();
/// Returns a HashMap <pallet_name, <extrinsic_name, weigh_info>>
/// of the analyzed weights.
///
/// # Arguments
///
/// * `folder_path` - A Path to a folder where the weight files are stored.
/// `paritydb_weights.rs` is mandatory and pallet weights should start by
/// `pallet_`.
///
/// # Examples
///
/// ```
/// let weight_by_pallet = analyze_weight(Path::new("../../runtime/common/src/weights/"));
/// println!("{:?}", weight_by_pallet);
/// ```
pub
fn
analyze_weight
(
folder_path
:
&
Path
)
->
Option
<
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
);
// Initialize scope with db weights
let
mut
scope
=
Scope
::
from_substrate
();
scope
=
scope
.with_storage_weights
(
db_weight
.weights.read
,
db_weight
.weights.write
);
let
weight_by_pallet
=
process
(
pallet_weights
,
scope
);
println!
(
"{:?}"
,
weight_by_pallet
);
process
(
pallet_weights
,
scope
)
}
fn
read_pallet_weight
()
->
Vec
<
Vec
<
ChromaticExtrinsic
>>
{
fn
read_pallet_weight
(
folder_path
:
&
Path
)
->
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
)
for
path
in
glob
(
folder_path
.join
(
"pallet_*"
)
.to_str
()
.expect
(
"Invalid pallet path"
),
)
.expect
(
"Invalid pallet pattern"
)
.filter_map
(
Result
::
ok
)
{
let
file
=
subweight_core
::
parse
::
pallet
::
parse_file
(
&
path
);
if
let
Ok
(
file
)
=
file
{
parsed_files
.push
(
file
);
}
}
if
parsed_files
.is_empty
()
{
panic!
(
"No pallet found"
);
}
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_db_weight
(
folder_path
:
&
Path
)
->
Weights
{
subweight_core
::
parse
::
storage
::
parse_file
(
folder_path
.join
(
"paritydb_weights.rs"
)
.as_path
())
.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
read_overhead_weight
(
folder_path
:
&
Path
)
->
Weight
{
subweight_core
::
parse
::
overhead
::
parse_file
(
folder_path
.join
(
"block_weights.rs"
)
.as_path
())
.expect
(
"No overhead weight"
)
}
fn
evaluate_weight
(
...
...
@@ -92,7 +110,10 @@ fn evaluate_weight(
fn
process
(
pallet_weights
:
Vec
<
Vec
<
ChromaticExtrinsic
>>
,
mut
scope
:
Scope
<
Term
<
u128
>>
,
)
->
HashMap
<
String
,
HashMap
<
String
,
WeightInfo
>>
{
)
->
Option
<
HashMap
<
String
,
HashMap
<
String
,
WeightInfo
>>>
{
if
pallet_weights
.is_empty
()
{
return
None
;
}
let
mut
weight_by_pallet
=
HashMap
::
new
();
for
i
in
pallet_weights
{
for
j
in
i
{
...
...
@@ -100,5 +121,16 @@ fn process(
weight_by_pallet
.insert
(
pallet
.clone
(),
HashMap
::
from
([(
extrinsic
.clone
(),
weight
)]));
}
}
weight_by_pallet
Some
(
weight_by_pallet
)
}
#[cfg(test)]
mod
tests
{
use
crate
::
analyze_weight
;
use
std
::
path
::
Path
;
#[test]
fn
should_works
()
{
let
weight_by_pallet
=
analyze_weight
(
Path
::
new
(
"../../runtime/common/src/weights/"
));
println!
(
"{:?}"
,
weight_by_pallet
);
// cargo test -- --nocapture
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment