diff --git a/include/ircd/db/database/database.h b/include/ircd/db/database/database.h index b7adeeb15..38aa3ab84 100644 --- a/include/ircd/db/database/database.h +++ b/include/ircd/db/database/database.h @@ -28,6 +28,18 @@ namespace ircd::db template R property(const database &, const string_view &name); template<> prop_int property(const database &, const string_view &name); + // Ticker + extern const uint32_t ticker_max; + string_view ticker_id(const uint32_t &id); + uint32_t ticker_id(const string_view &key); + uint64_t ticker(const database &, const uint32_t &id); + uint64_t ticker(const database &, const string_view &key); + + // Histogram + extern const uint32_t histogram_max; + string_view histogram_id(const uint32_t &id); + uint32_t histogram_id(const string_view &key); + // Control panel void compact(database &); void fdeletions(database &, const bool &enable); diff --git a/ircd/db.cc b/ircd/db.cc index 35cbbff3d..68a0152b8 100644 --- a/ircd/db.cc +++ b/ircd/db.cc @@ -192,6 +192,20 @@ ircd::db::compact(database &d) compact(*column, string_view{}, string_view{}); } +uint64_t +ircd::db::ticker(const database &d, + const string_view &key) +{ + return ticker(d, ticker_id(key)); +} + +uint64_t +ircd::db::ticker(const database &d, + const uint32_t &id) +{ + return d.stats->getTickerCount(id); +} + /// Get the live file list for db; see overlord documentation. std::vector ircd::db::files(const database &d) @@ -1171,6 +1185,64 @@ ircd::db::log_rdb_perf_context(const bool &all) log.debug("%s", pc->ToString(exclude_zeros)); } +uint32_t +ircd::db::ticker_id(const string_view &key) +{ + for(const auto &pair : rocksdb::TickersNameMap) + if(key == pair.second) + return pair.first; + + throw std::out_of_range + { + "No ticker with that key" + }; +} + +ircd::string_view +ircd::db::ticker_id(const uint32_t &id) +{ + for(const auto &pair : rocksdb::TickersNameMap) + if(id == pair.first) + return pair.second; + + return {}; +} + +decltype(ircd::db::ticker_max) +ircd::db::ticker_max +{ + rocksdb::TICKER_ENUM_MAX +}; + +uint32_t +ircd::db::histogram_id(const string_view &key) +{ + for(const auto &pair : rocksdb::HistogramsNameMap) + if(key == pair.second) + return pair.first; + + throw std::out_of_range + { + "No histogram with that key" + }; +} + +ircd::string_view +ircd::db::histogram_id(const uint32_t &id) +{ + for(const auto &pair : rocksdb::HistogramsNameMap) + if(id == pair.first) + return pair.second; + + return {}; +} + +decltype(ircd::db::histogram_max) +ircd::db::histogram_max +{ + rocksdb::HISTOGRAM_ENUM_MAX +}; + uint64_t ircd::db::database::stats::getAndResetTickerCount(const uint32_t type) noexcept diff --git a/modules/console.cc b/modules/console.cc index 92f50797e..520a91e17 100644 --- a/modules/console.cc +++ b/modules/console.cc @@ -638,6 +638,60 @@ catch(const std::out_of_range &e) return true; } +bool +console_cmd__db__ticker(opt &out, const string_view &line) +try +{ + const params param{line, " ", + { + "dbname", "[ticker]" + }}; + + const auto dbname + { + param.at(0) + }; + + const auto ticker + { + param[1] + }; + + auto &database + { + *db::database::dbs.at(dbname) + }; + + // Special branch for integer properties that RocksDB aggregates. + if(!empty(ticker)) + { + out << ticker << ": " << db::ticker(database, ticker) << std::endl; + return true; + } + + for(uint32_t i(0); i < db::ticker_max; ++i) + { + const string_view &name + { + db::ticker_id(i) + }; + + if(!name) + continue; + + out << std::setw(48) << std::right << name + << " " << db::ticker(database, i) + << std::endl; + } + + return true; +} +catch(const std::out_of_range &e) +{ + out << "No open database by that name" << std::endl; + return true; +} + bool console_cmd__db__prop(opt &out, const string_view &line) try