persistent_cache_stats.h
Go to the documentation of this file.
/*
* Copyright (C) 2015 Canonical Ltd.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License version 3 as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* Authored by: Michi Henning <michi.henning@canonical.com>
*/
#pragma once
#include <core/cache_discard_policy.h>
#include <chrono>
#include <memory>
#include <vector>
namespace core
{
namespace internal
{
class PersistentStringCacheImpl;
class PersistentStringCacheStats;
} // namespace internal
class PersistentCacheStats
{
public:
//{@
PersistentCacheStats();
PersistentCacheStats(PersistentCacheStats const&);
PersistentCacheStats(PersistentCacheStats&&) noexcept;
PersistentCacheStats& operator=(PersistentCacheStats const&);
PersistentCacheStats& operator=(PersistentCacheStats&&);
// Accessors instead of data members for ABI stability.
//{@
std::string cache_path() const;
CacheDiscardPolicy policy() const noexcept;
int64_t size() const noexcept;
int64_t size_in_bytes() const noexcept;
int64_t max_size_in_bytes() const noexcept;
int64_t hits() const noexcept;
int64_t misses() const noexcept;
int64_t hits_since_last_miss() const noexcept;
int64_t misses_since_last_hit() const noexcept;
int64_t longest_hit_run() const noexcept;
int64_t longest_miss_run() const noexcept;
int64_t hit_runs() const noexcept;
int64_t miss_runs() const noexcept;
double avg_hit_run_length() const noexcept;
double avg_miss_run_length() const noexcept;
int64_t ttl_evictions() const noexcept;
int64_t lru_evictions() const noexcept;
std::chrono::system_clock::time_point most_recent_hit_time() const noexcept;
std::chrono::system_clock::time_point most_recent_miss_time() const noexcept;
std::chrono::system_clock::time_point longest_hit_run_time() const noexcept;
std::chrono::system_clock::time_point longest_miss_run_time() const noexcept;
typedef std::vector<uint32_t> Histogram;
typedef std::vector<std::pair<int32_t, int32_t>> HistogramBounds;
static constexpr unsigned NUM_BINS = 74;
Histogram const& histogram() const noexcept;
static HistogramBounds const& histogram_bounds() noexcept;
private:
PersistentCacheStats(std::shared_ptr<core::internal::PersistentStringCacheStats> const& p) noexcept;
// We store a shared_ptr for efficiency. When the caller
// retrieves the stats, we set p_ to point at the PersistentStringCacheStats
// inside the cache. If the caller makes a copy or assigns,
// we create a new instance, to provide value semantics. This means
// that we don't have to copy all of the stats each time the caller
// gets them.
std::shared_ptr<internal::PersistentStringCacheStats const> p_;
bool internal_; // True if p_ points at the internal instance.
// @cond
friend class internal::PersistentStringCacheImpl; // For access to constructor
// @endcond
};
} // namespace core
cache_discard_policy.h
core::PersistentCacheStats::longest_miss_run
int64_t longest_miss_run() const noexcept
Returns the largest number of consecutive misses.
core::PersistentCacheStats::NUM_BINS
static constexpr unsigned NUM_BINS
The number of bins in a histogram.
Definition persistent_cache_stats.h:214
core::PersistentCacheStats::PersistentCacheStats
PersistentCacheStats(PersistentCacheStats const &)
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::hit_runs
int64_t hit_runs() const noexcept
Returns the number of hit runs.
core::PersistentCacheStats::hits
int64_t hits() const noexcept
Returns the number of hits since the statistics were last reset.
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::policy
CacheDiscardPolicy policy() const noexcept
Returns the discard policy (lru_only or lru_ttl).
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.
core::PersistentCacheStats::histogram_bounds
static HistogramBounds const & histogram_bounds() noexcept
Returns the bounds for each bin a histogram.
core::PersistentCacheStats::PersistentCacheStats
PersistentCacheStats()
core::PersistentCacheStats::max_size_in_bytes
int64_t max_size_in_bytes() const noexcept
Returns the maximum size of the cache.
core::PersistentCacheStats::size_in_bytes
int64_t size_in_bytes() const noexcept
Returns the size of all entries (including expired ones).
core::PersistentCacheStats::PersistentCacheStats
PersistentCacheStats(PersistentCacheStats &&) noexcept
core::PersistentCacheStats::histogram
Histogram const & histogram() const noexcept
Returns a histogram for the entries in the cache.
core::PersistentCacheStats::misses
int64_t misses() const noexcept
Returns the number of misses since the statistics were last reset.
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
core::PersistentCacheStats::avg_hit_run_length
double avg_hit_run_length() const noexcept
Returns a rolling average of the hit run length.
core::PersistentCacheStats::cache_path
std::string cache_path() const
Returns the path to the cache directory.
core::PersistentCacheStats::Histogram
std::vector< uint32_t > Histogram
Histogram of the size distribution of cache entries.
Definition persistent_cache_stats.h:201
core::PersistentCacheStats::ttl_evictions
int64_t ttl_evictions() const noexcept
Returns the number of entries that were evicted due to being expired.
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::size
int64_t size() const noexcept
Returns the number of entries (including expired ones).
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::longest_hit_run
int64_t longest_hit_run() const noexcept
Returns the largest number of consecutive hits.
core::PersistentCacheStats::miss_runs
int64_t miss_runs() const noexcept
Returns the number of miss runs.
core::PersistentCacheStats::avg_miss_run_length
double avg_miss_run_length() const noexcept
Returns a rolling average of the miss run length.
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::lru_evictions
int64_t lru_evictions() const noexcept
Returns the number of entries that were evicted due to being least recently used.
core
Top-level namespace for core functionality.
Definition cache_codec.h:24
core::CacheDiscardPolicy
CacheDiscardPolicy
Indicates the discard policy to make room for entries when the cache is full.
Definition cache_discard_policy.h:36