Skip to content

Commit

Permalink
ldb dump can print histogram of value size
Browse files Browse the repository at this point in the history
Summary:
Make "ldb dump --count_only" print histogram of value size. Also, fix a bug that "ldb dump --path=<db_path>" doesn't work.
Closes facebook#2944

Differential Revision: D5954527

Pulled By: siying

fbshipit-source-id: c620a444ec544258b8d113f5f663c375dd53d6be
  • Loading branch information
siying authored and facebook-github-bot committed Oct 2, 2017
1 parent 593d3de commit 2a3363d
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion tools/ldb_cmd.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1353,6 +1353,9 @@ DBDumperCommand::DBDumperCommand(
itr = options.find(ARG_PATH);
if (itr != options.end()) {
path_ = itr->second;
if (db_path_.empty()) {
db_path_ = path_;
}
}
}

Expand Down Expand Up @@ -1485,6 +1488,8 @@ void DBDumperCommand::DoDumpCommand() {
ReadableTime(ttl_start).c_str(), ReadableTime(ttl_end).c_str());
}

HistogramImpl vsize_hist;

for (; iter->Valid(); iter->Next()) {
int rawtime = 0;
// If end marker was specified, we stop before it
Expand Down Expand Up @@ -1529,7 +1534,9 @@ void DBDumperCommand::DoDumpCommand() {

}


if (count_only_) {
vsize_hist.Add(iter->value().size());
}

if (!count_only_ && !count_delim_) {
if (is_db_ttl_ && timestamp_) {
Expand All @@ -1551,6 +1558,11 @@ void DBDumperCommand::DoDumpCommand() {
} else {
fprintf(stdout, "Keys in range: %lld\n", (long long) count);
}

if (count_only_) {
fprintf(stdout, "Value size distribution: \n");
fprintf(stdout, "%s\n", vsize_hist.ToString().c_str());
}
// Clean up
delete iter;
}
Expand Down

0 comments on commit 2a3363d

Please sign in to comment.