Skip to content
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

add cli param keys_limit #7

Merged
merged 2 commits into from
Apr 24, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
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
Loading