0
0
Fork 0
mirror of https://github.com/matrix-construct/construct synced 2024-11-29 10:12:39 +01:00

ircd::db: Add custom cache stats ticker.

This commit is contained in:
Jason Volk 2018-09-05 02:56:50 -07:00
parent 4067809a9a
commit 66edb4a7fb
3 changed files with 49 additions and 2 deletions

View file

@ -21,6 +21,12 @@
namespace ircd::db
{
struct cache_stats;
// Get our stats
const cache_stats &stats(const rocksdb::Cache &);
cache_stats stats(const rocksdb::Cache *const &);
// Get capacity
size_t capacity(const rocksdb::Cache &);
size_t capacity(const rocksdb::Cache *const &);
@ -58,3 +64,13 @@ namespace ircd::db
void clear(rocksdb::Cache &);
void clear(rocksdb::Cache *const &);
}
/// Our custom cache statistics. Though the rocksdb::Statistics ticker could
/// be instantiated for each cache we have our own counters, and we let the
/// rocksdb cache impl update our database ticker instead for aggregate stats.
struct ircd::db::cache_stats
{
size_t inserts {0};
size_t misses {0};
size_t hits {0};
};

View file

@ -34,6 +34,7 @@ final
static const bool DEFAULT_STRICT;
database *d;
cache_stats stats;
std::shared_ptr<rocksdb::Cache> c;
const char *Name() const noexcept override;

View file

@ -2066,7 +2066,13 @@ ircd::db::database::cache::Insert(const Slice &key,
noexcept
{
assert(bool(c));
return c->Insert(key, value, charge, del, handle, priority);
const rocksdb::Status &ret
{
c->Insert(key, value, charge, del, handle, priority)
};
stats.inserts += ret.ok();
return ret;
}
rocksdb::Cache::Handle *
@ -2075,7 +2081,14 @@ ircd::db::database::cache::Lookup(const Slice &key,
noexcept
{
assert(bool(c));
return c->Lookup(key, statistics);
auto *const &ret
{
c->Lookup(key, statistics)
};
stats.hits += bool(ret);
stats.misses += !bool(ret);
return ret;
}
bool
@ -8217,6 +8230,23 @@ ircd::db::capacity(const rocksdb::Cache &cache)
return cache.GetCapacity();
}
ircd::db::cache_stats
ircd::db::stats(const rocksdb::Cache *const &cache)
{
return cache? stats(*cache) : cache_stats{};
}
const ircd::db::cache_stats &
ircd::db::stats(const rocksdb::Cache &cache)
{
const auto &dc
{
dynamic_cast<const database::cache &>(cache)
};
return dc.stats;
}
///////////////////////////////////////////////////////////////////////////////
//
// Misc