mirror of
https://github.com/matrix-construct/construct
synced 2024-11-16 15:00:51 +01:00
ircd::db: Expose an interface for some counters; add ticker command.
This commit is contained in:
parent
416d199736
commit
7b54dba291
3 changed files with 138 additions and 0 deletions
|
@ -28,6 +28,18 @@ namespace ircd::db
|
|||
template<class R = prop_int> 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);
|
||||
|
|
72
ircd/db.cc
72
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<std::string>
|
||||
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
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue