Skip to content

Commit dea577d

Browse files
MatzeBmeta-codesync[bot]
authored andcommitted
Warn when benchmarks run before init
Summary: Print a warning when `folly::runBenchmarks` is used before running `folly::Init` (or a direct initialization of gflags) first. Reviewed By: yfeldblum Differential Revision: D116830471 fbshipit-source-id: 84b51315e26067f21a89ffe572e35c89bc54b9e6
1 parent ebd06c1 commit dea577d

1 file changed

Lines changed: 15 additions & 0 deletions

File tree

folly/Benchmark.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -804,6 +804,19 @@ void checkRunMode() {
804804
}
805805
}
806806

807+
void warnIfCommandLineFlagsWereNotParsed() {
808+
#if FOLLY_HAVE_LIBGFLAGS && __has_include(<gflags/gflags.h>)
809+
if (FLAGS_bm_quiet || !folly::gflags::GetArgvs().empty()) {
810+
return;
811+
}
812+
813+
std::cerr
814+
<< detail::kANSIBoldYellow << "WARNING: " << detail::kANSIReset
815+
<< "runBenchmarks() called before Init(); --bm_* flags will be ignored."
816+
<< std::endl;
817+
#endif
818+
}
819+
807820
namespace {
808821

809822
struct BenchmarksToRun {
@@ -1367,6 +1380,8 @@ std::string benchmarkResultsToString(
13671380
} // namespace detail
13681381

13691382
void runBenchmarks() {
1383+
warnIfCommandLineFlagsWereNotParsed();
1384+
13701385
auto& state = detail::globalBenchmarkState();
13711386

13721387
if (FLAGS_bm_list) {

0 commit comments

Comments
 (0)