ClickHouse/utils/keeper-bench/Stats.h

53 lines
1.3 KiB
C++
Raw Normal View History

2021-04-12 08:10:23 +00:00
#pragma once
#include <vector>
#include <atomic>
#include <AggregateFunctions/ReservoirSampler.h>
struct Stats
{
2021-04-13 11:55:08 +00:00
std::atomic<size_t> read_requests{0};
std::atomic<size_t> write_requests{0};
2021-04-12 08:10:23 +00:00
size_t errors = 0;
size_t requests_write_bytes = 0;
size_t requests_read_bytes = 0;
2021-04-13 11:55:08 +00:00
double read_work_time = 0;
double write_work_time = 0;
2021-04-12 08:10:23 +00:00
using Sampler = ReservoirSampler<double>;
2021-04-13 11:55:08 +00:00
Sampler read_sampler {1 << 16};
Sampler write_sampler {1 << 16};
2021-04-12 08:10:23 +00:00
2021-04-13 11:55:08 +00:00
void addRead(double seconds, size_t requests_inc, size_t bytes_inc)
2021-04-12 08:10:23 +00:00
{
2021-04-13 11:55:08 +00:00
read_work_time += seconds;
read_requests += requests_inc;
requests_read_bytes += bytes_inc;
read_sampler.insert(seconds);
}
void addWrite(double seconds, size_t requests_inc, size_t bytes_inc)
{
write_work_time += seconds;
write_requests += requests_inc;
requests_write_bytes += bytes_inc;
write_sampler.insert(seconds);
2021-04-12 08:10:23 +00:00
}
void clear()
{
2021-04-13 11:55:08 +00:00
read_requests = 0;
write_requests = 0;
read_work_time = 0;
write_work_time = 0;
2021-04-12 08:10:23 +00:00
requests_read_bytes = 0;
requests_write_bytes = 0;
2021-04-13 11:55:08 +00:00
read_sampler.clear();
write_sampler.clear();
2021-04-12 08:10:23 +00:00
}
};
2021-04-12 15:40:42 +00:00
void report(std::shared_ptr<Stats> & info, size_t concurrency);