persistent-cache-cpp: /build/persistent-cache-cpp-git/src/persistent-cache-cpp/include/core/persistent_cache_stats.h Source File

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
21 #include <core/cache_discard_policy.h>
22
23 #include <chrono>
24 #include <memory>
25 #include <vector>
26
27 namespace core
28 {
29
30 namespace internal
31 {
32
33 class PersistentStringCacheImpl;
34 class PersistentStringCacheStats;
35
36 } // namespace internal
37
42 class PersistentCacheStats
43 {
44 public:
51 //{@
52 PersistentCacheStats();
53 PersistentCacheStats(PersistentCacheStats const&);
54 PersistentCacheStats(PersistentCacheStats&&) noexcept;
55 PersistentCacheStats& operator=(PersistentCacheStats const&);
56 PersistentCacheStats& operator=(PersistentCacheStats&&);
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
233 private:
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
core::PersistentCacheStats::policy
CacheDiscardPolicy policy() const noexcept
Returns the discard policy (lru_only or lru_ttl).
core::PersistentCacheStats::HistogramBounds
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
cache_discard_policy.h
core::PersistentCacheStats::size
int64_t size() const noexcept
Returns the number of entries (including expired ones).
core::PersistentCacheStats::most_recent_hit_time
std::chrono::system_clock::time_point most_recent_hit_time() const noexcept
Returns the timestamp of the most recent hit.
core::PersistentCacheStats::Histogram
std::vector< uint32_t > Histogram
Histogram of the size distribution of cache entries.
Definition: persistent_cache_stats.h:201
core::CacheDiscardPolicy
CacheDiscardPolicy
Indicates the discard policy to make room for entries when the cache is full.
Definition: cache_discard_policy.h:36
core::PersistentCacheStats::NUM_BINS
static constexpr unsigned NUM_BINS
The number of bins in a histogram.
Definition: persistent_cache_stats.h:214
core::PersistentCacheStats::longest_miss_run_time
std::chrono::system_clock::time_point longest_miss_run_time() const noexcept
Returns the time of the longest miss run.
core::PersistentCacheStats::hits_since_last_miss
int64_t hits_since_last_miss() const noexcept
Returns the number of consecutive hits since the last miss.
core::PersistentCacheStats
Class that provides (read-only) access to cache statistics and settings.
Definition: persistent_cache_stats.h:43
core::PersistentCacheStats::longest_hit_run
int64_t longest_hit_run() const noexcept
Returns the largest number of consecutive hits.
core::PersistentCacheStats::misses
int64_t misses() const noexcept
Returns the number of misses since the statistics were last reset.
core::PersistentCacheStats::size_in_bytes
int64_t size_in_bytes() const noexcept
Returns the size of all entries (including expired ones).
core::PersistentCacheStats::ttl_evictions
int64_t ttl_evictions() const noexcept
Returns the number of entries that were evicted due to being expired.
core::PersistentCacheStats::lru_evictions
int64_t lru_evictions() const noexcept
Returns the number of entries that were evicted due to being least recently used.
core::PersistentCacheStats::avg_miss_run_length
double avg_miss_run_length() const noexcept
Returns a rolling average of the miss run length.
core::PersistentCacheStats::max_size_in_bytes
int64_t max_size_in_bytes() const noexcept
Returns the maximum size of the cache.
core::PersistentCacheStats::hits
int64_t hits() const noexcept
Returns the number of hits since the statistics were last reset.
core::PersistentCacheStats::PersistentCacheStats
PersistentCacheStats(PersistentCacheStats &&) noexcept
core
Top-level namespace for core functionality.
Definition: cache_codec.h:24
core::PersistentCacheStats::avg_hit_run_length
double avg_hit_run_length() const noexcept
Returns a rolling average of the hit run length.
core::PersistentCacheStats::PersistentCacheStats
PersistentCacheStats()
core::PersistentCacheStats::cache_path
std::string cache_path() const
Returns the path to the cache directory.
core::PersistentCacheStats::longest_miss_run
int64_t longest_miss_run() const noexcept
Returns the largest number of consecutive misses.
core::PersistentCacheStats::most_recent_miss_time
std::chrono::system_clock::time_point most_recent_miss_time() const noexcept
Returns the timestamp of the most recent miss.
core::PersistentCacheStats::misses_since_last_hit
int64_t misses_since_last_hit() const noexcept
Returns the number of consecutive misses since the last hit.
core::PersistentCacheStats::miss_runs
int64_t miss_runs() const noexcept
Returns the number of miss runs.
core::PersistentCacheStats::hit_runs
int64_t hit_runs() const noexcept
Returns the number of hit runs.
core::PersistentCacheStats::PersistentCacheStats
PersistentCacheStats(PersistentCacheStats const &)
core::PersistentCacheStats::histogram
Histogram const & histogram() const noexcept
Returns a histogram for the entries in the cache.
core::PersistentCacheStats::histogram_bounds
static HistogramBounds const & histogram_bounds() noexcept
Returns the bounds for each bin a histogram.
core::PersistentCacheStats::longest_hit_run_time
std::chrono::system_clock::time_point longest_hit_run_time() const noexcept
Returns the time of the longest hit run.