Skip to content

Commit

Permalink
Make output more readable
Browse files Browse the repository at this point in the history
* Add id column
* Add ordinal number to histograms
* Add missing units

Part of: pmem#46
  • Loading branch information
Pawel Karczewski committed Jan 19, 2021
1 parent ae0a7e0 commit 80177bf
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 34 deletions.
73 changes: 44 additions & 29 deletions bench/db_bench.cc
Original file line number Diff line number Diff line change
Expand Up @@ -182,38 +182,53 @@ enum OperationType : unsigned char {
kUpdate,
};

class BenchmarkLogger : public CSV {
class BenchmarkLogger {
private:
struct hist {
int id;
std::string name;
std::string histogram;
};

int id = 0;
std::vector<hist> histograms;
CSV<int> csv = CSV<int>("id");

public:
using CSV::insert;

BenchmarkLogger() : CSV("Benchmark"){};

void insert(std::string name, Histogram histogram)
{
histograms.push_back({name, histogram.ToString()});
histograms.push_back({id, name, histogram.ToString()});
std::vector<double> percentiles = {50, 75, 90, 99.9, 99.99};
for (double &percentile : percentiles) {
insert(name, "Percentilie P" + std::to_string(percentile),
histogram.Percentile(percentile));
csv.insert(id, "Percentilie P" + std::to_string(percentile) + " [micros/op]",
histogram.Percentile(percentile));
}
insert(name, "Median", histogram.Median());
csv.insert(id, "Median [micros/op]", histogram.Median());
}
template <typename T>
void insert(std::string column, T data)
{
csv.insert(id, column, data);
}

void print_histogram()
{
std::cout << "------------------------------------------------" << std::endl;
for (auto &histogram : histograms) {
std::cout << histogram.name << std::endl << histogram.histogram << std::endl;
std::cout << "benchmark: " << histogram.id << ", " << histogram.name << std::endl
<< histogram.histogram << std::endl;
}
}

void print()
{
csv.print();
}

BenchmarkLogger operator++(int)
{
id++;
return *this;
}
};

class Stats {
Expand Down Expand Up @@ -461,12 +476,12 @@ class Benchmark {
void PrintHeader()
{
PrintEnvironment();
logger.insert(name.ToString(), "Path", FLAGS_db);
logger.insert(name.ToString(), "Engine", engine);
logger.insert(name.ToString(), "Keys [bytes each]", FLAGS_key_size);
logger.insert(name.ToString(), "Values [bytes each]", FLAGS_value_size);
logger.insert(name.ToString(), "Entries", num_);
logger.insert(name.ToString(), "RawSize [MB (estimated)]",
logger.insert("Path", FLAGS_db);
logger.insert("Engine", engine);
logger.insert("Keys [bytes each]", FLAGS_key_size);
logger.insert("Values [bytes each]", FLAGS_value_size);
logger.insert("Entries", num_);
logger.insert("RawSize [MB (estimated)]",
((static_cast<int64_t>(FLAGS_key_size + FLAGS_value_size) * num_) / 1048576.0));
PrintWarnings();
}
Expand All @@ -486,8 +501,7 @@ class Benchmark {
#if defined(__linux)
time_t now = time(NULL);
auto formatted_time = std::string(ctime(&now));
logger.insert(name.ToString(),
"Date:", formatted_time.erase(formatted_time.find_last_not_of("\n")));
logger.insert("Date:", formatted_time.erase(formatted_time.find_last_not_of("\n")));

FILE *cpuinfo = fopen("/proc/cpuinfo", "r");
if (cpuinfo != NULL) {
Expand All @@ -510,9 +524,9 @@ class Benchmark {
}
}
fclose(cpuinfo);
logger.insert(name.ToString(), "CPU", std::to_string(num_cpus));
logger.insert(name.ToString(), "CPU model", cpu_type);
logger.insert(name.ToString(), "CPUCache", cache_size);
logger.insert("CPU", std::to_string(num_cpus));
logger.insert("CPU model", cpu_type);
logger.insert("CPUCache", cache_size);
}
#endif
}
Expand Down Expand Up @@ -553,6 +567,8 @@ class Benchmark {
} else {
throw std::runtime_error("unknown benchmark: " + name.ToString());
}
logger++;
logger.insert("Benchmark", name.ToString());
PrintHeader();

Open(fresh_db, name.ToString());
Expand Down Expand Up @@ -620,10 +636,10 @@ class Benchmark {
arg[0].thread->stats.Merge(arg[i].thread->stats);
}
auto thread_stats = arg[0].thread->stats;
logger.insert(name.ToString(), "micros/op", thread_stats.get_micros_per_op());
logger.insert(name.ToString(), "ops/sec", thread_stats.get_ops_per_sec());
logger.insert(name.ToString(), "throughput [MB/s]", thread_stats.get_throughput());
logger.insert(name.ToString(), "extra_data", thread_stats.get_extra_data());
logger.insert("micros/op (avarage)", thread_stats.get_micros_per_op());
logger.insert("ops/sec", thread_stats.get_ops_per_sec());
logger.insert("throughput [MB/s]", thread_stats.get_throughput());
logger.insert("extra_data", thread_stats.get_extra_data());
if (FLAGS_histogram) {
logger.insert(name.ToString(), thread_stats.get_histogram());
}
Expand Down Expand Up @@ -704,8 +720,7 @@ class Benchmark {
if (pmempool_rm(FLAGS_db, PMEMPOOL_RM_FORCE) != 0) {
throw std::runtime_error(std::string("Cannot remove pool: ") + FLAGS_db);
}
logger.insert(name, "Remove [millis millis/op]",
((g_env->NowMicros() - start) * 1e-3));
logger.insert("Remove [millis/op]", ((g_env->NowMicros() - start) * 1e-3));
}

kv_ = new pmem::kv::db;
Expand All @@ -718,7 +733,7 @@ class Benchmark {
USAGE.c_str());
exit(-42);
}
logger.insert(name, "Open [millis/op]", ((g_env->NowMicros() - start) * 1e-3));
logger.insert("Open [millis/op]", ((g_env->NowMicros() - start) * 1e-3));
}

void DoWrite(ThreadState *thread, bool seq)
Expand Down
11 changes: 6 additions & 5 deletions bench/util/csv.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// SPDX-License-Identifier: Apache-2.0
/* Copyright 2020, Intel Corporation */
/* Copyright 2020-2021, Intel Corporation */

#pragma once

Expand All @@ -9,11 +9,12 @@
#include <set>
#include <string>

template <typename IdType>
class CSV {
private:
/* Hold data in two-dimensional map of strings: data_matrix[row][column]
*/
std::map<std::string, std::map<std::string, std::string>> data_matrix;
std::map<IdType, std::map<std::string, std::string>> data_matrix;
/* List of all columns, which is filled during inserts. Needed for
* printing header and data in the same order.
* */
Expand All @@ -22,19 +23,19 @@ class CSV {

public:
CSV(std::string id_column_name) : id_name(id_column_name){};
void insert(std::string row, std::string column, std::string data)
void insert(IdType row, std::string column, std::string data)
{
columns.insert(column);
data_matrix[row][column] = data;
}

void insert(std::string row, std::string column, const char *data)
void insert(IdType row, std::string column, const char *data)
{
insert(row, column, std::string(data));
}

template <typename T>
void insert(std::string row, std::string column, T data)
void insert(IdType row, std::string column, T data)
{
insert(row, column, std::to_string(data));
}
Expand Down

0 comments on commit 80177bf

Please sign in to comment.