Commit 2bf79e4d authored by Ulan Degenbaev's avatar Ulan Degenbaev Committed by Commit Bot

Properly set PerIsolateV8MemoryUsage::unassociated_bytes_used

This CL also makes V8DetailedMemoryReporterImplTest more robust by
replacing array allocation with a typed array nested in an object.

Bug: 1131491
Change-Id: If5fec7cc81aac0f33f068ecff3b928a1ceb7ede2
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2438372Reviewed-by: default avatarJoe Mason <joenotcharles@chromium.org>
Commit-Queue: Ulan Degenbaev <ulan@chromium.org>
Cr-Commit-Position: refs/heads/master@{#812079}
parent 83aea86e
...@@ -85,6 +85,7 @@ class FrameAssociatedMeasurementDelegate : public v8::MeasureMemoryDelegate { ...@@ -85,6 +85,7 @@ class FrameAssociatedMeasurementDelegate : public v8::MeasureMemoryDelegate {
#endif #endif
isolate_memory_usage->contexts.push_back(std::move(context_memory_usage)); isolate_memory_usage->contexts.push_back(std::move(context_memory_usage));
} }
isolate_memory_usage->unassociated_bytes_used = unattributed_size_in_bytes;
std::move(callback_).Run(std::move(isolate_memory_usage)); std::move(callback_).Run(std::move(isolate_memory_usage));
} }
......
...@@ -33,10 +33,11 @@ class MemoryUsageChecker { ...@@ -33,10 +33,11 @@ class MemoryUsageChecker {
size_t actual_context_count = 0; size_t actual_context_count = 0;
for (const auto& isolate : result->isolates) { for (const auto& isolate : result->isolates) {
for (const auto& entry : isolate->contexts) { for (const auto& entry : isolate->contexts) {
// Each context allocates an array of 1000000u elements, thus 4000000u // The memory usage of each context should be at least 1000000 bytes
// is a lower bound of the memory usage on any platform. We cannot make // because each context allocates a byte array of that length. Since
// this check more strict without making the test fragile. // other objects are allocated during context initialization we can
EXPECT_LT(4000000u, entry->bytes_used); // only check the lower bound.
EXPECT_LE(1000000u, entry->bytes_used);
++actual_context_count; ++actual_context_count;
} }
} }
...@@ -64,7 +65,9 @@ TEST_F(V8DetailedMemoryReporterImplTest, GetV8MemoryUsage) { ...@@ -64,7 +65,9 @@ TEST_F(V8DetailedMemoryReporterImplTest, GetV8MemoryUsage) {
main_resource.Complete(R"HTML( main_resource.Complete(R"HTML(
<script> <script>
window.onload = function () { window.onload = function () {
globalThis.array = new Array(1000000).fill(0); globalThis.root = {
array: new Uint8Array(1000000)
};
console.log("main loaded"); console.log("main loaded");
} }
</script> </script>
...@@ -77,7 +80,9 @@ TEST_F(V8DetailedMemoryReporterImplTest, GetV8MemoryUsage) { ...@@ -77,7 +80,9 @@ TEST_F(V8DetailedMemoryReporterImplTest, GetV8MemoryUsage) {
child_frame_resource.Complete(R"HTML( child_frame_resource.Complete(R"HTML(
<script> <script>
window.onload = function () { window.onload = function () {
globalThis.array = new Array(1000000).fill(0); globalThis.root = {
array: new Uint8Array(1000000)
};
console.log("iframe loaded"); console.log("iframe loaded");
} }
</script> </script>
...@@ -107,7 +112,10 @@ TEST_F(V8DetailedMemoryReporterImplTest, GetV8MemoryUsage) { ...@@ -107,7 +112,10 @@ TEST_F(V8DetailedMemoryReporterImplTest, GetV8MemoryUsage) {
} }
TEST_F(V8DetailedMemoryReporterImplWorkerTest, GetV8MemoryUsage) { TEST_F(V8DetailedMemoryReporterImplWorkerTest, GetV8MemoryUsage) {
const String source_code = "globalThis.array = new Array(1000000).fill(0);"; const String source_code = R"JS(
globalThis.root = {
array: new Uint8Array(1000000)
};)JS";
StartWorker(source_code); StartWorker(source_code);
WaitUntilWorkerIsRunning(); WaitUntilWorkerIsRunning();
V8DetailedMemoryReporterImpl reporter; V8DetailedMemoryReporterImpl reporter;
......
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