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
12ee6f18
Unverified
Commit
12ee6f18
authored
1 year ago
by
bgallois
Browse files
Options
Downloads
Patches
Plain Diff
remove all unwrap
parent
99bfde6d
No related branches found
No related tags found
No related merge requests found
Pipeline
#35111
passed
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/src/lib.rs
+24
-20
24 additions, 20 deletions
resources/weight_analyzer/src/lib.rs
xtask/src/gen_doc.rs
+1
-0
1 addition, 0 deletions
xtask/src/gen_doc.rs
with
25 additions
and
20 deletions
resources/weight_analyzer/src/lib.rs
+
24
−
20
View file @
12ee6f18
...
@@ -52,10 +52,10 @@ pub struct WeightInfo {
...
@@ -52,10 +52,10 @@ pub struct WeightInfo {
pub
fn
analyze_weight
(
pub
fn
analyze_weight
(
folder_path
:
&
Path
,
folder_path
:
&
Path
,
max_block_weight
:
&
MaxBlockWeight
,
max_block_weight
:
&
MaxBlockWeight
,
)
->
HashMap
<
String
,
HashMap
<
String
,
WeightInfo
>>
{
)
->
Result
<
HashMap
<
String
,
HashMap
<
String
,
WeightInfo
>>
,
String
>
{
let
pallet_weights
=
read_pallet_weight
(
folder_path
);
let
pallet_weights
=
read_pallet_weight
(
folder_path
)
?
;
let
db_weight
=
read_db_weight
(
folder_path
);
let
db_weight
=
read_db_weight
(
folder_path
)
?
;
let
overhead_weights
=
read_overhead_weight
(
folder_path
);
let
overhead_weights
=
read_overhead_weight
(
folder_path
)
?
;
// Initialize scope with db weights
// Initialize scope with db weights
let
mut
scope
=
Scope
::
from_substrate
();
let
mut
scope
=
Scope
::
from_substrate
();
...
@@ -64,7 +64,7 @@ pub fn analyze_weight(
...
@@ -64,7 +64,7 @@ pub fn analyze_weight(
process
(
pallet_weights
,
scope
,
max_block_weight
,
&
overhead_weights
)
process
(
pallet_weights
,
scope
,
max_block_weight
,
&
overhead_weights
)
}
}
fn
read_pallet_weight
(
folder_path
:
&
Path
)
->
Vec
<
Vec
<
ChromaticExtrinsic
>>
{
fn
read_pallet_weight
(
folder_path
:
&
Path
)
->
Result
<
Vec
<
Vec
<
ChromaticExtrinsic
>>
,
String
>
{
let
mut
parsed_files
=
Vec
::
new
();
let
mut
parsed_files
=
Vec
::
new
();
for
path
in
glob
(
folder_path
.join
(
"*"
)
.to_str
()
.expect
(
"Invalid pallet path"
))
for
path
in
glob
(
folder_path
.join
(
"*"
)
.to_str
()
.expect
(
"Invalid pallet path"
))
.expect
(
"Invalid pallet pattern"
)
.expect
(
"Invalid pallet pattern"
)
...
@@ -76,19 +76,17 @@ fn read_pallet_weight(folder_path: &Path) -> Vec<Vec<ChromaticExtrinsic>> {
...
@@ -76,19 +76,17 @@ fn read_pallet_weight(folder_path: &Path) -> Vec<Vec<ChromaticExtrinsic>> {
}
}
}
}
if
parsed_files
.is_empty
()
{
if
parsed_files
.is_empty
()
{
panic!
(
"No pallet found"
);
return
Err
(
"No pallet found"
.into
()
);
}
}
parsed_files
Ok
(
parsed_files
)
}
}
fn
read_db_weight
(
folder_path
:
&
Path
)
->
Weights
{
fn
read_db_weight
(
folder_path
:
&
Path
)
->
Result
<
Weights
,
String
>
{
subweight_core
::
parse
::
storage
::
parse_file
(
folder_path
.join
(
"paritydb_weights.rs"
)
.as_path
())
subweight_core
::
parse
::
storage
::
parse_file
(
folder_path
.join
(
"paritydb_weights.rs"
)
.as_path
())
.expect
(
"No DB weights"
)
}
}
fn
read_overhead_weight
(
folder_path
:
&
Path
)
->
Weight
{
fn
read_overhead_weight
(
folder_path
:
&
Path
)
->
Result
<
Weight
,
String
>
{
subweight_core
::
parse
::
overhead
::
parse_file
(
folder_path
.join
(
"extrinsic_weights.rs"
)
.as_path
())
subweight_core
::
parse
::
overhead
::
parse_file
(
folder_path
.join
(
"extrinsic_weights.rs"
)
.as_path
())
.expect
(
"No overhead weight"
)
}
}
fn
evaluate_weight
(
fn
evaluate_weight
(
...
@@ -111,16 +109,14 @@ fn evaluate_weight(
...
@@ -111,16 +109,14 @@ fn evaluate_weight(
.term
.term
.simplify
(
subweight_core
::
Dimension
::
Time
)
.simplify
(
subweight_core
::
Dimension
::
Time
)
.expect
(
"Can't evaluate"
)
.expect
(
"Can't evaluate"
)
.eval
(
scope
)
.eval
(
scope
)
?
;
.unwrap
();
// Add base extrinsic overhead
// Add base extrinsic overhead
if
let
Weight
::
ExtrinsicBase
(
i
)
=
overhead
{
if
let
Weight
::
ExtrinsicBase
(
i
)
=
overhead
{
weight
+=
i
weight
+=
i
.simplify
(
subweight_core
::
Dimension
::
Time
)
.simplify
(
subweight_core
::
Dimension
::
Time
)
.expect
(
"Can't evaluate"
)
.expect
(
"Can't evaluate"
)
.eval
(
scope
)
.eval
(
scope
)
?
;
.unwrap
();
}
}
let
relative_weight
=
(
weight
as
f64
)
/
max_block_weight
*
100.
;
let
relative_weight
=
(
weight
as
f64
)
/
max_block_weight
*
100.
;
...
@@ -146,12 +142,12 @@ fn process(
...
@@ -146,12 +142,12 @@ fn process(
mut
scope
:
Scope
<
Term
<
u128
>>
,
mut
scope
:
Scope
<
Term
<
u128
>>
,
max_block_weight
:
&
MaxBlockWeight
,
max_block_weight
:
&
MaxBlockWeight
,
overhead
:
&
Weight
,
overhead
:
&
Weight
,
)
->
HashMap
<
String
,
HashMap
<
String
,
WeightInfo
>>
{
)
->
Result
<
HashMap
<
String
,
HashMap
<
String
,
WeightInfo
>>
,
String
>
{
let
mut
weight_by_pallet
:
HashMap
<
String
,
HashMap
<
String
,
WeightInfo
>>
=
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
,
overhead
)
.unwrap
()
;
evaluate_weight
(
j
,
&
mut
scope
,
max_block_weight
,
overhead
)
?
;
if
let
Some
(
i
)
=
weight_by_pallet
.get_mut
(
&
pallet
)
{
if
let
Some
(
i
)
=
weight_by_pallet
.get_mut
(
&
pallet
)
{
i
.insert
(
extrinsic
,
weight
);
i
.insert
(
extrinsic
,
weight
);
}
else
{
}
else
{
...
@@ -159,7 +155,7 @@ fn process(
...
@@ -159,7 +155,7 @@ fn process(
}
}
}
}
}
}
weight_by_pallet
Ok
(
weight_by_pallet
)
}
}
#[cfg(test)]
#[cfg(test)]
...
@@ -173,12 +169,20 @@ mod tests {
...
@@ -173,12 +169,20 @@ 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
assert!
(
weight_by_pallet
.clone
()
.unwrap
()
.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]
#[should_panic]
#[should_panic]
fn
should_not_works
()
{
fn
should_not_works
()
{
let
_
=
analyze_weight
(
Path
::
new
(
""
),
&
MaxBlockWeight
::
default
());
let
_
=
analyze_weight
(
Path
::
new
(
""
),
&
MaxBlockWeight
::
default
())
.unwrap
()
;
}
}
}
}
This diff is collapsed.
Click to expand it.
xtask/src/gen_doc.rs
+
1
−
0
View file @
12ee6f18
...
@@ -395,6 +395,7 @@ fn get_from_metadata_v14(
...
@@ -395,6 +395,7 @@ fn get_from_metadata_v14(
fn
get_weights
()
->
HashMap
<
String
,
HashMap
<
String
,
WeightInfo
>>
{
fn
get_weights
()
->
HashMap
<
String
,
HashMap
<
String
,
WeightInfo
>>
{
analyze_weight
(
Path
::
new
(
WEIGHT_FILEPATH
),
&
MaxBlockWeight
::
default
())
analyze_weight
(
Path
::
new
(
WEIGHT_FILEPATH
),
&
MaxBlockWeight
::
default
())
.expect
(
"Weights unavailable"
)
}
}
/// use template to render markdown file with runtime calls documentation
/// use template to render markdown file with runtime calls documentation
...
...
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