Skip to content

Commit 98474d5

Browse files
yabmek-msfttzuvich
andauthored
Add ability to report JSon formatted leveldb stats (#9)
Co-authored-by: tzuvich <[email protected]>
1 parent a985fcc commit 98474d5

File tree

1 file changed

+47
-1
lines changed

1 file changed

+47
-1
lines changed

db/db_impl.cc

Lines changed: 47 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1465,7 +1465,7 @@ bool DBImpl::GetProperty(const Slice& property, std::string* value) {
14651465
for (int level = 0; level < config::kNumLevels; level++) {
14661466
int files = versions_->NumLevelFiles(level);
14671467
if (stats_[level].micros > 0 || files > 0) {
1468-
std::snprintf(buf, sizeof(buf), "%3d %8d %8.0f %9.0f %8.0f %9.0f\n",
1468+
std::snprintf(buf, sizeof(buf), "%3d %8d %8.0f %9.2f %8.2f %9.2f\n",
14691469
level, files, versions_->NumLevelBytes(level) / 1048576.0,
14701470
stats_[level].micros / 1e6,
14711471
stats_[level].bytes_read / 1048576.0,
@@ -1474,6 +1474,52 @@ bool DBImpl::GetProperty(const Slice& property, std::string* value) {
14741474
}
14751475
}
14761476
return true;
1477+
// BLOCK ADDED FOR MINECRAFT
1478+
} else if (in == "jsonstats") {
1479+
char buf[200];
1480+
value->append("{\n");
1481+
value->append("\"levels\"");
1482+
value->append(": [\n");
1483+
bool first = true;
1484+
for (int level = 0; level < config::kNumLevels; level++) {
1485+
int files = versions_->NumLevelFiles(level);
1486+
if (stats_[level].micros > 0 || files > 0) {
1487+
1488+
// Nth items in array append ,\n to previous entry
1489+
if (!first) {
1490+
value->append(",\n");
1491+
}
1492+
value->append("{\n");
1493+
1494+
value->append("\"level\"");
1495+
snprintf(buf, sizeof(buf), ": %3d,\n", level);
1496+
value->append(buf);
1497+
1498+
value->append("\"files\"");
1499+
snprintf(buf, sizeof(buf), ": %3d,\n", files);
1500+
value->append(buf);
1501+
1502+
snprintf(buf, sizeof(buf), "\"sizeMB\": %0.3f,\n", versions_->NumLevelBytes(level) / 1048576.0);
1503+
value->append(buf);
1504+
1505+
snprintf(buf, sizeof(buf), "\"tsec\": %0.3f,\n", stats_[level].micros / 1e6);
1506+
value->append(buf);
1507+
1508+
snprintf(buf, sizeof(buf), "\"readMB\": %0.3f,\n", stats_[level].bytes_read / 1048576.0);
1509+
value->append(buf);
1510+
1511+
snprintf(buf, sizeof(buf), "\"writeMB\": %0.3f\n", stats_[level].bytes_written / 1048576.0);
1512+
value->append(buf);
1513+
1514+
// append end }
1515+
value->append("}");
1516+
1517+
first = false;
1518+
}
1519+
}
1520+
value->append("]\n");
1521+
value->append("}");
1522+
14771523
} else if (in == "sstables") {
14781524
*value = versions_->current()->DebugString();
14791525
return true;

0 commit comments

Comments
 (0)