Skip to content

Commit

Permalink
info keyspace display statistics cost time (OpenAtomFoundation#520)
Browse files Browse the repository at this point in the history
  • Loading branch information
Axlgrep authored Mar 5, 2019
1 parent 4136989 commit 51fa23e
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 1 deletion.
2 changes: 2 additions & 0 deletions include/pika_server.h
Original file line number Diff line number Diff line change
Expand Up @@ -304,11 +304,13 @@ class PikaServer {
struct KeyScanInfo {
time_t start_time;
std::string s_start_time;
int32_t duration;
std::vector<blackwidow::KeyInfo> key_infos; //the order is strings, hashes, lists, zsets, sets
bool key_scaning_;
KeyScanInfo() :
start_time(0),
s_start_time("1970-01-01 08:00:00"),
duration(-1),
key_infos({{0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}}),
key_scaning_(false) {
}
Expand Down
4 changes: 3 additions & 1 deletion src/pika_admin.cc
Original file line number Diff line number Diff line change
Expand Up @@ -801,14 +801,16 @@ void InfoCmd::InfoKeyspace(std::string &info) {
}

PikaServer::KeyScanInfo key_scan_info = g_pika_server->key_scan_info();
int32_t duration = key_scan_info.duration;
std::vector<blackwidow::KeyInfo>& key_infos = key_scan_info.key_infos;
if (key_infos.size() != 5) {
info.append("info keyspace error\r\n");
return;
}
std::stringstream tmp_stream;
tmp_stream << "# Keyspace\r\n";
tmp_stream << "# Time:" << key_scan_info.s_start_time << "\r\n";
tmp_stream << "# Time: " << key_scan_info.s_start_time << "\r\n";
tmp_stream << "# Duration: " << (duration == -1 ? "In Processing" : std::to_string(duration) + "s" )<< "\r\n";
tmp_stream << "Strings: keys=" << key_infos[0].keys << ", expires=" << key_infos[0].expires << ", invaild_keys=" << key_infos[0].invaild_keys << "\r\n";
tmp_stream << "Hashes: keys=" << key_infos[1].keys << ", expires=" << key_infos[1].expires << ", invaild_keys=" << key_infos[1].invaild_keys << "\r\n";
tmp_stream << "Lists: keys=" << key_infos[2].keys << ", expires=" << key_infos[2].expires << ", invaild_keys=" << key_infos[2].invaild_keys << "\r\n";
Expand Down
2 changes: 2 additions & 0 deletions src/pika_server.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1639,6 +1639,7 @@ void PikaServer::RunKeyScan() {
slash::MutexLock lm(&key_scan_protector_);
if (s.ok()) {
key_scan_info_.key_infos = new_key_infos;
key_scan_info_.duration = time(NULL) - key_scan_info_.start_time;
}
key_scan_info_.key_scaning_ = false;
}
Expand Down Expand Up @@ -1675,6 +1676,7 @@ void PikaServer::InitKeyScan() {
char s_time[32];
int len = strftime(s_time, sizeof(s_time), "%Y-%m-%d %H:%M:%S", localtime(&key_scan_info_.start_time));
key_scan_info_.s_start_time.assign(s_time, len);
key_scan_info_.duration = -1;
}

void PikaServer::ClientKillAll() {
Expand Down

0 comments on commit 51fa23e

Please sign in to comment.