Make RecordIn/RecordOut human readable

Summary: I had hard time understanding these big numbers. Here's how the output looks like now: https://gist.github.com/igorcanadi/4c39c17685049584a992

Test Plan: db_bench

Reviewers: sdong, MarkCallaghan

Reviewed By: MarkCallaghan

Subscribers: dhruba, leveldb

Differential Revision: https://reviews.facebook.net/D35073
This commit is contained in:
Igor Canadi 2015-03-14 15:12:41 -07:00
parent c8da670325
commit c6967a1a5e
3 changed files with 34 additions and 12 deletions

View file

@ -33,9 +33,9 @@ void PrintLevelStatsHeader(char* buf, size_t len, const std::string& cf_name) {
"Level Files Size(MB) Score Read(GB) Rn(GB) Rnp1(GB) " "Level Files Size(MB) Score Read(GB) Rn(GB) Rnp1(GB) "
"Write(GB) Wnew(GB) Moved(GB) W-Amp Rd(MB/s) Wr(MB/s) " "Write(GB) Wnew(GB) Moved(GB) W-Amp Rd(MB/s) Wr(MB/s) "
"Comp(sec) Comp(cnt) Avg(sec) " "Comp(sec) Comp(cnt) Avg(sec) "
"Stall(cnt) RecordIn RecordDrop\n" "Stall(cnt) KeyIn KeyDrop\n"
"--------------------------------------------------------------------"
"--------------------------------------------------------------------" "--------------------------------------------------------------------"
"-----------------------------------------------------------"
"--------------------------------------\n", "--------------------------------------\n",
cf_name.c_str()); cf_name.c_str());
} }
@ -47,6 +47,9 @@ void PrintLevelStats(char* buf, size_t len, const std::string& name,
uint64_t bytes_read = stats.bytes_readn + stats.bytes_readnp1; uint64_t bytes_read = stats.bytes_readn + stats.bytes_readnp1;
int64_t bytes_new = stats.bytes_written - stats.bytes_readnp1; int64_t bytes_new = stats.bytes_written - stats.bytes_readnp1;
double elapsed = (stats.micros + 1) / 1000000.0; double elapsed = (stats.micros + 1) / 1000000.0;
std::string num_input_records = NumberToHumanString(stats.num_input_records);
std::string num_dropped_records =
NumberToHumanString(stats.num_dropped_records);
snprintf(buf, len, snprintf(buf, len,
"%4s %5d/%-3d %8.0f %5.1f " /* Level, Files, Size(MB), Score */ "%4s %5d/%-3d %8.0f %5.1f " /* Level, Files, Size(MB), Score */
@ -64,22 +67,19 @@ void PrintLevelStats(char* buf, size_t len, const std::string& name,
"%8.3f " /* Avg(sec) */ "%8.3f " /* Avg(sec) */
"%10" PRIu64 "%10" PRIu64
" " /* Stall(cnt) */ " " /* Stall(cnt) */
"%12" PRIu64 "%7s " /* KeyIn */
" " /* input entries */ "%6s\n", /* KeyDrop */
"%12" PRIu64 "\n" /* number of records reduced */,
name.c_str(), num_files, being_compacted, total_file_size / kMB, name.c_str(), num_files, being_compacted, total_file_size / kMB,
score, bytes_read / kGB, stats.bytes_readn / kGB, score, bytes_read / kGB, stats.bytes_readn / kGB,
stats.bytes_readnp1 / kGB, stats.bytes_written / kGB, stats.bytes_readnp1 / kGB, stats.bytes_written / kGB,
bytes_new / kGB, stats.bytes_moved / kGB, bytes_new / kGB, stats.bytes_moved / kGB,
w_amp, bytes_read / kMB / elapsed, w_amp, bytes_read / kMB / elapsed,
stats.bytes_written / kMB / elapsed, stats.bytes_written / kMB / elapsed, stats.micros / 1000000.0,
stats.micros / 1000000.0, stats.count, stats.count,
stats.count == 0 ? 0 : stats.micros / 1000000.0 / stats.count, stats.count == 0 ? 0 : stats.micros / 1000000.0 / stats.count,
stalls, stalls,
stats.num_input_records, stats.num_dropped_records); num_input_records.c_str(), num_dropped_records.c_str());
} }
} }
DBPropertyType GetPropertyType(const Slice& property, bool* is_int_property, DBPropertyType GetPropertyType(const Slice& property, bool* is_int_property,

View file

@ -13,6 +13,7 @@
#define __STDC_FORMAT_MACROS #define __STDC_FORMAT_MACROS
#endif #endif
#include <cmath>
#include <inttypes.h> #include <inttypes.h>
#include <errno.h> #include <errno.h>
#include <stdarg.h> #include <stdarg.h>
@ -95,6 +96,21 @@ std::string NumberToString(uint64_t num) {
return r; return r;
} }
std::string NumberToHumanString(int64_t num) {
char buf[16];
int64_t absnum = num < 0 ? -num : num;
if (absnum < 10000) {
snprintf(buf, sizeof(buf), "%" PRIi64, num);
} else if (absnum < 10000000) {
snprintf(buf, sizeof(buf), "%" PRIi64 "K", num / 1000);
} else if (absnum < 10000000000LL) {
snprintf(buf, sizeof(buf), "%" PRIi64 "M", num / 1000000);
} else {
snprintf(buf, sizeof(buf), "%" PRIi64 "G", num / 1000000000);
}
return std::string(buf);
}
std::string EscapeString(const Slice& value) { std::string EscapeString(const Slice& value) {
std::string r; std::string r;
AppendEscapedStringTo(&r, value); AppendEscapedStringTo(&r, value);

View file

@ -33,9 +33,15 @@ extern void AppendNumberTo(std::string* str, uint64_t num);
// Escapes any non-printable characters found in "value". // Escapes any non-printable characters found in "value".
extern void AppendEscapedStringTo(std::string* str, const Slice& value); extern void AppendEscapedStringTo(std::string* str, const Slice& value);
// Return a human-readable printout of "num" // Return a string printout of "num"
extern std::string NumberToString(uint64_t num); extern std::string NumberToString(uint64_t num);
// Return a human-readable version of num.
// for num >= 10.000, prints "xxK"
// for num >= 10.000.000, prints "xxM"
// for num >= 10.000.000.000, prints "xxG"
extern std::string NumberToHumanString(int64_t num);
// Return a human-readable version of "value". // Return a human-readable version of "value".
// Escapes any non-printable characters found in "value". // Escapes any non-printable characters found in "value".
extern std::string EscapeString(const Slice& value); extern std::string EscapeString(const Slice& value);