diff --git a/core/bin/zksync_core/src/state_keeper/root_hash_calculator/mod.rs b/core/bin/zksync_core/src/state_keeper/root_hash_calculator/mod.rs index 9b6e7c69e0..46e037727b 100644 --- a/core/bin/zksync_core/src/state_keeper/root_hash_calculator/mod.rs +++ b/core/bin/zksync_core/src/state_keeper/root_hash_calculator/mod.rs @@ -102,6 +102,16 @@ impl RootHashCalculator { job.block.0 as f64, "stage" => "root_hash_calculator" ); + self.report_memory_stats(); + } + + fn report_memory_stats(&self) { + let memory_stats = self.state.tree_memory_stats(); + metrics::histogram!("tree_memory_usage", memory_stats.allocated_total as f64, "type" => "total"); + metrics::histogram!("tree_memory_usage", memory_stats.items as f64, "type" => "items"); + metrics::histogram!("tree_memory_usage", memory_stats.nodes as f64, "type" => "nodes"); + metrics::histogram!("tree_memory_usage", memory_stats.prehashed as f64, "type" => "prehashed"); + metrics::histogram!("tree_memory_usage", memory_stats.cache as f64, "type" => "cache"); } } diff --git a/core/lib/state/src/state.rs b/core/lib/state/src/state.rs index f5222cbafd..70c9e86589 100644 --- a/core/lib/state/src/state.rs +++ b/core/lib/state/src/state.rs @@ -1,7 +1,7 @@ use num::BigUint; use std::collections::{HashMap, HashSet}; -use zksync_crypto::{params, params::NFT_STORAGE_ACCOUNT_ID, Fr}; +use zksync_crypto::{merkle_tree::TreeMemoryUsage, params, params::NFT_STORAGE_ACCOUNT_ID, Fr}; use zksync_types::{ helpers::reverse_updates, operations::{TransferOp, TransferToNewOp, ZkSyncOp}, @@ -111,6 +111,10 @@ impl ZkSyncState { } } + pub fn tree_memory_stats(&self) -> TreeMemoryUsage { + self.balance_tree.memory_stats() + } + pub fn get_accounts(&self) -> Vec<(u32, Account)> { self.balance_tree .items