Skip to content

Commit

Permalink
add cli param keys_limit
Browse files Browse the repository at this point in the history
  • Loading branch information
librelois committed Apr 23, 2024
1 parent b1a8ee8 commit 6aca526
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 5 deletions.
11 changes: 10 additions & 1 deletion substrate/utils/frame/benchmarking-cli/src/storage/cmd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,11 @@ pub struct StorageParams {
/// Include child trees in benchmark.
#[arg(long)]
pub include_child_trees: bool,

/// Maximum number of keys to read
/// (All keys if not define)
#[arg(long)]
pub keys_limit: Option<usize>,
}

impl StorageCmd {
Expand Down Expand Up @@ -191,7 +196,11 @@ impl StorageCmd {
BA: ClientBackend<B>,
{
let hash = client.usage_info().chain.best_hash;
let mut keys: Vec<_> = client.storage_keys(hash, None, None)?.collect();
let mut keys: Vec<_> = if let Some(keys_limit) = self.params.keys_limit {
client.storage_keys(hash, None, None)?.take(keys_limit).collect()
} else {
client.storage_keys(hash, None, None)?.collect()
};
let (mut rng, _) = new_rng(None);
keys.shuffle(&mut rng);

Expand Down
8 changes: 6 additions & 2 deletions substrate/utils/frame/benchmarking-cli/src/storage/read.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,12 @@ impl StorageCmd {
let best_hash = client.usage_info().chain.best_hash;

info!("Preparing keys from block {}", best_hash);
// Load all keys and randomly shuffle them.
let mut keys: Vec<_> = client.storage_keys(best_hash, None, None)?.collect();
// Load keys and randomly shuffle them.
let mut keys: Vec<_> = if let Some(keys_limit) = self.params.keys_limit {
client.storage_keys(best_hash, None, None)?.take(keys_limit).collect()
} else {
client.storage_keys(best_hash, None, None)?.collect()
};
let (mut rng, _) = new_rng(None);
keys.shuffle(&mut rng);

Expand Down
8 changes: 6 additions & 2 deletions substrate/utils/frame/benchmarking-cli/src/storage/write.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,12 @@ impl StorageCmd {
let trie = DbStateBuilder::<Block>::new(storage.clone(), original_root).build();

info!("Preparing keys from block {}", best_hash);
// Load all KV pairs and randomly shuffle them.
let mut kvs: Vec<_> = trie.pairs(Default::default())?.collect();
// Load KV pairs and randomly shuffle them.
let mut kvs: Vec<_> = if let Some(keys_limit) = self.params.keys_limit {
trie.pairs(Default::default())?.take(keys_limit).collect()
} else {
trie.pairs(Default::default())?.collect()
};
let (mut rng, _) = new_rng(None);
kvs.shuffle(&mut rng);
info!("Writing {} keys", kvs.len());
Expand Down

0 comments on commit 6aca526

Please sign in to comment.