From a68702249d4edde5b409fab1c376bf4c73aa3bde Mon Sep 17 00:00:00 2001 From: Jason Volk Date: Mon, 7 Sep 2020 17:21:10 -0700 Subject: [PATCH] ircd::db: Add interface to count cache entries. modules/console: Add count column to db cache cmd. --- include/ircd/db/cache.h | 12 ++++++++++++ ircd/db.cc | 13 +++++++++++++ modules/console.cc | 33 +++++++++++++++++++++++++++++++++ 3 files changed, 58 insertions(+) diff --git a/include/ircd/db/cache.h b/include/ircd/db/cache.h index 1d4420037..3743bec5d 100644 --- a/include/ircd/db/cache.h +++ b/include/ircd/db/cache.h @@ -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) { diff --git a/ircd/db.cc b/ircd/db.cc index 8492f0cb9..f7ac6a739 100644 --- a/ircd/db.cc +++ b/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) { diff --git a/modules/console.cc b/modules/console.cc index 1e7575faf..59da0a6c7 100644 --- a/modules/console.cc +++ b/modules/console.cc @@ -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)),