Skip to content

fix bencher key tracker #749

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 25, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions bencher/src/handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,9 @@ pub fn handle(output: Vec<u8>, storage_infos: Vec<StorageInfo>) {
let name = String::from_utf8(info.storage_name.clone()).unwrap();
let comment = format!("{}::{} (r: {}, w: {})", pallet, name, reads, writes);
comments.push(comment);
} else {
let comment = format!("Unknown (r: {}, w: {})", reads, writes);
comments.push(comment);
}
});

Expand Down
6 changes: 4 additions & 2 deletions bencher/src/tracker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,8 @@ impl BenchTracker {
let mut summary = HashMap::<StorageKey, AccessReport>::new();

self.main_keys.read().iter().for_each(|(key, info)| {
let prefix = key[0..32].to_vec();
let prefix_end = core::cmp::min(32, key.len());
let prefix = key[0..prefix_end].to_vec();
if let Some(report) = summary.get_mut(&prefix) {
if info.read.is_important() {
report.read += 1;
Expand All @@ -241,7 +242,8 @@ impl BenchTracker {

self.child_keys.read().iter().for_each(|(prefix, keys)| {
keys.iter().for_each(|(key, info)| {
let prefix = [prefix.clone(), key.clone()].concat()[0..32].to_vec();
let prefix_end = core::cmp::min(32, prefix.len() + key.len());
let prefix = [prefix.clone(), key.clone()].concat()[0..prefix_end].to_vec();
if let Some(report) = summary.get_mut(&prefix) {
if info.read.is_important() {
report.read += 1;
Expand Down
1 change: 1 addition & 0 deletions bencher/test/src/mock.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#![cfg(any(test, feature = "bench"))]

use frame_support::pallet_prelude::ConstU32;
use sp_core::H256;
use sp_runtime::{
traits::{BlakeTwo256, IdentityLookup},
Expand Down