Commit 2acb8ac9 authored by Sigurdur Asgeirsson's avatar Sigurdur Asgeirsson Committed by Commit Bot

[PM] Add node descriptions to graph dump protocol.

Bug: 1068233
Change-Id: Ie7b4dd8e6743dd963b8d94056bf71366c8633265
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2139438
Commit-Queue: Sigurður Ásgeirsson <siggi@chromium.org>
Reviewed-by: default avatarDaniel Cheng <dcheng@chromium.org>
Reviewed-by: default avatarJoe Mason <joenotcharles@chromium.org>
Cr-Commit-Position: refs/heads/master@{#758809}
parent 7c026d1d
...@@ -104,7 +104,12 @@ struct PageInfo { ...@@ -104,7 +104,12 @@ struct PageInfo {
url.mojom.Url main_frame_url; url.mojom.Url main_frame_url;
// TODO(siggi): Estimate data. // This field is a dictionary of values, where each value is generated by
// a performance_manager::NodeDataDescriber implementation and keyed by the
// name it registered with. The intent is for each describer to describe
// private node-related or node-attached data in some way, to allow presenting
// otherwise hidden state in the chrome://discards/graph view.
string description_json;
}; };
// Represents the momentary state of a Frame node. // Represents the momentary state of a Frame node.
...@@ -115,6 +120,9 @@ struct FrameInfo { ...@@ -115,6 +120,9 @@ struct FrameInfo {
int64 page_id; int64 page_id;
int64 parent_frame_id; int64 parent_frame_id;
int64 process_id; int64 process_id;
// See PageInfo::description_json.
string description_json;
}; };
// Represents the momentary state of a Process node. // Represents the momentary state of a Process node.
...@@ -123,6 +131,9 @@ struct ProcessInfo { ...@@ -123,6 +131,9 @@ struct ProcessInfo {
mojo_base.mojom.ProcessId pid; mojo_base.mojom.ProcessId pid;
uint64 private_footprint_kb; uint64 private_footprint_kb;
// See PageInfo::description_json.
string description_json;
}; };
// Represents the momentary state of a Worker node. // Represents the momentary state of a Worker node.
...@@ -135,6 +146,9 @@ struct WorkerInfo { ...@@ -135,6 +146,9 @@ struct WorkerInfo {
array<int64> client_frame_ids; array<int64> client_frame_ids;
array<int64> client_worker_ids; array<int64> client_worker_ids;
array<int64> child_worker_ids; array<int64> child_worker_ids;
// See PageInfo::description_json.
string description_json;
}; };
// Used to transport favicon data. // Used to transport favicon data.
......
...@@ -9,6 +9,7 @@ ...@@ -9,6 +9,7 @@
#include "base/base64.h" #include "base/base64.h"
#include "base/bind.h" #include "base/bind.h"
#include "base/json/json_string_value_serializer.h"
#include "base/macros.h" #include "base/macros.h"
#include "base/task/cancelable_task_tracker.h" #include "base/task/cancelable_task_tracker.h"
#include "base/task/post_task.h" #include "base/task/post_task.h"
...@@ -19,6 +20,8 @@ ...@@ -19,6 +20,8 @@
#include "components/favicon/core/favicon_service.h" #include "components/favicon/core/favicon_service.h"
#include "components/favicon_base/favicon_callback.h" #include "components/favicon_base/favicon_callback.h"
#include "components/performance_manager/public/graph/graph.h" #include "components/performance_manager/public/graph/graph.h"
#include "components/performance_manager/public/graph/node_data_describer.h"
#include "components/performance_manager/public/graph/node_data_describer_registry.h"
#include "components/performance_manager/public/performance_manager.h" #include "components/performance_manager/public/performance_manager.h"
#include "components/performance_manager/public/web_contents_proxy.h" #include "components/performance_manager/public/web_contents_proxy.h"
#include "content/public/browser/browser_task_traits.h" #include "content/public/browser/browser_task_traits.h"
...@@ -35,6 +38,16 @@ int64_t GetSerializationId(const performance_manager::Node* node) { ...@@ -35,6 +38,16 @@ int64_t GetSerializationId(const performance_manager::Node* node) {
return performance_manager::Node::GetSerializationId(node); return performance_manager::Node::GetSerializationId(node);
} }
// Best effort convert |value| to a string.
std::string ToJSON(const base::Value& value) {
std::string result;
JSONStringValueSerializer serializer(&result);
if (serializer.Serialize(value))
return result;
return std::string();
}
} // namespace } // namespace
class DiscardsGraphDumpImpl::FaviconRequestHelper { class DiscardsGraphDumpImpl::FaviconRequestHelper {
...@@ -372,6 +385,8 @@ void DiscardsGraphDumpImpl::SendFrameNotification( ...@@ -372,6 +385,8 @@ void DiscardsGraphDumpImpl::SendFrameNotification(
frame_info->page_id = GetSerializationId(page); frame_info->page_id = GetSerializationId(page);
frame_info->url = frame->GetURL(); frame_info->url = frame->GetURL();
frame_info->description_json = ToJSON(
graph_->GetNodeDataDescriberRegistry()->DescribeFrameNodeData(frame));
if (created) if (created)
change_subscriber_->FrameCreated(std::move(frame_info)); change_subscriber_->FrameCreated(std::move(frame_info));
...@@ -388,6 +403,9 @@ void DiscardsGraphDumpImpl::SendPageNotification( ...@@ -388,6 +403,9 @@ void DiscardsGraphDumpImpl::SendPageNotification(
page_info->id = GetSerializationId(page_node); page_info->id = GetSerializationId(page_node);
page_info->main_frame_url = page_node->GetMainFrameUrl(); page_info->main_frame_url = page_node->GetMainFrameUrl();
page_info->description_json = ToJSON(
graph_->GetNodeDataDescriberRegistry()->DescribePageNodeData(page_node));
if (created) if (created)
change_subscriber_->PageCreated(std::move(page_info)); change_subscriber_->PageCreated(std::move(page_info));
else else
...@@ -405,6 +423,9 @@ void DiscardsGraphDumpImpl::SendProcessNotification( ...@@ -405,6 +423,9 @@ void DiscardsGraphDumpImpl::SendProcessNotification(
process_info->pid = process->GetProcessId(); process_info->pid = process->GetProcessId();
process_info->private_footprint_kb = process->GetPrivateFootprintKb(); process_info->private_footprint_kb = process->GetPrivateFootprintKb();
process_info->description_json = ToJSON(
graph_->GetNodeDataDescriberRegistry()->DescribeProcessNodeData(process));
if (created) if (created)
change_subscriber_->ProcessCreated(std::move(process_info)); change_subscriber_->ProcessCreated(std::move(process_info));
else else
...@@ -435,6 +456,9 @@ void DiscardsGraphDumpImpl::SendWorkerNotification( ...@@ -435,6 +456,9 @@ void DiscardsGraphDumpImpl::SendWorkerNotification(
worker_info->child_worker_ids.push_back(GetSerializationId(child_worker)); worker_info->child_worker_ids.push_back(GetSerializationId(child_worker));
} }
worker_info->description_json = ToJSON(
graph_->GetNodeDataDescriberRegistry()->DescribeWorkerNodeData(worker));
if (created) if (created)
change_subscriber_->WorkerCreated(std::move(worker_info)); change_subscriber_->WorkerCreated(std::move(worker_info));
else else
......
...@@ -8,11 +8,14 @@ ...@@ -8,11 +8,14 @@
#include <set> #include <set>
#include <utility> #include <utility>
#include "base/json/json_reader.h"
#include "base/run_loop.h" #include "base/run_loop.h"
#include "base/stl_util.h" #include "base/stl_util.h"
#include "base/test/bind_test_util.h" #include "base/test/bind_test_util.h"
#include "base/time/time.h" #include "base/time/time.h"
#include "chrome/browser/ui/webui/discards/discards.mojom.h" #include "chrome/browser/ui/webui/discards/discards.mojom.h"
#include "components/performance_manager/public/graph/node_data_describer.h"
#include "components/performance_manager/public/graph/node_data_describer_registry.h"
#include "components/performance_manager/test_support/graph_impl.h" #include "components/performance_manager/test_support/graph_impl.h"
#include "components/performance_manager/test_support/mock_graphs.h" #include "components/performance_manager/test_support/mock_graphs.h"
#include "content/public/test/browser_task_environment.h" #include "content/public/test/browser_task_environment.h"
...@@ -26,7 +29,7 @@ namespace { ...@@ -26,7 +29,7 @@ namespace {
using performance_manager::NodeBase; using performance_manager::NodeBase;
const std::string kHtmlMimeType = "text/html"; const char kHtmlMimeType[] = "text/html";
class TestChangeStream : public discards::mojom::GraphChangeStream { class TestChangeStream : public discards::mojom::GraphChangeStream {
public: public:
...@@ -139,6 +142,31 @@ class DiscardsGraphDumpImplTest : public testing::Test { ...@@ -139,6 +142,31 @@ class DiscardsGraphDumpImplTest : public testing::Test {
performance_manager::TestGraphImpl graph_; performance_manager::TestGraphImpl graph_;
}; };
class TestNodeDataDescriber : public performance_manager::NodeDataDescriber {
public:
// NodeDataDescriber implementations:
base::Value DescribeFrameNodeData(
const performance_manager::FrameNode* node) const override {
return base::Value("frame");
}
base::Value DescribePageNodeData(
const performance_manager::PageNode* node) const override {
return base::Value("page");
}
base::Value DescribeProcessNodeData(
const performance_manager::ProcessNode* node) const override {
return base::Value("process");
}
base::Value DescribeSystemNodeData(
const performance_manager::SystemNode* node) const override {
return base::Value("system");
}
base::Value DescribeWorkerNodeData(
const performance_manager::WorkerNode* node) const override {
return base::Value("worker");
}
};
} // namespace } // namespace
TEST_F(DiscardsGraphDumpImplTest, ChangeStream) { TEST_F(DiscardsGraphDumpImplTest, ChangeStream) {
...@@ -175,6 +203,9 @@ TEST_F(DiscardsGraphDumpImplTest, ChangeStream) { ...@@ -175,6 +203,9 @@ TEST_F(DiscardsGraphDumpImplTest, ChangeStream) {
impl->BindWithGraph(&graph_, graph_dump_remote.BindNewPipeAndPassReceiver()); impl->BindWithGraph(&graph_, graph_dump_remote.BindNewPipeAndPassReceiver());
graph_.PassToGraph(std::move(impl)); graph_.PassToGraph(std::move(impl));
TestNodeDataDescriber describer;
graph_.GetNodeDataDescriberRegistry()->RegisterDescriber(&describer, "test");
TestChangeStream change_stream; TestChangeStream change_stream;
graph_dump_remote->SubscribeToChanges(change_stream.GetRemote()); graph_dump_remote->SubscribeToChanges(change_stream.GetRemote());
...@@ -186,11 +217,22 @@ TEST_F(DiscardsGraphDumpImplTest, ChangeStream) { ...@@ -186,11 +217,22 @@ TEST_F(DiscardsGraphDumpImplTest, ChangeStream) {
EXPECT_EQ(2u, change_stream.process_map().size()); EXPECT_EQ(2u, change_stream.process_map().size());
for (const auto& kv : change_stream.process_map()) { for (const auto& kv : change_stream.process_map()) {
EXPECT_NE(0u, kv.second->id); const auto* process_info = kv.second.get();
EXPECT_NE(0u, process_info->id);
EXPECT_EQ(base::JSONReader::Read("{\"test\":\"process\"}"),
base::JSONReader::Read(process_info->description_json));
} }
EXPECT_EQ(3u, change_stream.frame_map().size()); EXPECT_EQ(3u, change_stream.frame_map().size());
for (const auto& kv : change_stream.frame_map()) {
EXPECT_EQ(base::JSONReader::Read("{\"test\":\"frame\"}"),
base::JSONReader::Read(kv.second->description_json));
}
EXPECT_EQ(1u, change_stream.worker_map().size()); EXPECT_EQ(1u, change_stream.worker_map().size());
for (const auto& kv : change_stream.worker_map()) {
EXPECT_EQ(base::JSONReader::Read("{\"test\":\"worker\"}"),
base::JSONReader::Read(kv.second->description_json));
}
// Count the top-level frames as we go. // Count the top-level frames as we go.
size_t top_level_frames = 0; size_t top_level_frames = 0;
...@@ -218,6 +260,8 @@ TEST_F(DiscardsGraphDumpImplTest, ChangeStream) { ...@@ -218,6 +260,8 @@ TEST_F(DiscardsGraphDumpImplTest, ChangeStream) {
const auto& page = kv.second; const auto& page = kv.second;
EXPECT_NE(0u, page->id); EXPECT_NE(0u, page->id);
EXPECT_EQ(kExampleUrl, page->main_frame_url); EXPECT_EQ(kExampleUrl, page->main_frame_url);
EXPECT_EQ(base::JSONReader::Read("{\"test\":\"page\"}"),
base::JSONReader::Read(kv.second->description_json));
} }
// Test change notifications. // Test change notifications.
...@@ -249,4 +293,6 @@ TEST_F(DiscardsGraphDumpImplTest, ChangeStream) { ...@@ -249,4 +293,6 @@ TEST_F(DiscardsGraphDumpImplTest, ChangeStream) {
EXPECT_EQ(nullptr, graph_.TakeFromGraph(impl_raw)); EXPECT_EQ(nullptr, graph_.TakeFromGraph(impl_raw));
worker->RemoveClientFrame(mock_graph.frame.get()); worker->RemoveClientFrame(mock_graph.frame.get());
graph_.GetNodeDataDescriberRegistry()->UnregisterDescriber(&describer);
} }
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