0
0
Fork 0
mirror of https://github.com/matrix-construct/construct synced 2024-11-04 21:08:57 +01:00

ircd::db: Add interface to count cache entries.

modules/console: Add count column to db cache cmd.
This commit is contained in:
Jason Volk 2020-09-07 17:21:10 -07:00
parent ab58cedc09
commit a68702249d
3 changed files with 58 additions and 0 deletions

View file

@ -41,6 +41,10 @@ namespace ircd::db
size_t pinned(const rocksdb::Cache &); size_t pinned(const rocksdb::Cache &);
size_t pinned(const rocksdb::Cache *const &); size_t pinned(const rocksdb::Cache *const &);
// Get number of entries
size_t count(const rocksdb::Cache &);
size_t count(const rocksdb::Cache *const &);
// Test if key exists // Test if key exists
bool exists(const rocksdb::Cache &, const string_view &key); bool exists(const rocksdb::Cache &, const string_view &key);
bool exists(const rocksdb::Cache *const &, const string_view &key); bool exists(const rocksdb::Cache *const &, const string_view &key);
@ -133,6 +137,14 @@ ircd::db::exists(const rocksdb::Cache *const &cache,
false; false;
} }
inline size_t
ircd::db::count(const rocksdb::Cache *const &cache)
{
return cache?
count(*cache):
0UL;
}
inline size_t inline size_t
ircd::db::pinned(const rocksdb::Cache *const &cache) ircd::db::pinned(const rocksdb::Cache *const &cache)
{ {

View file

@ -7569,6 +7569,19 @@ ircd::db::exists(const rocksdb::Cache &cache_,
return bool(handle); return bool(handle);
} }
size_t
ircd::db::count(const rocksdb::Cache &cache)
{
size_t ret(0);
for_each(cache, [&ret]
(const const_buffer &)
{
++ret;
});
return ret;
}
size_t size_t
ircd::db::pinned(const rocksdb::Cache &cache) ircd::db::pinned(const rocksdb::Cache &cache)
{ {

View file

@ -3728,6 +3728,7 @@ try
struct stats struct stats
{ {
size_t count;
size_t usage; size_t usage;
size_t pinned; size_t pinned;
size_t capacity; size_t capacity;
@ -3738,6 +3739,7 @@ try
stats &operator+=(const stats &b) stats &operator+=(const stats &b)
{ {
count += b.count;
usage += b.usage; usage += b.usage;
pinned += b.pinned; pinned += b.pinned;
capacity += b.capacity; capacity += b.capacity;
@ -3751,6 +3753,7 @@ try
if(!colname) if(!colname)
{ {
const auto count(db::count(cache(database)));
const auto usage(db::usage(cache(database))); const auto usage(db::usage(cache(database)));
const auto pinned(db::pinned(cache(database))); const auto pinned(db::pinned(cache(database)));
const auto capacity(db::capacity(cache(database))); const auto capacity(db::capacity(cache(database)));
@ -3778,6 +3781,11 @@ try
inserts > 0.0? (double(hits) / double(inserts)) : 0.0L inserts > 0.0? (double(hits) / double(inserts)) : 0.0L
}; };
const auto ins_cnt_rat
{
count > 0.0? (double(inserts) / double(count)) : 0.0L
};
out << std::left out << std::left
<< std::setw(24) << "ROW" << std::setw(24) << "ROW"
<< std::right << std::right
@ -3802,6 +3810,10 @@ try
<< " " << " "
<< std::setw(9) << "INSERT%" << std::setw(9) << "INSERT%"
<< " " << " "
<< std::setw(8) << "COUNT"
<< " "
<< std::setw(10) << "INS:CNT"
<< " "
<< std::setw(20) << "LOCKED" << std::setw(20) << "LOCKED"
<< " " << " "
<< std::endl; << std::endl;
@ -3834,6 +3846,11 @@ try
<< std::setw(8) << std::right << std::fixed << std::setprecision(2) << (ins_miss_pct * 100) << std::setw(8) << std::right << std::fixed << std::setprecision(2) << (ins_miss_pct * 100)
<< "%" << "%"
<< " " << " "
<< std::setw(8) << std::right << count
<< " "
<< std::setw(8) << std::right << std::fixed << std::setprecision(0) << ins_cnt_rat
<< ":1"
<< " "
<< std::setw(20) << std::right << pretty(iec(pinned)) << std::setw(20) << std::right << pretty(iec(pinned))
<< " " << " "
<< std::endl << std::endl
@ -3868,6 +3885,10 @@ try
<< " " << " "
<< std::setw(9) << "INSERT%" << std::setw(9) << "INSERT%"
<< " " << " "
<< std::setw(8) << "COUNT"
<< " "
<< std::setw(10) << "INS:CNT"
<< " "
<< std::setw(20) << "LOCKED" << std::setw(20) << "LOCKED"
<< " " << " "
<< std::endl; << std::endl;
@ -3895,6 +3916,11 @@ try
s.inserts > 0.0? (double(s.hits) / double(s.inserts)) : 0.0L s.inserts > 0.0? (double(s.hits) / double(s.inserts)) : 0.0L
}; };
const auto ins_cnt_rat
{
s.count > 0.0? (double(s.inserts) / double(s.count)) : 0.0L
};
out << std::setw(24) << std::left << column_name out << std::setw(24) << std::left << column_name
<< std::right << std::right
<< " " << " "
@ -3922,6 +3948,11 @@ try
<< std::setw(8) << std::right << std::fixed << std::setprecision(2) << (ins_miss_pct * 100) << std::setw(8) << std::right << std::fixed << std::setprecision(2) << (ins_miss_pct * 100)
<< '%' << '%'
<< " " << " "
<< std::setw(8) << std::right << s.count
<< " "
<< std::setw(8) << std::right << std::fixed << std::setprecision(0) << ins_cnt_rat
<< ":1"
<< " "
<< std::setw(20) << std::right << pretty(iec(s.pinned)) << std::setw(20) << std::right << pretty(iec(s.pinned))
<< " " << " "
<< std::endl; << std::endl;
@ -3955,6 +3986,7 @@ try
const stats uncompressed const stats uncompressed
{ {
db::count(cache(column)),
db::usage(cache(column)), db::usage(cache(column)),
db::pinned(cache(column)), db::pinned(cache(column)),
db::capacity(cache(column)), db::capacity(cache(column)),
@ -3966,6 +3998,7 @@ try
const stats compressed const stats compressed
{ {
db::count(cache_compressed(column)),
db::usage(cache_compressed(column)), db::usage(cache_compressed(column)),
0, 0,
db::capacity(cache_compressed(column)), db::capacity(cache_compressed(column)),