Commit c5de988
folly/Benchmark: bracket perf around the benchmark, not the whole run (#2682)
Summary:
Pull Request resolved: #2682
## Human comment:
AI said that when it ran topdown, the extra noise from baseline set up and such was substantial.
That doesn't seem to be true.
But - the diff is still making things cleaner and neater I think.
## AI comment:
The perf guard was constructed one scope too high. `runBenchmarksWithPrinter`
built it immediately before calling `runBenchmarksWithPrinterImpl`, so the
counting window covered everything that function does -- including the two
global empty-loop baselines, flag validation, the banners, and per-row
printing.
`selectBenchmarksToRun` peels the baselines out before applying `--bm_regex`,
so no flag could exclude them. They run under the full
`--bm_max_secs`/`--bm_max_trials` budget: about 2 seconds and 9.8B
instructions per run.
On a memory-bound benchmark that was 68% of the counted instructions and 66%
of the cycles, and it inverted the answer -- AMD topdown reported
`frontend_bound` 32% and `backend_bound` 51.9%, because empty tight loops are
dispatch-bound. The true figures are ~2% and ~71%. Cache-miss counters were
mostly unaffected (0.2%), since empty loops never touch memory, which is why
this went unnoticed.
Move the guard into the per-benchmark loop, around the measurement dispatch
only. The baselines are computed before the loop, so they fall outside for
free, and printing stays outside too. Adaptive mode keeps a whole-run guard:
it interleaves samples across benchmarks, so there is no contiguous
per-benchmark region to bracket.
Since perf attaches to the whole process, it can only describe one benchmark,
so require the filters to select exactly one. `BENCHMARK_DRAW_TEXT` registers
an entry that passes the name filters but is not a measurement, so it is
excluded from the count and gets no window of its own.
Two related fixes:
- Usage errors were invisible. `LOG(ERROR)` emits nothing in these binaries --
the pre-existing `--bm_mode=bogus` path exits 1 silently too. Routed the
fatals through one helper that writes to `cerr`.
- A perf that cannot start now exits 1 with the reason instead of aborting.
Combined with the preceding commit, `--bm_perf_args="stat -e nosuchevent"`
goes from exit 134 to a clear message.
`--bm_perf_args` without a narrowing `--bm_regex` now fails instead of
silently profiling the whole run. Two callers do this today and will need
updating: `xplat/superpack/apps/crunch/recon_agents.py` and
`fbcode/kernel/fastio_kerneltest/provided_buffer_ring_bench_compare.py`. The
former parses last-block-wins, so its numbers are already wrong.
Reviewed By: yfeldblum
Differential Revision: D116315663
fbshipit-source-id: 9df0bf6cb1d6f9f6e3b84c5f527bbdf17f3cec791 parent a4a9631 commit c5de988
2 files changed
Lines changed: 169 additions & 25 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
29 | 29 | | |
30 | 30 | | |
31 | 31 | | |
| 32 | + | |
32 | 33 | | |
33 | 34 | | |
34 | 35 | | |
| |||
159 | 160 | | |
160 | 161 | | |
161 | 162 | | |
162 | | - | |
163 | | - | |
| 163 | + | |
| 164 | + | |
164 | 165 | | |
165 | 166 | | |
166 | 167 | | |
| |||
505 | 506 | | |
506 | 507 | | |
507 | 508 | | |
| 509 | + | |
| 510 | + | |
| 511 | + | |
| 512 | + | |
| 513 | + | |
508 | 514 | | |
509 | 515 | | |
510 | 516 | | |
| |||
570 | 576 | | |
571 | 577 | | |
572 | 578 | | |
573 | | - | |
| 579 | + | |
574 | 580 | | |
575 | 581 | | |
576 | 582 | | |
| |||
955 | 961 | | |
956 | 962 | | |
957 | 963 | | |
| 964 | + | |
| 965 | + | |
| 966 | + | |
| 967 | + | |
| 968 | + | |
| 969 | + | |
| 970 | + | |
| 971 | + | |
| 972 | + | |
| 973 | + | |
| 974 | + | |
| 975 | + | |
| 976 | + | |
| 977 | + | |
| 978 | + | |
| 979 | + | |
| 980 | + | |
| 981 | + | |
| 982 | + | |
| 983 | + | |
| 984 | + | |
| 985 | + | |
| 986 | + | |
| 987 | + | |
| 988 | + | |
| 989 | + | |
| 990 | + | |
| 991 | + | |
| 992 | + | |
| 993 | + | |
| 994 | + | |
| 995 | + | |
| 996 | + | |
| 997 | + | |
| 998 | + | |
| 999 | + | |
| 1000 | + | |
| 1001 | + | |
| 1002 | + | |
| 1003 | + | |
| 1004 | + | |
| 1005 | + | |
| 1006 | + | |
| 1007 | + | |
| 1008 | + | |
| 1009 | + | |
| 1010 | + | |
| 1011 | + | |
| 1012 | + | |
| 1013 | + | |
| 1014 | + | |
| 1015 | + | |
| 1016 | + | |
| 1017 | + | |
| 1018 | + | |
| 1019 | + | |
| 1020 | + | |
| 1021 | + | |
| 1022 | + | |
| 1023 | + | |
| 1024 | + | |
958 | 1025 | | |
959 | 1026 | | |
960 | | - | |
961 | | - | |
962 | | - | |
963 | | - | |
964 | | - | |
| 1027 | + | |
965 | 1028 | | |
966 | 1029 | | |
967 | 1030 | | |
| |||
987 | 1050 | | |
988 | 1051 | | |
989 | 1052 | | |
990 | | - | |
991 | | - | |
992 | | - | |
| 1053 | + | |
993 | 1054 | | |
994 | 1055 | | |
995 | 1056 | | |
| |||
1038 | 1099 | | |
1039 | 1100 | | |
1040 | 1101 | | |
1041 | | - | |
| 1102 | + | |
| 1103 | + | |
1042 | 1104 | | |
1043 | 1105 | | |
1044 | 1106 | | |
| |||
1110 | 1172 | | |
1111 | 1173 | | |
1112 | 1174 | | |
1113 | | - | |
1114 | | - | |
1115 | | - | |
1116 | | - | |
1117 | | - | |
1118 | | - | |
1119 | | - | |
| 1175 | + | |
| 1176 | + | |
| 1177 | + | |
| 1178 | + | |
| 1179 | + | |
| 1180 | + | |
| 1181 | + | |
| 1182 | + | |
| 1183 | + | |
| 1184 | + | |
| 1185 | + | |
| 1186 | + | |
| 1187 | + | |
1120 | 1188 | | |
1121 | 1189 | | |
1122 | 1190 | | |
| |||
1224 | 1292 | | |
1225 | 1293 | | |
1226 | 1294 | | |
1227 | | - | |
1228 | 1295 | | |
| 1296 | + | |
1229 | 1297 | | |
1230 | | - | |
1231 | 1298 | | |
1232 | 1299 | | |
1233 | 1300 | | |
1234 | | - | |
| 1301 | + | |
| 1302 | + | |
| 1303 | + | |
| 1304 | + | |
| 1305 | + | |
| 1306 | + | |
| 1307 | + | |
| 1308 | + | |
| 1309 | + | |
| 1310 | + | |
| 1311 | + | |
| 1312 | + | |
1235 | 1313 | | |
1236 | 1314 | | |
1237 | 1315 | | |
| |||
1242 | 1320 | | |
1243 | 1321 | | |
1244 | 1322 | | |
| 1323 | + | |
1245 | 1324 | | |
1246 | 1325 | | |
1247 | | - | |
1248 | | - | |
| 1326 | + | |
| 1327 | + | |
| 1328 | + | |
1249 | 1329 | | |
1250 | 1330 | | |
1251 | 1331 | | |
| |||
1291 | 1371 | | |
1292 | 1372 | | |
1293 | 1373 | | |
1294 | | - | |
| 1374 | + | |
1295 | 1375 | | |
1296 | 1376 | | |
1297 | 1377 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
200 | 200 | | |
201 | 201 | | |
202 | 202 | | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
203 | 209 | | |
204 | 210 | | |
205 | 211 | | |
| |||
219 | 225 | | |
220 | 226 | | |
221 | 227 | | |
| 228 | + | |
222 | 229 | | |
223 | 230 | | |
224 | 231 | | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
| 243 | + | |
| 244 | + | |
| 245 | + | |
| 246 | + | |
| 247 | + | |
| 248 | + | |
| 249 | + | |
| 250 | + | |
| 251 | + | |
| 252 | + | |
| 253 | + | |
| 254 | + | |
| 255 | + | |
| 256 | + | |
| 257 | + | |
| 258 | + | |
| 259 | + | |
| 260 | + | |
| 261 | + | |
| 262 | + | |
| 263 | + | |
| 264 | + | |
| 265 | + | |
| 266 | + | |
| 267 | + | |
| 268 | + | |
| 269 | + | |
| 270 | + | |
| 271 | + | |
| 272 | + | |
| 273 | + | |
| 274 | + | |
| 275 | + | |
| 276 | + | |
| 277 | + | |
| 278 | + | |
| 279 | + | |
| 280 | + | |
| 281 | + | |
| 282 | + | |
| 283 | + | |
| 284 | + | |
| 285 | + | |
| 286 | + | |
| 287 | + | |
| 288 | + | |
225 | 289 | | |
226 | 290 | | |
227 | 291 | | |
| |||
0 commit comments