From 4618f57fa2ba13b1e1a8dec83afd01c00ae4c867 Mon Sep 17 00:00:00 2001 From: evenyag Date: Thu, 29 Aug 2024 00:56:05 +0800 Subject: [PATCH] feat: add timer metrics --- src/mito2/src/cache.rs | 6 +++++- src/mito2/src/metrics.rs | 2 ++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/src/mito2/src/cache.rs b/src/mito2/src/cache.rs index 051e44015e04..e623b75c9074 100644 --- a/src/mito2/src/cache.rs +++ b/src/mito2/src/cache.rs @@ -38,7 +38,9 @@ use crate::cache::cache_size::parquet_meta_size; use crate::cache::file_cache::{FileType, IndexKey}; use crate::cache::index::{InvertedIndexCache, InvertedIndexCacheRef}; use crate::cache::write_cache::WriteCacheRef; -use crate::metrics::{CACHE_BYTES, CACHE_EVICTION, CACHE_HIT, CACHE_MISS}; +use crate::metrics::{ + CACHE_BYTES, CACHE_EVICTION, CACHE_HIT, CACHE_MISS, GET_CACHE_ELAPSED, PUT_CACHE_ELAPSED, +}; use crate::read::Batch; use crate::sst::file::FileId; @@ -158,6 +160,7 @@ impl CacheManager { /// Gets pages for the row group. pub fn get_pages(&self, page_key: &PageKey) -> Option> { + let _timer = GET_CACHE_ELAPSED.start_timer(); self.page_cache.as_ref().and_then(|page_cache| { let value = page_cache.get(page_key); update_hit_miss(value, PAGE_TYPE) @@ -166,6 +169,7 @@ impl CacheManager { /// Puts pages of the row group into the cache. pub fn put_pages(&self, page_key: PageKey, pages: Arc) { + let _timer = PUT_CACHE_ELAPSED.start_timer(); if let Some(cache) = &self.page_cache { CACHE_BYTES .with_label_values(&[PAGE_TYPE]) diff --git a/src/mito2/src/metrics.rs b/src/mito2/src/metrics.rs index 963330948955..15d0e3988f5a 100644 --- a/src/mito2/src/metrics.rs +++ b/src/mito2/src/metrics.rs @@ -133,6 +133,8 @@ lazy_static! { vec![0.005, 0.01, 0.05, 0.1, 0.5, 1.0, 5.0, 10.0, 60.0, 300.0] ) .unwrap(); + pub static ref GET_CACHE_ELAPSED: Histogram = READ_STAGE_ELAPSED.with_label_values(&["get_cache"]); + pub static ref PUT_CACHE_ELAPSED: Histogram = READ_STAGE_ELAPSED.with_label_values(&["put_cache"]); /// Counter of rows read from different source. pub static ref READ_ROWS_TOTAL: IntCounterVec = register_int_counter_vec!("greptime_mito_read_rows_total", "mito read rows total", &[TYPE_LABEL]).unwrap();