Skip to content

Commit

Permalink
add get_miss_rate APIs
Browse files Browse the repository at this point in the history
  • Loading branch information
chenhao-ye committed Apr 2, 2024
1 parent 7295617 commit 8127545
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions include/gcache/ghost_cache.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,13 @@ struct CacheStat {
if (acc_cnt == 0) return std::numeric_limits<double>::infinity();
return double(hit_cnt) / double(acc_cnt);
}

[[nodiscard]] double get_miss_rate() const {
uint64_t acc_cnt = hit_cnt + miss_cnt;
if (acc_cnt == 0) return std::numeric_limits<double>::infinity();
return double(miss_cnt) / double(acc_cnt);
}

void reset() {
hit_cnt = 0;
miss_cnt = 0;
Expand Down Expand Up @@ -113,6 +120,9 @@ class GhostCache {
[[nodiscard]] double get_hit_rate(uint32_t cache_size) const {
return get_stat(cache_size).get_hit_rate();
}
[[nodiscard]] double get_miss_rate(uint32_t cache_size) const {
return get_stat(cache_size).get_miss_rate();
}

[[nodiscard]] const CacheStat& get_stat(uint32_t cache_size) const {
assert(cache_size >= min_size);
Expand Down Expand Up @@ -163,6 +173,9 @@ class SampledGhostCache : public GhostCache {
double get_hit_rate(uint32_t cache_size) const {
return get_stat(cache_size).get_hit_rate();
}
double get_miss_rate(uint32_t cache_size) const {
return get_stat(cache_size).get_miss_rate();
}

const CacheStat& get_stat(uint32_t cache_size) const {
cache_size >>= SampleShift;
Expand Down

0 comments on commit 8127545

Please sign in to comment.