mirror of
https://github.com/matrix-construct/construct
synced 2024-06-25 21:38:18 +02:00
ircd::db: Add interface to count cache entries.
modules/console: Add count column to db cache cmd.
This commit is contained in:
parent
ab58cedc09
commit
a68702249d
|
@ -41,6 +41,10 @@ namespace ircd::db
|
|||
size_t pinned(const rocksdb::Cache &);
|
||||
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
|
||||
bool exists(const rocksdb::Cache &, 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;
|
||||
}
|
||||
|
||||
inline size_t
|
||||
ircd::db::count(const rocksdb::Cache *const &cache)
|
||||
{
|
||||
return cache?
|
||||
count(*cache):
|
||||
0UL;
|
||||
}
|
||||
|
||||
inline size_t
|
||||
ircd::db::pinned(const rocksdb::Cache *const &cache)
|
||||
{
|
||||
|
|
13
ircd/db.cc
13
ircd/db.cc
|
@ -7569,6 +7569,19 @@ ircd::db::exists(const rocksdb::Cache &cache_,
|
|||
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
|
||||
ircd::db::pinned(const rocksdb::Cache &cache)
|
||||
{
|
||||
|
|
|
@ -3728,6 +3728,7 @@ try
|
|||
|
||||
struct stats
|
||||
{
|
||||
size_t count;
|
||||
size_t usage;
|
||||
size_t pinned;
|
||||
size_t capacity;
|
||||
|
@ -3738,6 +3739,7 @@ try
|
|||
|
||||
stats &operator+=(const stats &b)
|
||||
{
|
||||
count += b.count;
|
||||
usage += b.usage;
|
||||
pinned += b.pinned;
|
||||
capacity += b.capacity;
|
||||
|
@ -3751,6 +3753,7 @@ try
|
|||
|
||||
if(!colname)
|
||||
{
|
||||
const auto count(db::count(cache(database)));
|
||||
const auto usage(db::usage(cache(database)));
|
||||
const auto pinned(db::pinned(cache(database)));
|
||||
const auto capacity(db::capacity(cache(database)));
|
||||
|
@ -3778,6 +3781,11 @@ try
|
|||
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
|
||||
<< std::setw(24) << "ROW"
|
||||
<< std::right
|
||||
|
@ -3802,6 +3810,10 @@ try
|
|||
<< " "
|
||||
<< std::setw(9) << "INSERT%"
|
||||
<< " "
|
||||
<< std::setw(8) << "COUNT"
|
||||
<< " "
|
||||
<< std::setw(10) << "INS:CNT"
|
||||
<< " "
|
||||
<< std::setw(20) << "LOCKED"
|
||||
<< " "
|
||||
<< 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 << count
|
||||
<< " "
|
||||
<< std::setw(8) << std::right << std::fixed << std::setprecision(0) << ins_cnt_rat
|
||||
<< ":1"
|
||||
<< " "
|
||||
<< std::setw(20) << std::right << pretty(iec(pinned))
|
||||
<< " "
|
||||
<< std::endl
|
||||
|
@ -3868,6 +3885,10 @@ try
|
|||
<< " "
|
||||
<< std::setw(9) << "INSERT%"
|
||||
<< " "
|
||||
<< std::setw(8) << "COUNT"
|
||||
<< " "
|
||||
<< std::setw(10) << "INS:CNT"
|
||||
<< " "
|
||||
<< std::setw(20) << "LOCKED"
|
||||
<< " "
|
||||
<< std::endl;
|
||||
|
@ -3895,6 +3916,11 @@ try
|
|||
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
|
||||
<< 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 << 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::endl;
|
||||
|
@ -3955,6 +3986,7 @@ try
|
|||
|
||||
const stats uncompressed
|
||||
{
|
||||
db::count(cache(column)),
|
||||
db::usage(cache(column)),
|
||||
db::pinned(cache(column)),
|
||||
db::capacity(cache(column)),
|
||||
|
@ -3966,6 +3998,7 @@ try
|
|||
|
||||
const stats compressed
|
||||
{
|
||||
db::count(cache_compressed(column)),
|
||||
db::usage(cache_compressed(column)),
|
||||
0,
|
||||
db::capacity(cache_compressed(column)),
|
||||
|
|
Loading…
Reference in a new issue