ClickHouse/utils/keeper-bench/Stats.h

43 lines
1.0 KiB
C++
Raw Normal View History

2021-04-12 08:10:23 +00:00
#pragma once
#include <vector>
#include <atomic>
#include <AggregateFunctions/ReservoirSampler.h>
2023-04-14 13:32:08 +00:00
#include <base/JSON.h>
2021-04-12 08:10:23 +00:00
struct Stats
{
size_t errors = 0;
using Sampler = ReservoirSampler<double>;
2023-04-14 13:32:08 +00:00
struct StatsCollector
2021-04-12 08:10:23 +00:00
{
2023-04-14 13:32:08 +00:00
std::atomic<size_t> requests{0};
uint64_t requests_bytes = 0;
uint64_t work_time = 0;
Sampler sampler;
2021-04-13 11:55:08 +00:00
2023-04-14 13:32:08 +00:00
/// requests/second, bytes/second
std::pair<double, double> getThroughput(size_t concurrency);
double getPercentile(double percent);
2021-04-12 08:10:23 +00:00
2023-04-14 13:32:08 +00:00
void add(uint64_t microseconds, size_t requests_inc, size_t bytes_inc);
void clear();
};
StatsCollector read_collector;
StatsCollector write_collector;
void addRead(uint64_t microseconds, size_t requests_inc, size_t bytes_inc);
void addWrite(uint64_t microseconds, size_t requests_inc, size_t bytes_inc);
void clear();
void report(size_t concurrency);
2023-04-17 11:25:46 +00:00
void writeJSON(DB::WriteBuffer & out, size_t concurrency, int64_t start_timestamp);
2021-04-12 08:10:23 +00:00
};