Commit 6b129066 authored by Ulan Degenbaev's avatar Ulan Degenbaev Committed by Commit Bot

[test] Make SamplingHeapProfilerRateAgnosticEstimates more robust.

The function allocating objects in the test can be inlined in the middle
of the run. All allocations after inlining are currently not accounted.
This patch sums up allocations of the function and its outer function.

The difference between counts is now about 4%-6% (down from 15%).

Bug: chromium:834832
Change-Id: Iad071bd5bf53bb3527c9cb24d0a9ea38618c833c
Reviewed-on: https://chromium-review.googlesource.com/1021734Reviewed-by: 's avatarAli Ijaz Sheikh <ofrobots@google.com>
Commit-Queue: Ulan Degenbaev <ulan@chromium.org>
Cr-Commit-Position: refs/heads/master@{#52713}
parent db065139
......@@ -3190,6 +3190,14 @@ static void CheckNoZeroCountNodes(v8::AllocationProfile::Node* node) {
}
}
static int NumberOfAllocations(const v8::AllocationProfile::Node* node) {
int count = 0;
for (auto allocation : node->allocations) {
count += allocation.count;
}
return count;
}
static const char* simple_sampling_heap_profiler_script =
"var A = [];\n"
"function bar(size) { return new Array(size); }\n"
......@@ -3231,12 +3239,6 @@ TEST(SamplingHeapProfiler) {
ArrayVector(names));
CHECK(node_bar);
// Count the number of allocations we sampled from bar.
int count_1024 = 0;
for (auto allocation : node_bar->allocations) {
count_1024 += allocation.count;
}
heap_profiler->StopSamplingHeapProfiler();
}
......@@ -3313,15 +3315,17 @@ TEST(SamplingHeapProfilerRateAgnosticEstimates) {
heap_profiler->GetAllocationProfile());
CHECK(profile);
const char* names[] = {"", "foo", "bar"};
const char* path_to_foo[] = {"", "foo"};
auto node_foo = FindAllocationProfileNode(env->GetIsolate(), *profile,
ArrayVector(path_to_foo));
CHECK(node_foo);
const char* path_to_bar[] = {"", "foo", "bar"};
auto node_bar = FindAllocationProfileNode(env->GetIsolate(), *profile,
ArrayVector(names));
ArrayVector(path_to_bar));
CHECK(node_bar);
// Count the number of allocations we sampled from bar.
for (auto allocation : node_bar->allocations) {
count_1024 += allocation.count;
}
// Function bar can be inlined in foo.
count_1024 = NumberOfAllocations(node_foo) + NumberOfAllocations(node_bar);
heap_profiler->StopSamplingHeapProfiler();
}
......@@ -3335,16 +3339,18 @@ TEST(SamplingHeapProfilerRateAgnosticEstimates) {
heap_profiler->GetAllocationProfile());
CHECK(profile);
const char* names[] = {"", "foo", "bar"};
const char* path_to_foo[] = {"", "foo"};
auto node_foo = FindAllocationProfileNode(env->GetIsolate(), *profile,
ArrayVector(path_to_foo));
CHECK(node_foo);
const char* path_to_bar[] = {"", "foo", "bar"};
auto node_bar = FindAllocationProfileNode(env->GetIsolate(), *profile,
ArrayVector(names));
ArrayVector(path_to_bar));
CHECK(node_bar);
// Count the number of allocations we sampled from bar.
int count_128 = 0;
for (auto allocation : node_bar->allocations) {
count_128 += allocation.count;
}
// Function bar can be inlined in foo.
int count_128 =
NumberOfAllocations(node_foo) + NumberOfAllocations(node_bar);
// We should have similar unsampled counts of allocations. Though
// we will sample different numbers of objects at different rates,
......@@ -3355,8 +3361,7 @@ TEST(SamplingHeapProfilerRateAgnosticEstimates) {
double max_count = std::max(count_128, count_1024);
double min_count = std::min(count_128, count_1024);
double percent_difference = (max_count - min_count) / min_count;
// TODO(ulan): Restore the original 0.15 after fixing crbug.com/834832.
CHECK_LT(percent_difference, 0.2);
CHECK_LT(percent_difference, 0.1);
heap_profiler->StopSamplingHeapProfiler();
}
......
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