Skip to content

Commit ea64b6e

Browse files
ckennellycopybara-github
authored andcommitted
Consume result from various SampleRecorder methods.
PiperOrigin-RevId: 897903309 Change-Id: I944031c84f2bcc6c116cef750ce789381b134467
1 parent 9cb62a0 commit ea64b6e

3 files changed

Lines changed: 27 additions & 17 deletions

File tree

absl/container/internal/hashtablez_sampler_test.cc

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -63,9 +63,10 @@ using ::testing::UnorderedElementsAre;
6363

6464
std::vector<size_t> GetSizes(HashtablezSampler* s) {
6565
std::vector<size_t> res;
66-
s->Iterate([&](const HashtablezInfo& info) {
66+
EXPECT_EQ(s->Iterate([&](const HashtablezInfo& info) {
6767
res.push_back(info.size.load(std::memory_order_acquire));
68-
});
68+
}),
69+
0);
6970
return res;
7071
}
7172

@@ -359,27 +360,29 @@ TEST(HashtablezSamplerTest, Handle) {
359360
info->hashes_bitwise_and.store(0x12345678, std::memory_order_relaxed);
360361

361362
bool found = false;
362-
sampler.Iterate([&](const HashtablezInfo& h) {
363+
EXPECT_EQ(sampler.Iterate([&](const HashtablezInfo& h) {
363364
if (&h == info) {
364365
EXPECT_EQ(h.weight, test_stride);
365366
EXPECT_EQ(h.hashes_bitwise_and.load(), 0x12345678);
366367
found = true;
367368
}
368-
});
369+
}),
370+
0);
369371
EXPECT_TRUE(found);
370372

371373
h.Unregister();
372374
h = HashtablezInfoHandle();
373375
found = false;
374-
sampler.Iterate([&](const HashtablezInfo& h) {
376+
EXPECT_EQ(sampler.Iterate([&](const HashtablezInfo& h) {
375377
if (&h == info) {
376378
// this will only happen if some other thread has resurrected the info
377379
// the old handle was using.
378380
if (h.hashes_bitwise_and.load() == 0x12345678) {
379381
found = true;
380382
}
381383
}
382-
});
384+
}),
385+
0);
383386
EXPECT_FALSE(found);
384387
}
385388
#endif
@@ -465,9 +468,10 @@ TEST(HashtablezSamplerTest, MultiThreaded) {
465468
}
466469
case 2: {
467470
absl::Duration oldest = absl::ZeroDuration();
468-
sampler.Iterate([&](const HashtablezInfo& info) {
471+
EXPECT_EQ(sampler.Iterate([&](const HashtablezInfo& info) {
469472
oldest = std::max(oldest, absl::Now() - info.create_time);
470-
});
473+
}),
474+
0);
471475
ASSERT_GE(oldest, absl::ZeroDuration());
472476
break;
473477
}

absl/container/sample_element_size_test.cc

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,12 +57,13 @@ void TestInlineElementSize(
5757
tables.back().insert(values.begin(), values.end());
5858
}
5959
size_t new_count = 0;
60-
sampler.Iterate([&](const HashtablezInfo& info) {
60+
EXPECT_EQ(sampler.Iterate([&](const HashtablezInfo& info) {
6161
if (preexisting_info.insert(&info).second) {
6262
EXPECT_EQ(info.inline_element_size, expected_element_size);
6363
++new_count;
6464
}
65-
});
65+
}),
66+
0);
6667
// Make sure we actually did get a new hashtablez.
6768
EXPECT_GT(new_count, 0);
6869
}
@@ -99,8 +100,10 @@ TEST(FlatHashMap, SampleElementSize) {
99100
// cannot be a flat_hash_set, however, since that would introduce a mutex
100101
// deadlock.
101102
std::unordered_set<const HashtablezInfo*> preexisting_info; // NOLINT
102-
sampler.Iterate(
103-
[&](const HashtablezInfo& info) { preexisting_info.insert(&info); });
103+
EXPECT_EQ(sampler.Iterate([&](const HashtablezInfo& info) {
104+
preexisting_info.insert(&info);
105+
}),
106+
0);
104107
TestInlineElementSize(sampler, preexisting_info, flat_map_tables, map_values,
105108
sizeof(int) + sizeof(bigstruct));
106109
TestInlineElementSize(sampler, preexisting_info, node_map_tables, map_values,

absl/profiling/internal/sample_recorder_test.cc

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -49,15 +49,17 @@ struct Info : public Sample<Info> {
4949

5050
std::vector<size_t> GetSizes(SampleRecorder<Info>* s) {
5151
std::vector<size_t> res;
52-
s->Iterate([&](const Info& info) {
52+
EXPECT_EQ(s->Iterate([&](const Info& info) {
5353
res.push_back(info.size.load(std::memory_order_acquire));
54-
});
54+
}),
55+
0);
5556
return res;
5657
}
5758

5859
std::vector<int64_t> GetWeights(SampleRecorder<Info>* s) {
5960
std::vector<int64_t> res;
60-
s->Iterate([&](const Info& info) { res.push_back(info.weight); });
61+
EXPECT_EQ(s->Iterate([&](const Info& info) { res.push_back(info.weight); }),
62+
0);
6163
return res;
6264
}
6365

@@ -141,9 +143,10 @@ TEST(SampleRecorderTest, MultiThreaded) {
141143
}
142144
case 2: {
143145
absl::Duration oldest = absl::ZeroDuration();
144-
sampler.Iterate([&](const Info& info) {
146+
EXPECT_EQ(sampler.Iterate([&](const Info& info) {
145147
oldest = std::max(oldest, absl::Now() - info.create_time);
146-
});
148+
}),
149+
0);
147150
ASSERT_GE(oldest, absl::ZeroDuration());
148151
break;
149152
}

0 commit comments

Comments
 (0)