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
0de985ae
Commit
0de985ae
authored
Mar 02, 2017
by
Joao Paulo Magalhaes
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add command line option --benchmark_counters_tabular
parent
9e346556
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
57 additions
and
26 deletions
+57
-26
reporter.h
include/benchmark/reporter.h
+13
-7
benchmark.cc
src/benchmark.cc
+24
-12
console_reporter.cc
src/console_reporter.cc
+19
-6
counter.cc
src/counter.cc
+1
-1
No files found.
include/benchmark/reporter.h
View file @
0de985ae
...
@@ -157,10 +157,17 @@ class BenchmarkReporter {
...
@@ -157,10 +157,17 @@ class BenchmarkReporter {
// Simple reporter that outputs benchmark data to the console. This is the
// Simple reporter that outputs benchmark data to the console. This is the
// default reporter used by RunSpecifiedBenchmarks().
// default reporter used by RunSpecifiedBenchmarks().
class
ConsoleReporter
:
public
BenchmarkReporter
{
class
ConsoleReporter
:
public
BenchmarkReporter
{
public
:
public
:
enum
OutputOptions
{
OO_None
,
OO_Color
};
enum
OutputOptions
{
explicit
ConsoleReporter
(
OutputOptions
color_output
=
OO_Color
)
OO_None
=
0
,
:
name_field_width_
(
0
),
color_output_
(
color_output
==
OO_Color
)
{}
OO_Color
=
1
,
OO_Tabular
=
2
,
OO_ColorTabular
=
OO_Color
|
OO_Tabular
,
OO_Defaults
=
OO_ColorTabular
};
explicit
ConsoleReporter
(
OutputOptions
opts_
=
OO_Defaults
)
:
output_options_
(
opts_
),
name_field_width_
(
0
),
prev_counters_
(),
printed_header_
(
false
)
{}
virtual
bool
ReportContext
(
const
Context
&
context
);
virtual
bool
ReportContext
(
const
Context
&
context
);
virtual
void
ReportRuns
(
const
std
::
vector
<
Run
>&
reports
);
virtual
void
ReportRuns
(
const
std
::
vector
<
Run
>&
reports
);
...
@@ -169,11 +176,10 @@ class ConsoleReporter : public BenchmarkReporter {
...
@@ -169,11 +176,10 @@ class ConsoleReporter : public BenchmarkReporter {
virtual
void
PrintRunData
(
const
Run
&
report
);
virtual
void
PrintRunData
(
const
Run
&
report
);
virtual
void
PrintHeader
(
const
Run
&
report
);
virtual
void
PrintHeader
(
const
Run
&
report
);
OutputOptions
output_options_
;
size_t
name_field_width_
;
size_t
name_field_width_
;
UserCounters
prev_counters_
;
bool
printed_header_
;
bool
printed_header_
;
private
:
bool
color_output_
;
};
};
class
JSONReporter
:
public
BenchmarkReporter
{
class
JSONReporter
:
public
BenchmarkReporter
{
...
...
src/benchmark.cc
View file @
0de985ae
...
@@ -91,6 +91,11 @@ DEFINE_string(benchmark_color, "auto",
...
@@ -91,6 +91,11 @@ DEFINE_string(benchmark_color, "auto",
"environment variable is set to a terminal type that supports "
"environment variable is set to a terminal type that supports "
"colors."
);
"colors."
);
DEFINE_bool
(
benchmark_counters_tabular
,
false
,
"Whether to use tabular format when printing user counters to "
"the console. Valid values: 'true'/'yes'/1, 'false'/'no'/0."
"Defaults to false."
);
DEFINE_int32
(
v
,
0
,
"The level of verbose logging to output"
);
DEFINE_int32
(
v
,
0
,
"The level of verbose logging to output"
);
namespace
benchmark
{
namespace
benchmark
{
...
@@ -510,10 +515,10 @@ void RunBenchmarks(const std::vector<Benchmark::Instance>& benchmarks,
...
@@ -510,10 +515,10 @@ void RunBenchmarks(const std::vector<Benchmark::Instance>& benchmarks,
}
}
std
::
unique_ptr
<
BenchmarkReporter
>
CreateReporter
(
std
::
unique_ptr
<
BenchmarkReporter
>
CreateReporter
(
std
::
string
const
&
name
,
ConsoleReporter
::
OutputOptions
allow_color
)
{
std
::
string
const
&
name
,
ConsoleReporter
::
OutputOptions
output_opts
)
{
typedef
std
::
unique_ptr
<
BenchmarkReporter
>
PtrType
;
typedef
std
::
unique_ptr
<
BenchmarkReporter
>
PtrType
;
if
(
name
==
"console"
)
{
if
(
name
==
"console"
)
{
return
PtrType
(
new
ConsoleReporter
(
allow_color
));
return
PtrType
(
new
ConsoleReporter
(
output_opts
));
}
else
if
(
name
==
"json"
)
{
}
else
if
(
name
==
"json"
)
{
return
PtrType
(
new
JSONReporter
);
return
PtrType
(
new
JSONReporter
);
}
else
if
(
name
==
"csv"
)
{
}
else
if
(
name
==
"csv"
)
{
...
@@ -546,16 +551,20 @@ size_t RunSpecifiedBenchmarks(BenchmarkReporter* console_reporter,
...
@@ -546,16 +551,20 @@ size_t RunSpecifiedBenchmarks(BenchmarkReporter* console_reporter,
std
::
unique_ptr
<
BenchmarkReporter
>
default_console_reporter
;
std
::
unique_ptr
<
BenchmarkReporter
>
default_console_reporter
;
std
::
unique_ptr
<
BenchmarkReporter
>
default_file_reporter
;
std
::
unique_ptr
<
BenchmarkReporter
>
default_file_reporter
;
if
(
!
console_reporter
)
{
if
(
!
console_reporter
)
{
auto
output_opts
=
ConsoleReporter
::
OO_None
;
int
output_opts
=
ConsoleReporter
::
OO_Defaults
;
if
(
FLAGS_benchmark_color
==
"auto"
)
if
((
FLAGS_benchmark_color
==
"auto"
&&
IsColorTerminal
())
||
output_opts
=
IsColorTerminal
()
?
ConsoleReporter
::
OO_Color
IsTruthyFlagValue
(
FLAGS_benchmark_color
))
{
:
ConsoleReporter
::
OO_None
;
output_opts
|=
ConsoleReporter
::
OO_Color
;
else
}
else
{
output_opts
=
IsTruthyFlagValue
(
FLAGS_benchmark_color
)
output_opts
&=
~
ConsoleReporter
::
OO_Color
;
?
ConsoleReporter
::
OO_Color
}
:
ConsoleReporter
::
OO_None
;
if
(
FLAGS_benchmark_counters_tabular
)
{
default_console_reporter
=
output_opts
|=
ConsoleReporter
::
OO_Tabular
;
internal
::
CreateReporter
(
FLAGS_benchmark_format
,
output_opts
);
}
else
{
output_opts
&=
~
ConsoleReporter
::
OO_Tabular
;
}
default_console_reporter
=
internal
::
CreateReporter
(
FLAGS_benchmark_format
,
(
ConsoleReporter
::
OutputOptions
)
output_opts
);
console_reporter
=
default_console_reporter
.
get
();
console_reporter
=
default_console_reporter
.
get
();
}
}
auto
&
Out
=
console_reporter
->
GetOutputStream
();
auto
&
Out
=
console_reporter
->
GetOutputStream
();
...
@@ -614,6 +623,7 @@ void PrintUsageAndExit() {
...
@@ -614,6 +623,7 @@ void PrintUsageAndExit() {
" [--benchmark_out=<filename>]
\n
"
" [--benchmark_out=<filename>]
\n
"
" [--benchmark_out_format=<json|console|csv>]
\n
"
" [--benchmark_out_format=<json|console|csv>]
\n
"
" [--benchmark_color={auto|true|false}]
\n
"
" [--benchmark_color={auto|true|false}]
\n
"
" [--benchmark_counters_tabular={true|false}]
\n
"
" [--v=<verbosity>]
\n
"
);
" [--v=<verbosity>]
\n
"
);
exit
(
0
);
exit
(
0
);
}
}
...
@@ -638,6 +648,8 @@ void ParseCommandLineFlags(int* argc, char** argv) {
...
@@ -638,6 +648,8 @@ void ParseCommandLineFlags(int* argc, char** argv) {
// "color_print" is the deprecated name for "benchmark_color".
// "color_print" is the deprecated name for "benchmark_color".
// TODO: Remove this.
// TODO: Remove this.
ParseStringFlag
(
argv
[
i
],
"color_print"
,
&
FLAGS_benchmark_color
)
||
ParseStringFlag
(
argv
[
i
],
"color_print"
,
&
FLAGS_benchmark_color
)
||
ParseBoolFlag
(
argv
[
i
],
"benchmark_counters_tabular"
,
&
FLAGS_benchmark_counters_tabular
)
||
ParseInt32Flag
(
argv
[
i
],
"v"
,
&
FLAGS_v
))
{
ParseInt32Flag
(
argv
[
i
],
"v"
,
&
FLAGS_v
))
{
for
(
int
j
=
i
;
j
!=
*
argc
-
1
;
++
j
)
argv
[
j
]
=
argv
[
j
+
1
];
for
(
int
j
=
i
;
j
!=
*
argc
-
1
;
++
j
)
argv
[
j
]
=
argv
[
j
+
1
];
...
...
src/console_reporter.cc
View file @
0de985ae
...
@@ -36,6 +36,7 @@ namespace benchmark {
...
@@ -36,6 +36,7 @@ namespace benchmark {
bool
ConsoleReporter
::
ReportContext
(
const
Context
&
context
)
{
bool
ConsoleReporter
::
ReportContext
(
const
Context
&
context
)
{
name_field_width_
=
context
.
name_field_width
;
name_field_width_
=
context
.
name_field_width
;
printed_header_
=
false
;
printed_header_
=
false
;
prev_counters_
.
clear
();
PrintBasicContext
(
&
GetErrorStream
(),
context
);
PrintBasicContext
(
&
GetErrorStream
(),
context
);
...
@@ -64,13 +65,21 @@ void ConsoleReporter::PrintHeader(const Run& run) {
...
@@ -64,13 +65,21 @@ void ConsoleReporter::PrintHeader(const Run& run) {
void
ConsoleReporter
::
ReportRuns
(
const
std
::
vector
<
Run
>&
reports
)
{
void
ConsoleReporter
::
ReportRuns
(
const
std
::
vector
<
Run
>&
reports
)
{
for
(
const
auto
&
run
:
reports
)
{
for
(
const
auto
&
run
:
reports
)
{
// print the header if none was printed yet
// print the header:
if
(
!
printed_header_
)
{
// --- if none was printed yet
bool
print_header
=
!
printed_header_
;
// --- or if the format is tabular and this run
// has different fields from the prev header
print_header
|=
(
output_options_
&
OO_Tabular
)
&&
(
!
internal
::
SameNames
(
run
.
counters
,
prev_counters_
));
if
(
print_header
)
{
printed_header_
=
true
;
printed_header_
=
true
;
prev_counters_
=
run
.
counters
;
PrintHeader
(
run
);
PrintHeader
(
run
);
}
}
// As an alternative to printing the headers like this, we could sort
// As an alternative to printing the headers like this, we could sort
// the benchmarks by header and then print like that.
// the benchmarks by header and then print. But this would require
// waiting for the full results before printing, or printing twice.
PrintRunData
(
run
);
PrintRunData
(
run
);
}
}
}
}
...
@@ -86,8 +95,8 @@ static void IgnoreColorPrint(std::ostream& out, LogColor, const char* fmt,
...
@@ -86,8 +95,8 @@ static void IgnoreColorPrint(std::ostream& out, LogColor, const char* fmt,
void
ConsoleReporter
::
PrintRunData
(
const
Run
&
result
)
{
void
ConsoleReporter
::
PrintRunData
(
const
Run
&
result
)
{
typedef
void
(
PrinterFn
)(
std
::
ostream
&
,
LogColor
,
const
char
*
,
...);
typedef
void
(
PrinterFn
)(
std
::
ostream
&
,
LogColor
,
const
char
*
,
...);
auto
&
Out
=
GetOutputStream
();
auto
&
Out
=
GetOutputStream
();
PrinterFn
*
printer
=
PrinterFn
*
printer
=
(
output_options_
&
OO_Color
)
?
color_output_
?
(
PrinterFn
*
)
ColorPrintf
:
IgnoreColorPrint
;
(
PrinterFn
*
)
ColorPrintf
:
IgnoreColorPrint
;
auto
name_color
=
auto
name_color
=
(
result
.
report_big_o
||
result
.
report_rms
)
?
COLOR_BLUE
:
COLOR_GREEN
;
(
result
.
report_big_o
||
result
.
report_rms
)
?
COLOR_BLUE
:
COLOR_GREEN
;
printer
(
Out
,
name_color
,
"%-*s "
,
name_field_width_
,
printer
(
Out
,
name_color
,
"%-*s "
,
name_field_width_
,
...
@@ -134,7 +143,11 @@ void ConsoleReporter::PrintRunData(const Run& result) {
...
@@ -134,7 +143,11 @@ void ConsoleReporter::PrintRunData(const Run& result) {
for
(
auto
&
c
:
result
.
counters
)
{
for
(
auto
&
c
:
result
.
counters
)
{
auto
const
&
s
=
HumanReadableNumber
(
c
.
second
.
value
);
auto
const
&
s
=
HumanReadableNumber
(
c
.
second
.
value
);
printer
(
Out
,
COLOR_DEFAULT
,
" %s=%s"
,
c
.
first
.
c_str
(),
s
.
c_str
());
if
(
output_options_
&
OO_Tabular
)
{
printer
(
Out
,
COLOR_DEFAULT
,
" %10s"
,
s
.
c_str
());
}
else
{
printer
(
Out
,
COLOR_DEFAULT
,
" %s=%s"
,
c
.
first
.
c_str
(),
s
.
c_str
());
}
}
}
if
(
!
rate
.
empty
())
{
if
(
!
rate
.
empty
())
{
...
...
src/counter.cc
View file @
0de985ae
...
@@ -57,7 +57,7 @@ bool SameNames(UserCounters const& l, UserCounters const& r) {
...
@@ -57,7 +57,7 @@ bool SameNames(UserCounters const& l, UserCounters const& r) {
return
false
;
return
false
;
}
}
for
(
auto
const
&
c
:
l
)
{
for
(
auto
const
&
c
:
l
)
{
if
(
r
.
find
(
c
.
first
)
==
r
.
end
())
{
if
(
r
.
find
(
c
.
first
)
==
r
.
end
())
{
return
false
;
return
false
;
}
}
}
}
...
...
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