From fd0a1c44aa40b581bc37070a77d68487b5094c3c Mon Sep 17 00:00:00 2001 From: Paul Hauner Date: Fri, 17 Jan 2020 14:59:42 +1100 Subject: [PATCH] Add cache metrics --- .../beacon_chain/src/fork_choice/checkpoint_manager.rs | 6 +++++- beacon_node/beacon_chain/src/metrics.rs | 4 ++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/beacon_node/beacon_chain/src/fork_choice/checkpoint_manager.rs b/beacon_node/beacon_chain/src/fork_choice/checkpoint_manager.rs index 00b4513e55..33211f62c1 100644 --- a/beacon_node/beacon_chain/src/fork_choice/checkpoint_manager.rs +++ b/beacon_node/beacon_chain/src/fork_choice/checkpoint_manager.rs @@ -1,5 +1,5 @@ use super::Error; -use crate::{BeaconChain, BeaconChainTypes}; +use crate::{metrics, BeaconChain, BeaconChainTypes}; use proto_array_fork_choice::ProtoArrayForkChoice; use ssz_derive::{Decode, Encode}; use types::{BeaconState, Checkpoint, Epoch, EthSpec, Hash256, Slot}; @@ -201,8 +201,12 @@ impl CheckpointManager { chain: &BeaconChain, ) -> Result, Error> { if let Some(balances) = self.balances_cache.get(block_root) { + metrics::inc_counter(&metrics::BALANCES_CACHE_HITS); + Ok(balances) } else { + metrics::inc_counter(&metrics::BALANCES_CACHE_MISSES); + let block = chain .get_block_caching(&block_root)? .ok_or_else(|| Error::UnknownJustifiedBlock(block_root))?; diff --git a/beacon_node/beacon_chain/src/metrics.rs b/beacon_node/beacon_chain/src/metrics.rs index 7ad92bf151..72b1fdbc1c 100644 --- a/beacon_node/beacon_chain/src/metrics.rs +++ b/beacon_node/beacon_chain/src/metrics.rs @@ -138,6 +138,10 @@ lazy_static! { "beacon_fork_choice_process_attestation_seconds", "Time taken to add an attestation to fork choice" ); + pub static ref BALANCES_CACHE_HITS: Result = + try_create_int_counter("beacon_balances_cache_hits_total", "Count of times balances cache fulfils request"); + pub static ref BALANCES_CACHE_MISSES: Result = + try_create_int_counter("beacon_balances_cache_misses_total", "Count of times balances cache fulfils request"); /* * Persisting BeaconChain to disk