From 48abb9fe0eeaf0149f0351acb00201f07e79f293 Mon Sep 17 00:00:00 2001 From: Chris Kennelly Date: Mon, 25 Mar 2024 13:16:00 -0700 Subject: Record sizeof(key_type), sizeof(value_type) in hashtable profiles. This can identify situations where flat_hash_* is suboptimal for large elements. PiperOrigin-RevId: 618937993 Change-Id: I2bde069bc3526b14ad1718ba6f50467002aeed16 --- absl/container/internal/hashtablez_sampler.cc | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) (limited to 'absl/container/internal/hashtablez_sampler.cc') diff --git a/absl/container/internal/hashtablez_sampler.cc b/absl/container/internal/hashtablez_sampler.cc index e17ba14d..fd21d966 100644 --- a/absl/container/internal/hashtablez_sampler.cc +++ b/absl/container/internal/hashtablez_sampler.cc @@ -79,6 +79,8 @@ HashtablezInfo::~HashtablezInfo() = default; void HashtablezInfo::PrepareForSampling(int64_t stride, size_t inline_element_size_value, + size_t key_size_value, + size_t value_size_value, uint16_t soo_capacity_value) { capacity.store(0, std::memory_order_relaxed); size.store(0, std::memory_order_relaxed); @@ -99,6 +101,8 @@ void HashtablezInfo::PrepareForSampling(int64_t stride, depth = absl::GetStackTrace(stack, HashtablezInfo::kMaxStackDepth, /* skip_count= */ 0); inline_element_size = inline_element_size_value; + key_size = key_size_value; + value_size = value_size_value; soo_capacity = soo_capacity_value; } @@ -123,12 +127,13 @@ static bool ShouldForceSampling() { } HashtablezInfo* SampleSlow(SamplingState& next_sample, - size_t inline_element_size, uint16_t soo_capacity) { + size_t inline_element_size, size_t key_size, + size_t value_size, uint16_t soo_capacity) { if (ABSL_PREDICT_FALSE(ShouldForceSampling())) { next_sample.next_sample = 1; const int64_t old_stride = exchange(next_sample.sample_stride, 1); HashtablezInfo* result = GlobalHashtablezSampler().Register( - old_stride, inline_element_size, soo_capacity); + old_stride, inline_element_size, key_size, value_size, soo_capacity); return result; } @@ -158,11 +163,12 @@ HashtablezInfo* SampleSlow(SamplingState& next_sample, // that case. if (first) { if (ABSL_PREDICT_TRUE(--next_sample.next_sample > 0)) return nullptr; - return SampleSlow(next_sample, inline_element_size, soo_capacity); + return SampleSlow(next_sample, inline_element_size, key_size, value_size, + soo_capacity); } return GlobalHashtablezSampler().Register(old_stride, inline_element_size, - soo_capacity); + key_size, value_size, soo_capacity); #endif } -- cgit v1.2.3