0
0
Fork 0
mirror of https://github.com/matrix-construct/construct synced 2024-06-29 15:28:20 +02:00

ircd::db: Elaborate interface to the rocksdb perf_context.

This commit is contained in:
Jason Volk 2018-05-23 16:27:44 -07:00
parent 60bd4f2346
commit 1c20df652b
4 changed files with 84 additions and 7 deletions

View file

@ -31,6 +31,7 @@ namespace rocksdb
struct Slice;
struct Checkpoint;
struct SstFileManager;
struct PerfContext;
}
//

View file

@ -87,7 +87,10 @@ namespace ircd::db
std::string path(const std::string &name);
std::vector<std::string> 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 &);
}

View file

@ -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

View file

@ -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<uint>(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