From 2a3363d52eab5d1f83fa45fbd6b295c9a66061a4 Mon Sep 17 00:00:00 2001 From: Siying Dong Date: Mon, 2 Oct 2017 09:40:00 -0700 Subject: [PATCH] ldb dump can print histogram of value size Summary: Make "ldb dump --count_only" print histogram of value size. Also, fix a bug that "ldb dump --path=" doesn't work. Closes https://github.com/facebook/rocksdb/pull/2944 Differential Revision: D5954527 Pulled By: siying fbshipit-source-id: c620a444ec544258b8d113f5f663c375dd53d6be --- tools/ldb_cmd.cc | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/tools/ldb_cmd.cc b/tools/ldb_cmd.cc index c8b6221a5..4c4b596c7 100644 --- a/tools/ldb_cmd.cc +++ b/tools/ldb_cmd.cc @@ -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_; + } } } @@ -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 @@ -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_) { @@ -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; }