diff --git a/include/ircd/db/database/rocksdb.h b/include/ircd/db/database/rocksdb.h index d7996b81a..648edebb0 100644 --- a/include/ircd/db/database/rocksdb.h +++ b/include/ircd/db/database/rocksdb.h @@ -31,6 +31,7 @@ namespace rocksdb struct Slice; struct Checkpoint; struct SstFileManager; + struct PerfContext; } // diff --git a/include/ircd/db/db.h b/include/ircd/db/db.h index eafedc05a..daca89db1 100644 --- a/include/ircd/db/db.h +++ b/include/ircd/db/db.h @@ -87,7 +87,10 @@ namespace ircd::db std::string path(const std::string &name); std::vector available(); - void log_rdb_perf_context(const bool &all = true); + uint perf_level(); + void perf_level(const uint &); + const rocksdb::PerfContext &perf_current(); + std::string string(const rocksdb::PerfContext &, const bool &all = false); string_view reflect(const pos &); } diff --git a/ircd/db.cc b/ircd/db.cc index 557453f08..b126418e7 100644 --- a/ircd/db.cc +++ b/ircd/db.cc @@ -1304,17 +1304,49 @@ catch(const std::exception &e) // database::stats // -void -ircd::db::log_rdb_perf_context(const bool &all) +std::string +ircd::db::string(const rocksdb::PerfContext &pc, + const bool &all) { - const auto pc + const bool exclude_zeros(!all); + return pc.ToString(exclude_zeros); +} + +const rocksdb::PerfContext & +ircd::db::perf_current() +{ + const auto *const &ret { rocksdb::get_perf_context() }; - assert(pc); - const bool exclude_zeros(!all); - log.debug("%s", pc->ToString(exclude_zeros)); + if(unlikely(!ret)) + throw error + { + "Performance counters are not available on this thread." + }; + + return *ret; +} + +void +ircd::db::perf_level(const uint &level) +{ + if(level >= rocksdb::PerfLevel::kOutOfBounds) + throw error + { + "Perf level of '%u' is invalid; maximum is '%u'", + level, + uint(rocksdb::PerfLevel::kOutOfBounds) + }; + + rocksdb::SetPerfLevel(rocksdb::PerfLevel(level)); +} + +uint +ircd::db::perf_level() +{ + return rocksdb::GetPerfLevel(); } uint32_t diff --git a/modules/console.cc b/modules/console.cc index 3f22bf3db..0d33ab60b 100644 --- a/modules/console.cc +++ b/modules/console.cc @@ -1130,6 +1130,47 @@ catch(const std::out_of_range &e) return true; } +bool +console_cmd__db__perf(opt &out, const string_view &line) +{ + const auto &pc + { + db::perf_current() + }; + + out << db::string(pc) << std::endl; + return true; +} + +bool +console_cmd__db__perf__level(opt &out, const string_view &line) +{ + const params param{line, " ", + { + "[level]" + }}; + + if(!param.count()) + { + const auto &level + { + db::perf_level() + }; + + out << "Current level is: " << level << std::endl; + return true; + } + + const auto &level + { + param.at(0) + }; + + db::perf_level(level); + out << "Set level to: " << level << std::endl; + return true; +} + bool console_cmd__db__prop(opt &out, const string_view &line) try