persistent-cache-cpp
persistent_cache_stats.h
Go to the documentation of this file.
1/*
2 * Copyright (C) 2015 Canonical Ltd.
3 *
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU Lesser General Public License version 3 as
6 * published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU Lesser General Public License for more details.
12 *
13 * You should have received a copy of the GNU Lesser General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 *
16 * Authored by: Michi Henning <michi.henning@canonical.com>
17 */
18
19#pragma once
20
22
23#include <chrono>
24#include <memory>
25#include <vector>
26
27namespace core
28{
29
30namespace internal
31{
32
33class PersistentStringCacheImpl;
34class PersistentStringCacheStats;
35
36} // namespace internal
37
43{
44public:
51 //{@
58
59 // Accessors instead of data members for ABI stability.
63 //{@
67 std::string cache_path() const;
68
72 CacheDiscardPolicy policy() const noexcept;
73
77 int64_t size() const noexcept;
78
82 int64_t size_in_bytes() const noexcept;
83
87 int64_t max_size_in_bytes() const noexcept;
88
92 int64_t hits() const noexcept;
93
97 int64_t misses() const noexcept;
98
102 int64_t hits_since_last_miss() const noexcept;
103
107 int64_t misses_since_last_hit() const noexcept;
108
112 int64_t longest_hit_run() const noexcept;
113
117 int64_t longest_miss_run() const noexcept;
118
122 int64_t hit_runs() const noexcept;
123
127 int64_t miss_runs() const noexcept;
128
132 double avg_hit_run_length() const noexcept;
133
137 double avg_miss_run_length() const noexcept;
138
142 int64_t ttl_evictions() const noexcept;
143
148 int64_t lru_evictions() const noexcept;
149
153 std::chrono::system_clock::time_point most_recent_hit_time() const noexcept;
154
158 std::chrono::system_clock::time_point most_recent_miss_time() const noexcept;
159
163 std::chrono::system_clock::time_point longest_hit_run_time() const noexcept;
164
168 std::chrono::system_clock::time_point longest_miss_run_time() const noexcept;
169
201 typedef std::vector<uint32_t> Histogram;
202
209 typedef std::vector<std::pair<int32_t, int32_t>> HistogramBounds;
210
214 static constexpr unsigned NUM_BINS = 74;
215
219 Histogram const& histogram() const noexcept;
220
229 static HistogramBounds const& histogram_bounds() noexcept;
230
232
233private:
234 PersistentCacheStats(std::shared_ptr<core::internal::PersistentStringCacheStats> const& p) noexcept;
235
236 // We store a shared_ptr for efficiency. When the caller
237 // retrieves the stats, we set p_ to point at the PersistentStringCacheStats
238 // inside the cache. If the caller makes a copy or assigns,
239 // we create a new instance, to provide value semantics. This means
240 // that we don't have to copy all of the stats each time the caller
241 // gets them.
242 std::shared_ptr<internal::PersistentStringCacheStats const> p_;
243 bool internal_; // True if p_ points at the internal instance.
244
245 // @cond
246 friend class internal::PersistentStringCacheImpl; // For access to constructor
247 // @endcond
248};
249
250} // namespace core
Class that provides (read-only) access to cache statistics and settings.
Definition persistent_cache_stats.h:43
int64_t longest_miss_run() const noexcept
Returns the largest number of consecutive misses.
static constexpr unsigned NUM_BINS
The number of bins in a histogram.
Definition persistent_cache_stats.h:214
PersistentCacheStats(PersistentCacheStats const &)
std::chrono::system_clock::time_point most_recent_miss_time() const noexcept
Returns the timestamp of the most recent miss.
int64_t hit_runs() const noexcept
Returns the number of hit runs.
int64_t hits() const noexcept
Returns the number of hits since the statistics were last reset.
int64_t hits_since_last_miss() const noexcept
Returns the number of consecutive hits since the last miss.
CacheDiscardPolicy policy() const noexcept
Returns the discard policy (lru_only or lru_ttl).
std::chrono::system_clock::time_point longest_hit_run_time() const noexcept
Returns the time of the longest hit run.
static HistogramBounds const & histogram_bounds() noexcept
Returns the bounds for each bin a histogram.
int64_t max_size_in_bytes() const noexcept
Returns the maximum size of the cache.
int64_t size_in_bytes() const noexcept
Returns the size of all entries (including expired ones).
PersistentCacheStats(PersistentCacheStats &&) noexcept
Histogram const & histogram() const noexcept
Returns a histogram for the entries in the cache.
int64_t misses() const noexcept
Returns the number of misses since the statistics were last reset.
std::vector< std::pair< int32_t, int32_t > > HistogramBounds
Lower and upper bounds for the bins in the histogram.
Definition persistent_cache_stats.h:209
double avg_hit_run_length() const noexcept
Returns a rolling average of the hit run length.
std::string cache_path() const
Returns the path to the cache directory.
std::vector< uint32_t > Histogram
Histogram of the size distribution of cache entries.
Definition persistent_cache_stats.h:201
int64_t ttl_evictions() const noexcept
Returns the number of entries that were evicted due to being expired.
std::chrono::system_clock::time_point most_recent_hit_time() const noexcept
Returns the timestamp of the most recent hit.
int64_t size() const noexcept
Returns the number of entries (including expired ones).
std::chrono::system_clock::time_point longest_miss_run_time() const noexcept
Returns the time of the longest miss run.
int64_t longest_hit_run() const noexcept
Returns the largest number of consecutive hits.
int64_t miss_runs() const noexcept
Returns the number of miss runs.
double avg_miss_run_length() const noexcept
Returns a rolling average of the miss run length.
int64_t misses_since_last_hit() const noexcept
Returns the number of consecutive misses since the last hit.
int64_t lru_evictions() const noexcept
Returns the number of entries that were evicted due to being least recently used.
Top-level namespace for core functionality.
Definition cache_codec.h:24
CacheDiscardPolicy
Indicates the discard policy to make room for entries when the cache is full.
Definition cache_discard_policy.h:36