Skip to content

Commit bf891a1

Browse files
ckennellycopybara-github
authored andcommitted
Represent dropped samples in hashtable profile.
PiperOrigin-RevId: 817877427 Change-Id: I57cf4880ff39851b7dce4d96bb0897a9fc43d8a0
1 parent 79549fe commit bf891a1

File tree

1 file changed

+14
-4
lines changed

1 file changed

+14
-4
lines changed

absl/profiling/hashtable.cc

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@ StatusOr<std::string> MarshalHashtableProfile() {
4242

4343
namespace debugging_internal {
4444

45+
static void DroppedHashtableSample() {}
46+
4547
StatusOr<std::string> MarshalHashtableProfile(
4648
container_internal::HashtablezSampler& sampler, Time now) {
4749
static constexpr absl::string_view kDropFrames =
@@ -111,10 +113,18 @@ StatusOr<std::string> MarshalHashtableProfile(
111113
MakeSpan(info.stack, info.depth), labels);
112114
});
113115

114-
// TODO(b/262310142): Make this more structured data.
115-
StringId comment_id =
116-
builder.InternString(StrCat("dropped_samples: ", dropped));
117-
builder.set_comment_id(comment_id);
116+
if (dropped > 0) {
117+
// If we dropped samples, we don't have information for them, including
118+
// their sizes. The non-zero weight allows it to be noticed in the profile
119+
// and examined more closely.
120+
//
121+
// We compensate for the fixup done by AddSample by adjusting the address
122+
// here.
123+
const void* kFakeStack[] = {
124+
absl::bit_cast<void*>(
125+
reinterpret_cast<uintptr_t>(&DroppedHashtableSample)+1)};
126+
builder.AddSample(static_cast<int64_t>(dropped), kFakeStack, {});
127+
}
118128
builder.AddCurrentMappings();
119129
return std::move(builder).Emit();
120130
}

0 commit comments

Comments
 (0)