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 
27 namespace core
28 {
29 
30 namespace internal
31 {
32 
33 class PersistentStringCacheImpl;
34 class PersistentStringCacheStats;
35 
36 } // namespace internal
37 
43 {
44 public:
51  //{@
55  PersistentCacheStats& operator=(PersistentCacheStats const&);
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
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
Top-level namespace for core functionality.
Definition: persistent_cache.h:24
std::vector< uint32_t > Histogram
Histogram of the size distribution of cache entries.
Definition: persistent_cache_stats.h:201
STL namespace.
CacheDiscardPolicy
Indicates the discard policy to make room for entries when the cache is full.
Definition: cache_discard_policy.h:35
Class that provides (read-only) access to cache statistics and settings.
Definition: persistent_cache_stats.h:42