diff --git a/include/gcache/ghost_kv_cache.h b/include/gcache/ghost_kv_cache.h index f36947d..87537fc 100644 --- a/include/gcache/ghost_kv_cache.h +++ b/include/gcache/ghost_kv_cache.h @@ -64,22 +64,21 @@ class SampledGhostKvCache { void reset_stat() { ghost_cache.reset_stat(); } - [[nodiscard]] const std::vector< - std::tuple> - get_miss_rate_curve() const { - std::vector> mrc; + [[nodiscard]] const std::vector> + get_cache_stat_curve() const { + std::vector> curve; uint32_t curr_count = 0; uint32_t curr_size = 0; ghost_cache.unsafe_for_each_mru([&](Handle_t h) { curr_size += h->kv_size; ++curr_count; if ((curr_count - ghost_cache.min_size) % ghost_cache.tick == 0) { - mrc.emplace_back( - curr_count << SampleShift, curr_size << SampleShift, - ghost_cache.get_stat_shifted(curr_count).get_miss_rate()); + curve.emplace_back(curr_count << SampleShift, curr_size << SampleShift, + ghost_cache.get_stat_shifted(curr_count)); } }); - return mrc; + return curve; // should be implicitly moved by compiler // avoid explict move for Return Value Optimization (RVO) } diff --git a/tests/test_ghost_kv.cpp b/tests/test_ghost_kv.cpp index f52218c..0650de9 100644 --- a/tests/test_ghost_kv.cpp +++ b/tests/test_ghost_kv.cpp @@ -61,20 +61,20 @@ void bench1() { << "-------------------------------------------------------------" << "-----------------------\n"; - auto mrc = sampled_ghost_kv_cache.get_miss_rate_curve(); + auto curve = sampled_ghost_kv_cache.get_cache_stat_curve(); for (uint32_t s = tick; s <= bench_size; s += tick) { std::cout << std::setw(5) << s / 1024 << "K|"; ghost_cache.get_stat(s).print(std::cout, 8); std::cout << '|'; sampled_ghost_kv_cache.get_stat(s).print(std::cout, 8); std::cout << '|'; - auto [count, size, miss_rate] = mrc[s / tick - 1]; + auto [count, size, cache_stat] = curve[s / tick - 1]; assert(count == s); - if (miss_rate == std::numeric_limits::infinity()) { + if (cache_stat.hit_cnt == 0) { std::cout << " NAN"; } else { std::cout << std::setw(5) << std::fixed << std::setprecision(1) - << (1 - miss_rate) * 100 << '%'; + << cache_stat.get_hit_rate() * 100 << '%'; } std::cout << " @" << std::setw(7) << std::fixed << size / 1024 / 1024 << 'M' << std::setw(5) << std::fixed << size / count << std::endl;