pub struct WorkloadStatistics { /* private fields */ }Expand description
A thread-safe statistical observer used to validate cache efficiency.
It captures the “Ground Truth” of a workload by counting every key access. This allows tests to compare the cache’s internal state against the mathematically ideal set of frequent items.
Implementations§
Source§impl WorkloadStatistics
impl WorkloadStatistics
Sourcepub fn record(&self, key: Bytes)
pub fn record(&self, key: Bytes)
Records access to a specific key.
In a concurrent test, multiple threads call this to build a global view of key popularity.
Sourcepub fn frequent_keys(&self, count: usize) -> Vec<Bytes>
pub fn frequent_keys(&self, count: usize) -> Vec<Bytes>
Retrieves the count most frequently accessed keys, ordered from
hottest to coldest.
This uses a Min-Heap (via Reverse) to maintain a sliding window of the
top elements, ensuring $O(N \log K)$ time complexity where $N$ is total
unique keys and $K$ is the requested count.
§Performance
This method is intended for use at the end of a test run, as it iterates over the entire frequency map.