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
722e570b
Unverified
Commit
722e570b
authored
1 year ago
by
bgallois
Browse files
Options
Downloads
Patches
Plain Diff
fix weight analyzer
parent
b328921f
No related branches found
No related tags found
No related merge requests found
Pipeline
#35096
failed
1 year ago
Stage: labels
Stage: quality
Stage: build
Stage: tests
Changes
2
Pipelines
1
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
resources/weight_analyzer/Cargo.toml
+2
-0
2 additions, 0 deletions
resources/weight_analyzer/Cargo.toml
resources/weight_analyzer/src/lib.rs
+21
-12
21 additions, 12 deletions
resources/weight_analyzer/src/lib.rs
with
23 additions
and
12 deletions
resources/weight_analyzer/Cargo.toml
+
2
−
0
View file @
722e570b
...
@@ -14,4 +14,6 @@ path = "src/lib.rs"
...
@@ -14,4 +14,6 @@ path = "src/lib.rs"
[dependencies]
[dependencies]
subweight-core
=
"3.3.1"
subweight-core
=
"3.3.1"
convert_case
=
"0.6.0"
glob
=
"0.3.1"
glob
=
"0.3.1"
serde
=
{
version
=
"1.0.101"
,
features
=
[
"derive"
]
}
This diff is collapsed.
Click to expand it.
resources/weight_analyzer/src/lib.rs
+
21
−
12
View file @
722e570b
use
convert_case
::{
Case
,
Casing
};
use
glob
::
glob
;
use
glob
::
glob
;
use
serde
::
Serialize
;
use
std
::
collections
::
HashMap
;
use
std
::
collections
::
HashMap
;
use
std
::
ops
::
Div
;
use
std
::
ops
::
Div
;
use
std
::
path
::
Path
;
use
std
::
path
::
Path
;
...
@@ -22,7 +24,7 @@ impl Div<&MaxBlockWeight> for f64 {
...
@@ -22,7 +24,7 @@ impl Div<&MaxBlockWeight> for f64 {
}
}
}
}
#[derive(
Debug
)]
#[derive(
Clone,
Debug,
Serialize
)]
pub
struct
WeightInfo
{
pub
struct
WeightInfo
{
pub
weight
:
u128
,
pub
weight
:
u128
,
pub
relative_weight
:
f64
,
pub
relative_weight
:
f64
,
...
@@ -64,12 +66,7 @@ pub fn analyze_weight(
...
@@ -64,12 +66,7 @@ pub fn analyze_weight(
fn
read_pallet_weight
(
folder_path
:
&
Path
)
->
Vec
<
Vec
<
ChromaticExtrinsic
>>
{
fn
read_pallet_weight
(
folder_path
:
&
Path
)
->
Vec
<
Vec
<
ChromaticExtrinsic
>>
{
let
mut
parsed_files
=
Vec
::
new
();
let
mut
parsed_files
=
Vec
::
new
();
for
path
in
glob
(
for
path
in
glob
(
folder_path
.join
(
"*"
)
.to_str
()
.expect
(
"Invalid pallet path"
))
folder_path
.join
(
"pallet_*"
)
.to_str
()
.expect
(
"Invalid pallet path"
),
)
.expect
(
"Invalid pallet pattern"
)
.expect
(
"Invalid pallet pattern"
)
.filter_map
(
Result
::
ok
)
.filter_map
(
Result
::
ok
)
{
{
...
@@ -117,7 +114,14 @@ fn evaluate_weight(
...
@@ -117,7 +114,14 @@ fn evaluate_weight(
.unwrap
();
.unwrap
();
let
relative_weight
=
(
weight
as
f64
)
/
max_block_weight
*
100.
;
let
relative_weight
=
(
weight
as
f64
)
/
max_block_weight
*
100.
;
Ok
((
Ok
((
extrinsic
.pallet
,
extrinsic
.pallet
.to_case
(
Case
::
Title
)
.replace
(
"Pallet"
,
""
)
.replace
(
".rs"
,
""
)
.chars
()
.filter
(|
c
|
!
c
.is_whitespace
())
.collect
(),
extrinsic
.name
,
extrinsic
.name
,
WeightInfo
{
WeightInfo
{
weight
,
weight
,
...
@@ -131,12 +135,16 @@ fn process(
...
@@ -131,12 +135,16 @@ fn process(
mut
scope
:
Scope
<
Term
<
u128
>>
,
mut
scope
:
Scope
<
Term
<
u128
>>
,
max_block_weight
:
&
MaxBlockWeight
,
max_block_weight
:
&
MaxBlockWeight
,
)
->
HashMap
<
String
,
HashMap
<
String
,
WeightInfo
>>
{
)
->
HashMap
<
String
,
HashMap
<
String
,
WeightInfo
>>
{
let
mut
weight_by_pallet
=
HashMap
::
new
();
let
mut
weight_by_pallet
:
HashMap
<
String
,
HashMap
<
String
,
WeightInfo
>>
=
HashMap
::
new
();
for
i
in
pallet_weights
{
for
i
in
pallet_weights
{
for
j
in
i
{
for
j
in
i
{
let
(
pallet
,
extrinsic
,
weight
)
=
let
(
pallet
,
extrinsic
,
weight
)
=
evaluate_weight
(
j
,
&
mut
scope
,
max_block_weight
)
.unwrap
();
evaluate_weight
(
j
,
&
mut
scope
,
max_block_weight
)
.unwrap
();
weight_by_pallet
.insert
(
pallet
.clone
(),
HashMap
::
from
([(
extrinsic
.clone
(),
weight
)]));
if
let
Some
(
i
)
=
weight_by_pallet
.get_mut
(
&
pallet
)
{
i
.insert
(
extrinsic
,
weight
);
}
else
{
weight_by_pallet
.insert
(
pallet
,
HashMap
::
from
([(
extrinsic
,
weight
)]));
}
}
}
}
}
weight_by_pallet
weight_by_pallet
...
@@ -153,6 +161,7 @@ mod tests {
...
@@ -153,6 +161,7 @@ mod tests {
Path
::
new
(
"../../runtime/common/src/weights/"
),
Path
::
new
(
"../../runtime/common/src/weights/"
),
&
MaxBlockWeight
::
default
(),
&
MaxBlockWeight
::
default
(),
);
);
assert!
(
weight_by_pallet
.get
(
"Balances"
)
.unwrap
()
.len
()
==
7
);
// 7 extrinsics in pallet
println!
(
"{:?}"
,
weight_by_pallet
);
// cargo test -- --nocapture
println!
(
"{:?}"
,
weight_by_pallet
);
// cargo test -- --nocapture
}
}
#[test]
#[test]
...
...
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