mirror of
https://github.com/abseil/abseil-cpp.git
synced 2026-06-04 20:14:23 +08:00
Consume result from various SampleRecorder methods.
PiperOrigin-RevId: 897903309 Change-Id: I944031c84f2bcc6c116cef750ce789381b134467
This commit is contained in:
committed by
Copybara-Service
parent
9cb62a03a4
commit
ea64b6e7e6
@@ -63,9 +63,10 @@ using ::testing::UnorderedElementsAre;
|
||||
|
||||
std::vector<size_t> GetSizes(HashtablezSampler* s) {
|
||||
std::vector<size_t> res;
|
||||
s->Iterate([&](const HashtablezInfo& info) {
|
||||
EXPECT_EQ(s->Iterate([&](const HashtablezInfo& info) {
|
||||
res.push_back(info.size.load(std::memory_order_acquire));
|
||||
});
|
||||
}),
|
||||
0);
|
||||
return res;
|
||||
}
|
||||
|
||||
@@ -359,19 +360,20 @@ TEST(HashtablezSamplerTest, Handle) {
|
||||
info->hashes_bitwise_and.store(0x12345678, std::memory_order_relaxed);
|
||||
|
||||
bool found = false;
|
||||
sampler.Iterate([&](const HashtablezInfo& h) {
|
||||
EXPECT_EQ(sampler.Iterate([&](const HashtablezInfo& h) {
|
||||
if (&h == info) {
|
||||
EXPECT_EQ(h.weight, test_stride);
|
||||
EXPECT_EQ(h.hashes_bitwise_and.load(), 0x12345678);
|
||||
found = true;
|
||||
}
|
||||
});
|
||||
}),
|
||||
0);
|
||||
EXPECT_TRUE(found);
|
||||
|
||||
h.Unregister();
|
||||
h = HashtablezInfoHandle();
|
||||
found = false;
|
||||
sampler.Iterate([&](const HashtablezInfo& h) {
|
||||
EXPECT_EQ(sampler.Iterate([&](const HashtablezInfo& h) {
|
||||
if (&h == info) {
|
||||
// this will only happen if some other thread has resurrected the info
|
||||
// the old handle was using.
|
||||
@@ -379,7 +381,8 @@ TEST(HashtablezSamplerTest, Handle) {
|
||||
found = true;
|
||||
}
|
||||
}
|
||||
});
|
||||
}),
|
||||
0);
|
||||
EXPECT_FALSE(found);
|
||||
}
|
||||
#endif
|
||||
@@ -465,9 +468,10 @@ TEST(HashtablezSamplerTest, MultiThreaded) {
|
||||
}
|
||||
case 2: {
|
||||
absl::Duration oldest = absl::ZeroDuration();
|
||||
sampler.Iterate([&](const HashtablezInfo& info) {
|
||||
EXPECT_EQ(sampler.Iterate([&](const HashtablezInfo& info) {
|
||||
oldest = std::max(oldest, absl::Now() - info.create_time);
|
||||
});
|
||||
}),
|
||||
0);
|
||||
ASSERT_GE(oldest, absl::ZeroDuration());
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -57,12 +57,13 @@ void TestInlineElementSize(
|
||||
tables.back().insert(values.begin(), values.end());
|
||||
}
|
||||
size_t new_count = 0;
|
||||
sampler.Iterate([&](const HashtablezInfo& info) {
|
||||
EXPECT_EQ(sampler.Iterate([&](const HashtablezInfo& info) {
|
||||
if (preexisting_info.insert(&info).second) {
|
||||
EXPECT_EQ(info.inline_element_size, expected_element_size);
|
||||
++new_count;
|
||||
}
|
||||
});
|
||||
}),
|
||||
0);
|
||||
// Make sure we actually did get a new hashtablez.
|
||||
EXPECT_GT(new_count, 0);
|
||||
}
|
||||
@@ -99,8 +100,10 @@ TEST(FlatHashMap, SampleElementSize) {
|
||||
// cannot be a flat_hash_set, however, since that would introduce a mutex
|
||||
// deadlock.
|
||||
std::unordered_set<const HashtablezInfo*> preexisting_info; // NOLINT
|
||||
sampler.Iterate(
|
||||
[&](const HashtablezInfo& info) { preexisting_info.insert(&info); });
|
||||
EXPECT_EQ(sampler.Iterate([&](const HashtablezInfo& info) {
|
||||
preexisting_info.insert(&info);
|
||||
}),
|
||||
0);
|
||||
TestInlineElementSize(sampler, preexisting_info, flat_map_tables, map_values,
|
||||
sizeof(int) + sizeof(bigstruct));
|
||||
TestInlineElementSize(sampler, preexisting_info, node_map_tables, map_values,
|
||||
|
||||
@@ -49,15 +49,17 @@ struct Info : public Sample<Info> {
|
||||
|
||||
std::vector<size_t> GetSizes(SampleRecorder<Info>* s) {
|
||||
std::vector<size_t> res;
|
||||
s->Iterate([&](const Info& info) {
|
||||
EXPECT_EQ(s->Iterate([&](const Info& info) {
|
||||
res.push_back(info.size.load(std::memory_order_acquire));
|
||||
});
|
||||
}),
|
||||
0);
|
||||
return res;
|
||||
}
|
||||
|
||||
std::vector<int64_t> GetWeights(SampleRecorder<Info>* s) {
|
||||
std::vector<int64_t> res;
|
||||
s->Iterate([&](const Info& info) { res.push_back(info.weight); });
|
||||
EXPECT_EQ(s->Iterate([&](const Info& info) { res.push_back(info.weight); }),
|
||||
0);
|
||||
return res;
|
||||
}
|
||||
|
||||
@@ -141,9 +143,10 @@ TEST(SampleRecorderTest, MultiThreaded) {
|
||||
}
|
||||
case 2: {
|
||||
absl::Duration oldest = absl::ZeroDuration();
|
||||
sampler.Iterate([&](const Info& info) {
|
||||
EXPECT_EQ(sampler.Iterate([&](const Info& info) {
|
||||
oldest = std::max(oldest, absl::Now() - info.create_time);
|
||||
});
|
||||
}),
|
||||
0);
|
||||
ASSERT_GE(oldest, absl::ZeroDuration());
|
||||
break;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user