Commit bfeeec97 authored by Sigurdur Asgeirsson's avatar Sigurdur Asgeirsson Committed by Commit Bot

PM: Serialize per-frame data in a vector instead of a map.

There's no need to represent this as a map on the wire and it creates
complications in the mojo bindings for upcoming CLs.

Bug: 1080672
Change-Id: I20cfe281d5dbb752bd5b376e45f6d1e1aff98852
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2250790Reviewed-by: default avatarJoe Mason <joenotcharles@chromium.org>
Reviewed-by: default avatarWill Harris <wfh@chromium.org>
Commit-Queue: Sigurður Ásgeirsson <siggi@chromium.org>
Cr-Commit-Position: refs/heads/master@{#780301}
parent 823f5b8a
...@@ -134,9 +134,19 @@ void NodeAttachedProcessData::OnPerFrameV8MemoryUsageData( ...@@ -134,9 +134,19 @@ void NodeAttachedProcessData::OnPerFrameV8MemoryUsageData(
// existing frame is likewise accured to unassociated usage. // existing frame is likewise accured to unassociated usage.
uint64_t unassociated_v8_bytes_used = result->unassociated_bytes_used; uint64_t unassociated_v8_bytes_used = result->unassociated_bytes_used;
// Create a mapping from token to per-frame usage for the merge below.
// Note that in the presence of multiple records with identical
// dev_tools_token fields, this will throw away all but one of those
// records.
// TODO(https://crbug.com/1096543): Change to using the frame-unique token and
// validate that multiple frames/records don't carry the same token.
std::vector<
std::pair<base::UnguessableToken, mojom::PerFrameV8MemoryUsageDataPtr>>
tmp;
for (auto& entry : result->associated_memory)
tmp.emplace_back(std::make_pair(entry->dev_tools_token, std::move(entry)));
base::flat_map<base::UnguessableToken, mojom::PerFrameV8MemoryUsageDataPtr> base::flat_map<base::UnguessableToken, mojom::PerFrameV8MemoryUsageDataPtr>
associated_memory; associated_memory(std::move(tmp));
associated_memory.swap(result->associated_memory);
base::flat_set<const FrameNode*> frame_nodes = process_node_->GetFrameNodes(); base::flat_set<const FrameNode*> frame_nodes = process_node_->GetFrameNodes();
for (const FrameNode* frame_node : frame_nodes) { for (const FrameNode* frame_node : frame_nodes) {
......
...@@ -72,12 +72,21 @@ void AddPerFrameIsolateMemoryUsage(base::UnguessableToken frame_id, ...@@ -72,12 +72,21 @@ void AddPerFrameIsolateMemoryUsage(base::UnguessableToken frame_id,
int64_t world_id, int64_t world_id,
uint64_t bytes_used, uint64_t bytes_used,
mojom::PerProcessV8MemoryUsageData* data) { mojom::PerProcessV8MemoryUsageData* data) {
if (!base::Contains(data->associated_memory, frame_id)) { mojom::PerFrameV8MemoryUsageData* per_frame_data = nullptr;
data->associated_memory[frame_id] = mojom::PerFrameV8MemoryUsageData::New(); for (auto& datum : data->associated_memory) {
if (datum->dev_tools_token == frame_id) {
per_frame_data = datum.get();
break;
}
} }
mojom::PerFrameV8MemoryUsageData* per_frame_data = if (!per_frame_data) {
data->associated_memory[frame_id].get(); mojom::PerFrameV8MemoryUsageDataPtr datum =
mojom::PerFrameV8MemoryUsageData::New();
datum->dev_tools_token = frame_id;
per_frame_data = datum.get();
data->associated_memory.push_back(std::move(datum));
}
ASSERT_FALSE(base::Contains(per_frame_data->associated_bytes, world_id)); ASSERT_FALSE(base::Contains(per_frame_data->associated_bytes, world_id));
auto isolated_world_usage = mojom::V8IsolatedWorldMemoryUsage::New(); auto isolated_world_usage = mojom::V8IsolatedWorldMemoryUsage::New();
......
...@@ -27,6 +27,9 @@ struct V8IsolatedWorldMemoryUsage { ...@@ -27,6 +27,9 @@ struct V8IsolatedWorldMemoryUsage {
// Returns the number of bytes used by the v8 heap per frame. // Returns the number of bytes used by the v8 heap per frame.
struct PerFrameV8MemoryUsageData { struct PerFrameV8MemoryUsageData {
// The devtools token associated with the frame.
mojo_base.mojom.UnguessableToken dev_tools_token;
// The resources used by this frame, mapped on the isolated world ID. // The resources used by this frame, mapped on the isolated world ID.
// World ID 0 is the main world. // World ID 0 is the main world.
map<int64, V8IsolatedWorldMemoryUsage> associated_bytes; map<int64, V8IsolatedWorldMemoryUsage> associated_bytes;
...@@ -45,10 +48,8 @@ struct PerProcessV8MemoryUsageData { ...@@ -45,10 +48,8 @@ struct PerProcessV8MemoryUsageData {
uint64 num_unassociated_contexts; uint64 num_unassociated_contexts;
uint64 unassociated_context_bytes_used; uint64 unassociated_context_bytes_used;
// A map from devtools token associated with a frame, to the number // The V8 memory usage by individual frames in this process.
// of v8 heap bytes associated with that frame. array<PerFrameV8MemoryUsageData> associated_memory;
map<mojo_base.mojom.UnguessableToken, PerFrameV8MemoryUsageData>
associated_memory;
}; };
// Allows a browser to query the resource usage of sub-processes. // Allows a browser to query the resource usage of sub-processes.
......
...@@ -4,6 +4,7 @@ ...@@ -4,6 +4,7 @@
#include "content/renderer/performance_manager/v8_per_frame_memory_reporter_impl.h" #include "content/renderer/performance_manager/v8_per_frame_memory_reporter_impl.h"
#include "base/containers/flat_map.h"
#include "content/public/common/isolated_world_ids.h" #include "content/public/common/isolated_world_ids.h"
#include "mojo/public/cpp/bindings/self_owned_receiver.h" #include "mojo/public/cpp/bindings/self_owned_receiver.h"
#include "third_party/blink/public/web/web_local_frame.h" #include "third_party/blink/public/web/web_local_frame.h"
...@@ -44,6 +45,9 @@ class FrameAssociatedMeasurementDelegate : public v8::MeasureMemoryDelegate { ...@@ -44,6 +45,9 @@ class FrameAssociatedMeasurementDelegate : public v8::MeasureMemoryDelegate {
result->unassociated_bytes_used = unattributed_size_in_bytes; result->unassociated_bytes_used = unattributed_size_in_bytes;
// Keep track of the per-frame data throughout this loop.
base::flat_map<blink::WebLocalFrame*, mojom::PerFrameV8MemoryUsageDataPtr>
frames;
for (const auto& context_and_size : context_sizes_in_bytes) { for (const auto& context_and_size : context_sizes_in_bytes) {
const v8::Local<v8::Context>& context = context_and_size.first; const v8::Local<v8::Context>& context = context_and_size.first;
const size_t size = context_and_size.second; const size_t size = context_and_size.second;
...@@ -58,14 +62,14 @@ class FrameAssociatedMeasurementDelegate : public v8::MeasureMemoryDelegate { ...@@ -58,14 +62,14 @@ class FrameAssociatedMeasurementDelegate : public v8::MeasureMemoryDelegate {
++(result->num_unassociated_contexts); ++(result->num_unassociated_contexts);
result->unassociated_context_bytes_used += size; result->unassociated_context_bytes_used += size;
} else { } else {
base::UnguessableToken token = frame->Client()->GetDevToolsFrameToken();
mojom::PerFrameV8MemoryUsageData* per_frame_resources = mojom::PerFrameV8MemoryUsageData* per_frame_resources =
result->associated_memory[token].get(); frames[frame].get();
if (!per_frame_resources) { if (!per_frame_resources) {
auto new_resources = mojom::PerFrameV8MemoryUsageData::New(); auto new_resources = mojom::PerFrameV8MemoryUsageData::New();
new_resources->dev_tools_token =
frame->Client()->GetDevToolsFrameToken();
per_frame_resources = new_resources.get(); per_frame_resources = new_resources.get();
result->associated_memory[token] = std::move(new_resources); frames[frame] = std::move(new_resources);
} }
mojom::V8IsolatedWorldMemoryUsagePtr isolated_world_usage = mojom::V8IsolatedWorldMemoryUsagePtr isolated_world_usage =
...@@ -86,6 +90,9 @@ class FrameAssociatedMeasurementDelegate : public v8::MeasureMemoryDelegate { ...@@ -86,6 +90,9 @@ class FrameAssociatedMeasurementDelegate : public v8::MeasureMemoryDelegate {
std::move(isolated_world_usage); std::move(isolated_world_usage);
} }
} }
// Move the per-frame memory values to the result.
for (auto& entry : frames)
result->associated_memory.push_back(std::move(entry.second));
std::move(callback_).Run(std::move(result)); std::move(callback_).Run(std::move(result));
} }
......
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