benchmark
1.10.0
Toggle main menu visibility
Loading...
Searching...
No Matches
reporter.h
1
// Copyright 2015 Google Inc. All rights reserved.
2
//
3
// Licensed under the Apache License, Version 2.0 (the "License");
4
// you may not use this file except in compliance with the License.
5
// You may obtain a copy of the License at
6
//
7
// http://www.apache.org/licenses/LICENSE-2.0
8
//
9
// Unless required by applicable law or agreed to in writing, software
10
// distributed under the License is distributed on an "AS IS" BASIS,
11
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
// See the License for the specific language governing permissions and
13
// limitations under the License.
14
15
#ifndef BENCHMARK_REPORTER_H_
16
#define BENCHMARK_REPORTER_H_
17
18
#if defined(_MSC_VER)
19
#pragma warning(push)
20
// C4251: <symbol> needs to have dll-interface to be used by clients of class
21
#pragma warning(disable : 4251)
22
#endif
23
24
#include <cassert>
25
#include <iostream>
26
#include <set>
27
#include <string>
28
#include <vector>
29
30
#include "benchmark/counter.h"
31
#include "benchmark/macros.h"
32
#include "benchmark/managers.h"
33
#include "benchmark/statistics.h"
34
#include "benchmark/sysinfo.h"
35
#include "benchmark/types.h"
36
37
namespace
benchmark {
38
39
namespace
internal {
40
class
BenchmarkInstance
;
41
}
// namespace internal
42
43
struct
BENCHMARK_EXPORT
BenchmarkName
{
44
std::string function_name;
45
std::string args;
46
std::string min_time;
47
std::string min_warmup_time;
48
std::string iterations;
49
std::string repetitions;
50
std::string time_type;
51
std::string threads;
52
53
std::string str()
const
;
54
};
55
56
class
BENCHMARK_EXPORT BenchmarkReporter {
57
public
:
58
struct
Context {
59
CPUInfo
const
& cpu_info;
60
SystemInfo
const
& sys_info;
61
size_t
name_field_width = 0;
62
static
const
char
* executable_name;
63
Context();
64
};
65
66
struct
BENCHMARK_EXPORT Run {
67
static
const
int64_t no_repetition_index = -1;
68
enum
RunType { RT_Iteration, RT_Aggregate };
69
70
Run()
71
: run_type(RT_Iteration),
72
aggregate_unit(kTime),
73
skipped(internal::NotSkipped),
74
iterations(1),
75
threads(1),
76
time_unit(kNanosecond),
77
real_accumulated_time(0),
78
cpu_accumulated_time(0),
79
max_heapbytes_used(0),
80
use_real_time_for_initial_big_o(
false
),
81
complexity(oNone),
82
complexity_lambda(),
83
complexity_n(0),
84
statistics(),
85
report_big_o(
false
),
86
report_rms(
false
),
87
allocs_per_iter(0.0) {}
88
89
std::string benchmark_name()
const
;
90
BenchmarkName
run_name;
91
int64_t family_index;
92
int64_t per_family_instance_index;
93
RunType run_type;
94
std::string aggregate_name;
95
StatisticUnit aggregate_unit;
96
std::string report_label;
97
internal::Skipped skipped;
98
std::string skip_message;
99
100
IterationCount iterations;
101
int64_t threads;
102
int64_t repetition_index;
103
int64_t repetitions;
104
TimeUnit time_unit;
105
double
real_accumulated_time;
106
double
cpu_accumulated_time;
107
108
double
GetAdjustedRealTime()
const
;
109
double
GetAdjustedCPUTime()
const
;
110
111
double
max_heapbytes_used;
112
bool
use_real_time_for_initial_big_o;
113
BigO complexity;
114
BigOFunc* complexity_lambda;
115
ComplexityN complexity_n;
116
const
std::vector<internal::Statistics>* statistics;
117
bool
report_big_o;
118
bool
report_rms;
119
UserCounters counters;
120
MemoryManager::Result
memory_result;
121
double
allocs_per_iter;
122
};
123
124
struct
PerFamilyRunReports {
125
PerFamilyRunReports() : num_runs_total(0), num_runs_done(0) {}
126
int
num_runs_total;
127
int
num_runs_done;
128
std::vector<BenchmarkReporter::Run> Runs;
129
};
130
131
BenchmarkReporter();
132
virtual
bool
ReportContext(
const
Context
& context) = 0;
133
virtual
void
ReportRunsConfig(
double
/*min_time*/
,
134
bool
/*has_explicit_iters*/
,
135
IterationCount
/*iters*/
) {}
136
virtual
void
ReportRuns(
const
std::vector<Run>& report) = 0;
137
virtual
void
Finalize() {}
138
139
// Called instead of running the benchmarks when `--benchmark_list_tests`
140
// is specified, with the benchmarks that were selected to run. The default
141
// implementation prints one benchmark name per line without any markup.
142
virtual
void
List(
const
std::vector<internal::BenchmarkInstance>& benchmarks);
143
144
void
SetOutputStream(std::ostream* out) {
145
assert(out);
146
output_stream_ = out;
147
}
148
void
SetErrorStream(std::ostream* err) {
149
assert(err);
150
error_stream_ = err;
151
}
152
std::ostream& GetOutputStream()
const
{
return
*output_stream_; }
153
std::ostream& GetErrorStream()
const
{
return
*error_stream_; }
154
virtual
~BenchmarkReporter();
155
static
void
PrintBasicContext(std::ostream* out, Context
const
& context);
156
157
private
:
158
std::ostream* output_stream_;
159
std::ostream* error_stream_;
160
};
161
162
class
BENCHMARK_EXPORT ConsoleReporter :
public
BenchmarkReporter {
163
public
:
164
enum
OutputOptions {
165
OO_None = 0,
166
OO_Color = 1,
167
OO_Tabular = 2,
168
OO_ColorTabular = OO_Color | OO_Tabular,
169
OO_Defaults = OO_ColorTabular
170
};
171
explicit
ConsoleReporter(OutputOptions opts_ = OO_Defaults)
172
: output_options_(opts_), name_field_width_(0), printed_header_(
false
) {}
173
174
bool
ReportContext(
const
Context
& context)
override
;
175
void
ReportRuns(
const
std::vector<Run>& reports)
override
;
176
177
protected
:
178
virtual
void
PrintRunData(
const
Run
& result);
179
virtual
void
PrintHeader(
const
Run
& run);
180
181
OutputOptions output_options_;
182
size_t
name_field_width_;
183
UserCounters prev_counters_;
184
bool
printed_header_;
185
};
186
187
class
BENCHMARK_EXPORT JSONReporter :
public
BenchmarkReporter {
188
public
:
189
JSONReporter() : first_report_(
true
) {}
190
bool
ReportContext(
const
Context
& context)
override
;
191
void
ReportRuns(
const
std::vector<Run>& reports)
override
;
192
void
Finalize()
override
;
193
void
List(
194
const
std::vector<internal::BenchmarkInstance>& benchmarks)
override
;
195
196
private
:
197
void
PrintRunData(
const
Run
& run);
198
bool
first_report_;
199
};
200
201
class
BENCHMARK_EXPORT BENCHMARK_DEPRECATED_MSG(
202
"The CSV Reporter will be removed in a future release"
) CSVReporter
203
:
public
BenchmarkReporter
{
204
public
:
205
CSVReporter() : printed_header_(false) {}
206
bool
ReportContext(
const
Context& context)
override
;
207
void
ReportRuns(
const
std::vector<Run>& reports)
override
;
208
void
List(
209
const
std::vector<internal::BenchmarkInstance>& benchmarks)
override
;
210
211
private
:
212
void
PrintRunData(
const
Run& run);
213
bool
printed_header_;
214
std::set<std::string> user_counter_names_;
215
};
216
217
inline
const
char
* GetTimeUnitString(TimeUnit unit) {
218
switch
(unit) {
219
case
kSecond:
220
return
"s"
;
221
case
kMillisecond:
222
return
"ms"
;
223
case
kMicrosecond:
224
return
"us"
;
225
case
kNanosecond:
226
return
"ns"
;
227
}
228
BENCHMARK_UNREACHABLE();
229
}
230
231
inline
double
GetTimeUnitMultiplier(TimeUnit unit) {
232
switch
(unit) {
233
case
kSecond:
234
return
1;
235
case
kMillisecond:
236
return
1e3;
237
case
kMicrosecond:
238
return
1e6;
239
case
kNanosecond:
240
return
1e9;
241
}
242
BENCHMARK_UNREACHABLE();
243
}
244
245
}
// namespace benchmark
246
247
#if defined(_MSC_VER)
248
#pragma warning(pop)
249
#endif
250
251
#endif
// BENCHMARK_REPORTER_H_
benchmark::BenchmarkReporter
Definition
reporter.h:56
benchmark::internal::BenchmarkInstance
Definition
benchmark_api_internal.h:20
benchmark::BenchmarkName
Definition
reporter.h:43
benchmark::BenchmarkReporter::Context
Definition
reporter.h:58
benchmark::BenchmarkReporter::Run
Definition
reporter.h:66
benchmark::CPUInfo
Definition
sysinfo.h:30
benchmark::MemoryManager::Result
Definition
managers.h:32
benchmark::SystemInfo
Definition
sysinfo.h:53
include
benchmark
reporter.h
Generated by
1.18.0