Commit a8d3aba7 authored by Alexei Filippov's avatar Alexei Filippov Committed by Commit Bot

[heap profile] Report allocations count in UMA heap profiles.

BUG=878604

Change-Id: I0321b48834ccf85db9e72cb5942d2c53f8af3aac
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1628109Reviewed-by: default avatarMike Wittman <wittman@chromium.org>
Commit-Queue: Alexei Filippov <alph@chromium.org>
Cr-Commit-Position: refs/heads/master@{#663172}
parent e14ee2f3
...@@ -87,7 +87,11 @@ void HeapProfilerController::RetrieveAndSendSnapshot() { ...@@ -87,7 +87,11 @@ void HeapProfilerController::RetrieveAndSendSnapshot() {
module_cache.GetModuleForAddress(address); module_cache.GetModuleForAddress(address);
frames.emplace_back(address, module); frames.emplace_back(address, module);
} }
profile_builder.OnSampleCompleted(std::move(frames), sample.total); size_t count = std::max<size_t>(
static_cast<size_t>(
std::llround(static_cast<double>(sample.total) / sample.size)),
1);
profile_builder.OnSampleCompleted(std::move(frames), sample.total, count);
} }
profile_builder.OnProfileCompleted(base::TimeDelta(), base::TimeDelta()); profile_builder.OnProfileCompleted(base::TimeDelta(), base::TimeDelta());
......
...@@ -139,11 +139,12 @@ void CallStackProfileBuilder::RecordMetadata() { ...@@ -139,11 +139,12 @@ void CallStackProfileBuilder::RecordMetadata() {
void CallStackProfileBuilder::OnSampleCompleted( void CallStackProfileBuilder::OnSampleCompleted(
std::vector<base::Frame> frames) { std::vector<base::Frame> frames) {
OnSampleCompleted(std::move(frames), 1); OnSampleCompleted(std::move(frames), 1, 1);
} }
void CallStackProfileBuilder::OnSampleCompleted(std::vector<base::Frame> frames, void CallStackProfileBuilder::OnSampleCompleted(std::vector<base::Frame> frames,
size_t weight) { size_t weight,
size_t count) {
// Write CallStackProfile::Stack protobuf message. // Write CallStackProfile::Stack protobuf message.
CallStackProfile::Stack stack; CallStackProfile::Stack stack;
...@@ -193,6 +194,8 @@ void CallStackProfileBuilder::OnSampleCompleted(std::vector<base::Frame> frames, ...@@ -193,6 +194,8 @@ void CallStackProfileBuilder::OnSampleCompleted(std::vector<base::Frame> frames,
stack_sample_proto->set_stack_index(stack_loc->second); stack_sample_proto->set_stack_index(stack_loc->second);
if (weight != 1) if (weight != 1)
stack_sample_proto->set_weight(weight); stack_sample_proto->set_weight(weight);
if (count != 1)
stack_sample_proto->set_count(count);
if (is_continued_work_) if (is_continued_work_)
stack_sample_proto->set_continued_work(is_continued_work_); stack_sample_proto->set_continued_work(is_continued_work_);
......
...@@ -62,8 +62,10 @@ class CallStackProfileBuilder : public base::ProfileBuilder { ...@@ -62,8 +62,10 @@ class CallStackProfileBuilder : public base::ProfileBuilder {
~CallStackProfileBuilder() override; ~CallStackProfileBuilder() override;
// The weight is used by the heap profiler only. // Both weight and count are used by the heap profiler only.
void OnSampleCompleted(std::vector<base::Frame> frames, size_t weight); void OnSampleCompleted(std::vector<base::Frame> frames,
size_t weight,
size_t count);
// base::ProfileBuilder: // base::ProfileBuilder:
base::ModuleCache* GetModuleCache() override; base::ModuleCache* GetModuleCache() override;
......
...@@ -176,7 +176,7 @@ TEST(CallStackProfileBuilderTest, ProfilingCompleted) { ...@@ -176,7 +176,7 @@ TEST(CallStackProfileBuilderTest, ProfilingCompleted) {
EXPECT_EQ(100, profile.sampling_period_ms()); EXPECT_EQ(100, profile.sampling_period_ms());
} }
TEST(CallStackProfileBuilderTest, CustomWeights) { TEST(CallStackProfileBuilderTest, CustomWeightsAndCounts) {
auto profile_builder = auto profile_builder =
std::make_unique<TestingCallStackProfileBuilder>(kProfileParams); std::make_unique<TestingCallStackProfileBuilder>(kProfileParams);
...@@ -184,8 +184,8 @@ TEST(CallStackProfileBuilderTest, CustomWeights) { ...@@ -184,8 +184,8 @@ TEST(CallStackProfileBuilderTest, CustomWeights) {
base::Frame frame1 = {0x10, &module1}; base::Frame frame1 = {0x10, &module1};
std::vector<base::Frame> frames = {frame1}; std::vector<base::Frame> frames = {frame1};
profile_builder->OnSampleCompleted(frames, 42); profile_builder->OnSampleCompleted(frames, 42, 3);
profile_builder->OnSampleCompleted(frames, 1); profile_builder->OnSampleCompleted(frames, 1, 1);
profile_builder->OnSampleCompleted(frames); profile_builder->OnSampleCompleted(frames);
profile_builder->OnProfileCompleted(base::TimeDelta(), base::TimeDelta()); profile_builder->OnProfileCompleted(base::TimeDelta(), base::TimeDelta());
...@@ -195,9 +195,13 @@ TEST(CallStackProfileBuilderTest, CustomWeights) { ...@@ -195,9 +195,13 @@ TEST(CallStackProfileBuilderTest, CustomWeights) {
const CallStackProfile& profile = proto.call_stack_profile(); const CallStackProfile& profile = proto.call_stack_profile();
ASSERT_EQ(3, profile.stack_sample_size()); ASSERT_EQ(3, profile.stack_sample_size());
EXPECT_TRUE(profile.stack_sample(0).has_weight()); EXPECT_TRUE(profile.stack_sample(0).has_weight());
EXPECT_TRUE(profile.stack_sample(0).has_count());
EXPECT_EQ(42, profile.stack_sample(0).weight()); EXPECT_EQ(42, profile.stack_sample(0).weight());
EXPECT_EQ(3, profile.stack_sample(0).count());
EXPECT_FALSE(profile.stack_sample(1).has_weight()); EXPECT_FALSE(profile.stack_sample(1).has_weight());
EXPECT_FALSE(profile.stack_sample(1).has_count());
EXPECT_FALSE(profile.stack_sample(2).has_weight()); EXPECT_FALSE(profile.stack_sample(2).has_weight());
EXPECT_FALSE(profile.stack_sample(2).has_count());
} }
TEST(CallStackProfileBuilderTest, StacksDeduped) { TEST(CallStackProfileBuilderTest, StacksDeduped) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment