Skip to content

Commit 2aad051

Browse files
xrocheclaude
andcommitted
fix: correct SetItemsProcessed in BM_GetTlState benchmark
SetItemsProcessed was called inside the benchmark loop with a per-iteration count. google benchmark expects the cumulative total after the loop ends. Move the call after the loop and compute it from state.iterations(). Also remove the now-unused total_ops atomic and per-thread ops counter. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent bb7fa90 commit 2aad051

1 file changed

Lines changed: 1 addition & 6 deletions

File tree

test/allocation_tracker-bench.cc

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -335,7 +335,6 @@ static void BM_GetTlState(benchmark::State &state) {
335335
std::atomic<int> ready_count{0};
336336
std::atomic<bool> go{false};
337337
std::atomic<bool> done{false};
338-
std::atomic<int64_t> total_ops{0};
339338

340339
std::vector<std::thread> workers;
341340
workers.reserve(nb_threads);
@@ -351,13 +350,10 @@ static void BM_GetTlState(benchmark::State &state) {
351350
break;
352351
}
353352
// Hot loop: pure TLS access
354-
int64_t ops = 0;
355353
for (int j = 0; j < k_ops_per_iter; ++j) {
356354
auto *tl = ddprof::AllocationTracker::get_tl_state();
357355
benchmark::DoNotOptimize(tl);
358-
++ops;
359356
}
360-
total_ops.fetch_add(ops, std::memory_order_relaxed);
361357
ready_count.fetch_sub(1, std::memory_order_release);
362358
// wait for go to be lowered before looping back
363359
while (go.load(std::memory_order_acquire) &&
@@ -367,15 +363,14 @@ static void BM_GetTlState(benchmark::State &state) {
367363
}
368364

369365
for (auto _ : state) {
370-
total_ops.store(0, std::memory_order_relaxed);
371366
// Wait for all workers to be ready
372367
while (ready_count.load(std::memory_order_acquire) != nb_threads) {}
373368
go.store(true, std::memory_order_release);
374369
// Wait for all workers to finish the hot loop
375370
while (ready_count.load(std::memory_order_acquire) != 0) {}
376371
go.store(false, std::memory_order_release);
377-
state.SetItemsProcessed(total_ops.load(std::memory_order_relaxed));
378372
}
373+
state.SetItemsProcessed(state.iterations() * nb_threads * k_ops_per_iter);
379374

380375
done.store(true, std::memory_order_release);
381376
go.store(true, std::memory_order_release); // unblock workers

0 commit comments

Comments
 (0)