Skip to content

Commit 1157de0

Browse files
jimwwalkertrondn
authored andcommitted
RangeScan: update internal tool to report results in JSON
Main change is to report rangescan results as JSON. More detail is included in the JSON output, such as overheads and per connection data. Change-Id: I9877b4415be2cc9f50f7de690412e937f861f88a Reviewed-on: https://review.couchbase.org/c/kv_engine/+/197105 Reviewed-by: Trond Norbye <[email protected]> Tested-by: Trond Norbye <[email protected]>
1 parent 8352836 commit 1157de0

File tree

1 file changed

+36
-22
lines changed

1 file changed

+36
-22
lines changed

programs/rangescan/rangescan.cc

Lines changed: 36 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -124,9 +124,10 @@ static void usage(std::string_view program) {
124124
exit(EXIT_FAILURE);
125125
}
126126

127-
std::string calculateThroughput(size_t bytes, size_t sec) {
128-
if (sec > 1) {
129-
bytes /= sec;
127+
static std::string calculateThroughput(size_t bytes,
128+
std::chrono::seconds seconds) {
129+
if (seconds > std::chrono::seconds(1)) {
130+
bytes /= seconds.count();
130131
}
131132

132133
std::vector<const char*> suffix = {"B/s", "kB/s", "MB/s", "GB/s"};
@@ -140,7 +141,7 @@ std::string calculateThroughput(size_t bytes, size_t sec) {
140141
}
141142
}
142143

143-
return std::to_string(bytes) + suffix[ii];
144+
return std::to_string(bytes) + suffix.at(ii);
144145
}
145146

146147
/// The RangeScanConnection class is responsible for a single connection and
@@ -220,19 +221,23 @@ class RangeScanConnection {
220221
return records;
221222
}
222223

223-
void reportConnectionStats() {
224+
nlohmann::json getConnectionStats() {
224225
const auto duration =
225226
std::chrono::duration_cast<std::chrono::milliseconds>(stop -
226227
start);
227-
228-
size_t total_bytes = getTotalBytesReceived();
229-
std::cout << "Connection took " << duration.count() << " ms - "
230-
<< records << " records with a total of " << total_bytes
231-
<< " bytes received (overhead "
232-
<< total_bytes - mutation_bytes << ") ("
233-
<< calculateThroughput(total_bytes, duration.count() / 1000)
234-
<< ") total range-scan-continues:" << continueCount
235-
<< std::endl;
228+
const auto totalBytes = getTotalBytesReceived();
229+
nlohmann::json result;
230+
result["connection"] = connection->to_string();
231+
result["duration_ms"] = duration.count();
232+
result["records"] = records;
233+
result["total_bytes_rx"] = totalBytes;
234+
result["record_bytes_rx"] = recordBytes;
235+
result["overhead_bytes_rx"] = totalBytes - recordBytes;
236+
result["throughput"] = calculateThroughput(
237+
totalBytes,
238+
std::chrono::duration_cast<std::chrono::seconds>(duration));
239+
result["continues"] = continueCount;
240+
return result;
236241
}
237242

238243
protected:
@@ -378,6 +383,7 @@ class RangeScanConnection {
378383
auto key = payload.next();
379384
while (key.data()) {
380385
records++;
386+
recordBytes += key.size();
381387
if (verbose) {
382388
std::cout << "KEY:" << key << std::endl;
383389
}
@@ -389,6 +395,11 @@ class RangeScanConnection {
389395
auto record = payload.next();
390396
while (record.key.data()) {
391397
records++;
398+
recordBytes += record.key.size();
399+
recordBytes += record.value.size();
400+
// Account the document metadata as well.
401+
recordBytes += sizeof(
402+
cb::mcbp::response::RangeScanContinueMetaResponse);
392403
if (verbose) {
393404
std::cout << "KEY:" << record.key
394405
<< " VALUE:" << record.value << std::endl;
@@ -402,7 +413,7 @@ class RangeScanConnection {
402413
}
403414

404415
uint32_t opaque{1};
405-
size_t mutation_bytes = 0;
416+
size_t recordBytes = 0; // Count of bytes for the key/document.
406417
size_t records = 0;
407418
size_t current_buffer_window = 0;
408419
size_t max_vbuckets = 0;
@@ -870,18 +881,21 @@ int main(int argc, char** argv) {
870881

871882
size_t total_bytes = 0;
872883
size_t records = 0;
884+
nlohmann::json result;
873885
for (const auto& c : connections) {
874886
total_bytes += c->getTotalBytesReceived();
875887
records += c->getRecords();
876-
if (connections.size() > 1) {
877-
c->reportConnectionStats();
878-
}
888+
result["connection_stats"].emplace_back(c->getConnectionStats());
879889
}
880890

881-
std::cout << "Took " << duration.count() << " ms - " << records
882-
<< " records with a total of " << total_bytes << " ("
883-
<< calculateThroughput(total_bytes, duration.count() / 1000)
884-
<< ")" << std::endl;
891+
result["connections"] = connections.size();
892+
result["total_duration_ms"] = duration.count();
893+
result["total_records"] = records;
894+
result["total_records_per_ms"] = float(records) / duration.count();
895+
result["total_throughput"] = calculateThroughput(
896+
total_bytes,
897+
std::chrono::duration_cast<std::chrono::seconds>(duration));
898+
std::cout << result.dump() << std::endl;
885899

886900
connections.clear();
887901
return EXIT_SUCCESS;

0 commit comments

Comments
 (0)