Skip to content

Commit 21a1baf

Browse files
ckennellycopybara-github
authored andcommitted
Consume result from various SampleRecorder methods.
PiperOrigin-RevId: 897953609
1 parent 106f474 commit 21a1baf

1 file changed

Lines changed: 19 additions & 12 deletions

File tree

src/google/protobuf/arenaz_sampler_test.cc

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -50,15 +50,16 @@ class ThreadSafeArenaStatsHandlePeer {
5050

5151
std::vector<size_t> GetBytesAllocated(ThreadSafeArenazSampler* s) {
5252
std::vector<size_t> res;
53-
s->Iterate([&](const ThreadSafeArenaStats& info) {
53+
EXPECT_EQ(s->Iterate([&](const ThreadSafeArenaStats& info) {
5454
for (const auto& block_stats : info.block_histogram) {
5555
size_t bytes_allocated =
5656
block_stats.bytes_allocated.load(std::memory_order_acquire);
5757
if (bytes_allocated != 0) {
5858
res.push_back(bytes_allocated);
5959
}
6060
}
61-
});
61+
}),
62+
0);
6263
return res;
6364
}
6465

@@ -268,20 +269,21 @@ TEST(ThreadSafeArenazSamplerTest, Handle) {
268269
std::memory_order_relaxed);
269270

270271
bool found = false;
271-
sampler.Iterate([&](const ThreadSafeArenaStats& h) {
272+
EXPECT_EQ(sampler.Iterate([&](const ThreadSafeArenaStats& h) {
272273
if (&h == info) {
273274
EXPECT_EQ(
274275
h.block_histogram[0].bytes_allocated.load(std::memory_order_relaxed),
275276
0x12345678);
276277
EXPECT_EQ(h.weight, kTestStride);
277278
found = true;
278279
}
279-
});
280+
}),
281+
0);
280282
EXPECT_TRUE(found);
281283

282284
h = ThreadSafeArenaStatsHandle();
283285
found = false;
284-
sampler.Iterate([&](const ThreadSafeArenaStats& h) {
286+
EXPECT_EQ(sampler.Iterate([&](const ThreadSafeArenaStats& h) {
285287
if (&h == info) {
286288
// this will only happen if some other thread has resurrected the info
287289
// the old handle was using.
@@ -290,7 +292,8 @@ TEST(ThreadSafeArenazSamplerTest, Handle) {
290292
found = true;
291293
}
292294
}
293-
});
295+
}),
296+
0);
294297
EXPECT_FALSE(found);
295298
}
296299

@@ -424,15 +427,16 @@ TEST(ThreadSafeArenazSamplerTest, InitialBlockReportsZeroUsedAndWasted) {
424427
char block[kSize];
425428
google::protobuf::Arena arena(/*initial_block=*/block, /*initial_block_size=*/kSize);
426429
benchmark::DoNotOptimize(&arena);
427-
sampler.Iterate([&](const ThreadSafeArenaStats& h) {
430+
EXPECT_EQ(sampler.Iterate([&](const ThreadSafeArenaStats& h) {
428431
const auto& histbin =
429432
h.block_histogram[ThreadSafeArenaStats::FindBin(kSize)];
430433
if (histbin.bytes_allocated.load(std::memory_order_relaxed) == kSize) {
431434
count_found_allocation++;
432435
EXPECT_EQ(histbin.bytes_used, 0);
433436
EXPECT_EQ(histbin.bytes_wasted, 0);
434437
}
435-
});
438+
}),
439+
0);
436440
}
437441
EXPECT_GT(count_found_allocation, 0);
438442
SetThreadSafeArenazSampleParameter(oldparam);
@@ -491,7 +495,8 @@ TEST(ThreadSafeArenazSamplerTest, MultiThread) {
491495
if (barrier->Block()) {
492496
delete barrier;
493497
}
494-
sampler.Iterate([&](const ThreadSafeArenaStats& h) { ++count; });
498+
EXPECT_EQ(sampler.Iterate([&](const ThreadSafeArenaStats& h) { ++count; }),
499+
0);
495500
for (int i = 0; i < kNumThreads; i++) {
496501
threads[i]->Join();
497502
}
@@ -535,7 +540,8 @@ TEST(ThreadSafeArenazSamplerTest, SampleFirstArena) {
535540

536541
auto count_samples = [&]() {
537542
int count = 0;
538-
sampler.Iterate([&](const ThreadSafeArenaStats& h) { ++count; });
543+
EXPECT_EQ(sampler.Iterate([&](const ThreadSafeArenaStats& h) { ++count; }),
544+
0);
539545
return count;
540546
};
541547

@@ -600,7 +606,7 @@ TEST(ThreadSafeArenazSamplerTest, UsedAndWasted) {
600606
for (int i = 0; i < 1000; ++i) {
601607
(void)Arena::Create<char>(&arena);
602608
}
603-
sampler.Iterate([&](const ThreadSafeArenaStats& h) {
609+
EXPECT_EQ(sampler.Iterate([&](const ThreadSafeArenaStats& h) {
604610
for (size_t i = 0; i < 3; ++i) {
605611
constexpr auto kSize =
606612
google::protobuf::internal::AllocationPolicy::kDefaultStartBlockSize;
@@ -611,7 +617,8 @@ TEST(ThreadSafeArenazSamplerTest, UsedAndWasted) {
611617
(kSize << i) - google::protobuf::internal::SerialArena::kBlockHeaderSize);
612618
EXPECT_EQ(histbin.bytes_wasted, 0);
613619
}
614-
});
620+
}),
621+
0);
615622
SetThreadSafeArenazSampleParameter(oldparam);
616623
}
617624
#endif // defined(PROTOBUF_ARENAZ_SAMPLE)

0 commit comments

Comments
 (0)