@@ -2790,6 +2790,7 @@ TYPED_TEST(RawHashSamplerTest, Sample) {
27902790 absl::flat_hash_set<const HashtablezInfo*> preexisting_info (10 );
27912791 absl::flat_hash_map<size_t , int > observed_checksums (10 );
27922792 absl::flat_hash_map<ssize_t , int > reservations (10 );
2793+ absl::flat_hash_map<std::pair<size_t , size_t >, int > hit_misses (10 );
27932794
27942795 start_size += sampler.Iterate ([&](const HashtablezInfo& info) {
27952796 preexisting_info.insert (&info);
@@ -2802,14 +2803,23 @@ TYPED_TEST(RawHashSamplerTest, Sample) {
28022803
28032804 const bool do_reserve = (i % 10 > 5 );
28042805 const bool do_rehash = !do_reserve && (i % 10 > 0 );
2806+ const bool do_first_insert_hit = i % 2 == 0 ;
2807+ const bool do_second_insert_hit = i % 4 == 0 ;
28052808
28062809 if (do_reserve) {
28072810 // Don't reserve on all tables.
28082811 tables.back ().reserve (10 * (i % 10 ));
28092812 }
28102813
28112814 tables.back ().insert (1 );
2815+ if (do_first_insert_hit) {
2816+ tables.back ().insert (1 );
2817+ tables.back ().insert (1 );
2818+ }
28122819 tables.back ().insert (i % 5 );
2820+ if (do_second_insert_hit) {
2821+ tables.back ().insert (i % 5 );
2822+ }
28132823
28142824 if (do_rehash) {
28152825 // Rehash some other tables.
@@ -2823,6 +2833,10 @@ TYPED_TEST(RawHashSamplerTest, Sample) {
28232833 observed_checksums[info.hashes_bitwise_xor .load (
28242834 std::memory_order_relaxed)]++;
28252835 reservations[info.max_reserve .load (std::memory_order_relaxed)]++;
2836+ hit_misses[std::make_pair (
2837+ info.num_insert_hits .load (std::memory_order_relaxed),
2838+ info.size .load (std::memory_order_relaxed))]++;
2839+
28262840 EXPECT_EQ (info.inline_element_size , sizeof (typename TypeParam::value_type));
28272841 EXPECT_EQ (info.key_size , sizeof (typename TypeParam::key_type));
28282842 EXPECT_EQ (info.value_size , sizeof (typename TypeParam::value_type));
@@ -2850,6 +2864,21 @@ TYPED_TEST(RawHashSamplerTest, Sample) {
28502864 EXPECT_NEAR ((100 * count) / static_cast <double >(tables.size ()), 0.1 , 0.05 )
28512865 << reservation;
28522866 }
2867+
2868+ EXPECT_THAT (hit_misses, testing::SizeIs (6 ));
2869+ const double sampled_tables = end_size - start_size;
2870+ // i % 20: { 1, 11 }
2871+ EXPECT_NEAR ((hit_misses[{1 , 1 }] / sampled_tables), 0.10 , 0.02 );
2872+ // i % 20: { 6 }
2873+ EXPECT_NEAR ((hit_misses[{3 , 1 }] / sampled_tables), 0.05 , 0.02 );
2874+ // i % 20: { 0, 4, 8, 12 }
2875+ EXPECT_NEAR ((hit_misses[{3 , 2 }] / sampled_tables), 0.20 , 0.02 );
2876+ // i % 20: { 2, 10, 14, 18 }
2877+ EXPECT_NEAR ((hit_misses[{2 , 2 }] / sampled_tables), 0.20 , 0.02 );
2878+ // i % 20: { 16 }
2879+ EXPECT_NEAR ((hit_misses[{4 , 1 }] / sampled_tables), 0.05 , 0.02 );
2880+ // i % 20: { 3, 5, 7, 9, 13, 15, 17, 19 }
2881+ EXPECT_NEAR ((hit_misses[{0 , 2 }] / sampled_tables), 0.40 , 0.02 );
28532882}
28542883
28552884std::vector<const HashtablezInfo*> SampleSooMutation (
0 commit comments