From ece5095a077cf2a09fd1d8aa1a50e29387b5938e Mon Sep 17 00:00:00 2001 From: Adrian Stone Date: Thu, 26 Sep 2024 11:14:53 -0700 Subject: [PATCH] Add bm_file_regex command line option to benchmark Summary: Benchmarks already support --bm_regex to filter benchmarks by name. This commit adds --bm_file_regex to further filter benchmarks by filename. This is convenient when iterating on benchmarks for a single class which are typically placed in a single translation unit. Reviewed By: Gownta Differential Revision: D63044678 fbshipit-source-id: 648514fd3075859ab0cbfbdffd2bee48c37852c7 --- folly/Benchmark.cpp | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/folly/Benchmark.cpp b/folly/Benchmark.cpp index 180a4162ad8..02ad816a059 100644 --- a/folly/Benchmark.cpp +++ b/folly/Benchmark.cpp @@ -84,6 +84,11 @@ FOLLY_GFLAGS_DEFINE_string( FOLLY_GFLAGS_DEFINE_string( bm_regex, "", "Only benchmarks whose names match this regex will be run."); +FOLLY_GFLAGS_DEFINE_string( + bm_file_regex, + "", + "Only benchmarks whose filenames match this regex will be run."); + FOLLY_GFLAGS_DEFINE_int64( bm_min_usec, 100, @@ -687,6 +692,7 @@ BenchmarksToRun selectBenchmarksToRun( BenchmarksToRun res; folly::Optional bmRegex; + folly::Optional bmFileRegex; res.benchmarks.reserve(benchmarks.size()); @@ -694,6 +700,10 @@ BenchmarksToRun selectBenchmarksToRun( bmRegex.emplace(FLAGS_bm_regex); } + if (!FLAGS_bm_file_regex.empty()) { + bmFileRegex.emplace(FLAGS_bm_file_regex); + } + for (auto& bm : benchmarks) { if (bm.name == "-") { addSeparator(res); @@ -705,7 +715,11 @@ BenchmarksToRun selectBenchmarksToRun( continue; } - if (!bmRegex || boost::regex_search(bm.name, *bmRegex)) { + bool matchedName = !bmRegex || boost::regex_search(bm.name, *bmRegex); + bool matchedFile = + !bmFileRegex || boost::regex_search(bm.file, *bmFileRegex); + + if (matchedName && matchedFile) { res.benchmarks.push_back(&bm); } }