1#pragma once
2
3#include <Core/Types.h>
4#include <limits>
5#include <Common/Stopwatch.h>
6#include <AggregateFunctions/ReservoirSampler.h>
7
8namespace DB
9{
10struct TestStats
11{
12 TestStats();
13 Stopwatch watch;
14 Stopwatch watch_per_query;
15 Stopwatch min_time_watch;
16 Stopwatch max_rows_speed_watch;
17 Stopwatch max_bytes_speed_watch;
18 Stopwatch avg_rows_speed_watch;
19 Stopwatch avg_bytes_speed_watch;
20
21 bool last_query_was_cancelled = false;
22 std::string query_id;
23
24 size_t queries = 0;
25
26 size_t total_rows_read = 0;
27 size_t total_bytes_read = 0;
28
29 size_t last_query_rows_read = 0;
30 size_t last_query_bytes_read = 0;
31
32 using Sampler = ReservoirSampler<double>;
33 Sampler sampler{1 << 16};
34
35 /// min_time in ms
36 UInt64 min_time = std::numeric_limits<UInt64>::max();
37 double total_time = 0;
38
39 UInt64 max_rows_speed = 0;
40 UInt64 max_bytes_speed = 0;
41
42 double avg_rows_speed_value = 0;
43 double avg_rows_speed_first = 0;
44 static inline double avg_rows_speed_precision = 0.005;
45
46 double avg_bytes_speed_value = 0;
47 double avg_bytes_speed_first = 0;
48 static inline double avg_bytes_speed_precision = 0.005;
49
50 size_t number_of_rows_speed_info_batches = 0;
51 size_t number_of_bytes_speed_info_batches = 0;
52
53 UInt64 memory_usage = 0;
54
55 bool ready = false; // check if a query wasn't interrupted by SIGINT
56 std::string exception;
57
58 /// Hack, actually this field doesn't required for statistics
59 bool got_SIGINT = false;
60
61 std::string getStatisticByName(const std::string & statistic_name);
62
63 void update_min_time(UInt64 min_time_candidate);
64
65 void update_average_speed(
66 double new_speed_info,
67 Stopwatch & avg_speed_watch,
68 size_t & number_of_info_batches,
69 double precision,
70 double & avg_speed_first,
71 double & avg_speed_value);
72
73 void update_max_speed(
74 size_t max_speed_candidate,
75 Stopwatch & max_speed_watch,
76 UInt64 & max_speed);
77
78 void add(size_t rows_read_inc, size_t bytes_read_inc);
79
80 void updateQueryInfo();
81
82 void setTotalTime()
83 {
84 total_time = watch.elapsedSeconds();
85 }
86
87 void startWatches();
88};
89
90}
91