Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
B
benchmark
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Chen Yisong
benchmark
Commits
520573fe
Unverified
Commit
520573fe
authored
Jun 03, 2021
by
Roman Lebedev
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[NFCI] RunBenchmarks(): extract FlushStreams()/Report() functions
Based on original implementation by Hai Huang @haih-g in
https://github.com/google/benchmark/pull/1105
parent
6e32352c
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
36 additions
and
29 deletions
+36
-29
benchmark.cc
src/benchmark.cc
+36
-29
No files found.
src/benchmark.cc
View file @
520573fe
...
...
@@ -241,6 +241,37 @@ void State::FinishKeepRunning() {
namespace
internal
{
namespace
{
// Flushes streams after invoking reporter methods that write to them. This
// ensures users get timely updates even when streams are not line-buffered.
void
FlushStreams
(
BenchmarkReporter
*
reporter
)
{
if
(
!
reporter
)
return
;
std
::
flush
(
reporter
->
GetOutputStream
());
std
::
flush
(
reporter
->
GetErrorStream
());
}
// Reports in both display and file reporters.
void
Report
(
BenchmarkReporter
*
display_reporter
,
BenchmarkReporter
*
file_reporter
,
const
RunResults
&
run_results
)
{
auto
report_one
=
[](
BenchmarkReporter
*
reporter
,
bool
aggregates_only
,
const
RunResults
&
results
)
{
assert
(
reporter
);
// If there are no aggregates, do output non-aggregates.
aggregates_only
&=
!
results
.
aggregates_only
.
empty
();
if
(
!
aggregates_only
)
reporter
->
ReportRuns
(
results
.
non_aggregates
);
if
(
!
results
.
aggregates_only
.
empty
())
reporter
->
ReportRuns
(
results
.
aggregates_only
);
};
report_one
(
display_reporter
,
run_results
.
display_report_aggregates_only
,
run_results
);
if
(
file_reporter
)
report_one
(
file_reporter
,
run_results
.
file_report_aggregates_only
,
run_results
);
FlushStreams
(
display_reporter
);
FlushStreams
(
file_reporter
);
}
void
RunBenchmarks
(
const
std
::
vector
<
BenchmarkInstance
>&
benchmarks
,
BenchmarkReporter
*
display_reporter
,
BenchmarkReporter
*
file_reporter
)
{
...
...
@@ -269,18 +300,10 @@ void RunBenchmarks(const std::vector<BenchmarkInstance>& benchmarks,
std
::
map
<
int
/*family_index*/
,
std
::
vector
<
BenchmarkReporter
::
Run
>>
complexity_reports
;
// We flush streams after invoking reporter methods that write to them. This
// ensures users get timely updates even when streams are not line-buffered.
auto
flushStreams
=
[](
BenchmarkReporter
*
reporter
)
{
if
(
!
reporter
)
return
;
std
::
flush
(
reporter
->
GetOutputStream
());
std
::
flush
(
reporter
->
GetErrorStream
());
};
if
(
display_reporter
->
ReportContext
(
context
)
&&
(
!
file_reporter
||
file_reporter
->
ReportContext
(
context
)))
{
f
lushStreams
(
display_reporter
);
f
lushStreams
(
file_reporter
);
F
lushStreams
(
display_reporter
);
F
lushStreams
(
file_reporter
);
for
(
const
BenchmarkInstance
&
benchmark
:
benchmarks
)
{
std
::
vector
<
BenchmarkReporter
::
Run
>*
complexity_reports_for_family
=
...
...
@@ -292,29 +315,13 @@ void RunBenchmarks(const std::vector<BenchmarkInstance>& benchmarks,
RunResults
run_results
=
RunBenchmark
(
benchmark
,
complexity_reports_for_family
);
auto
report
=
[
&
run_results
](
BenchmarkReporter
*
reporter
,
bool
report_aggregates_only
)
{
assert
(
reporter
);
// If there are no aggregates, do output non-aggregates.
report_aggregates_only
&=
!
run_results
.
aggregates_only
.
empty
();
if
(
!
report_aggregates_only
)
reporter
->
ReportRuns
(
run_results
.
non_aggregates
);
if
(
!
run_results
.
aggregates_only
.
empty
())
reporter
->
ReportRuns
(
run_results
.
aggregates_only
);
};
report
(
display_reporter
,
run_results
.
display_report_aggregates_only
);
if
(
file_reporter
)
report
(
file_reporter
,
run_results
.
file_report_aggregates_only
);
flushStreams
(
display_reporter
);
flushStreams
(
file_reporter
);
Report
(
display_reporter
,
file_reporter
,
run_results
);
}
}
display_reporter
->
Finalize
();
if
(
file_reporter
)
file_reporter
->
Finalize
();
f
lushStreams
(
display_reporter
);
f
lushStreams
(
file_reporter
);
F
lushStreams
(
display_reporter
);
F
lushStreams
(
file_reporter
);
}
// Disable deprecated warnings temporarily because we need to reference
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment