Skip to content

Commit

Permalink
Report tree memory usage to prometheus
Browse files Browse the repository at this point in the history
  • Loading branch information
popzxc committed Feb 1, 2022
1 parent 965d6f4 commit 4f59399
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
10 changes: 10 additions & 0 deletions core/bin/zksync_core/src/state_keeper/root_hash_calculator/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}
}

Expand Down
6 changes: 5 additions & 1 deletion core/lib/state/src/state.rs
Original file line number Diff line number Diff line change
@@ -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},
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 4f59399

Please sign in to comment.