Commit 2622bb33 authored by Patrick Monette's avatar Patrick Monette Committed by Commit Bot

[PM] Add a NodeDataDescriber for PageNodeImpl

Bug: 1077305
Change-Id: I9dc0120fc976741cd2ef1a7acc1d0c92d1daf928
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2176257
Commit-Queue: Patrick Monette <pmonette@chromium.org>
Reviewed-by: default avatarChris Hamilton <chrisha@chromium.org>
Cr-Commit-Position: refs/heads/master@{#766525}
parent 3001d933
...@@ -46,6 +46,8 @@ static_library("performance_manager") { ...@@ -46,6 +46,8 @@ static_library("performance_manager") {
"graph/page_node.cc", "graph/page_node.cc",
"graph/page_node_impl.cc", "graph/page_node_impl.cc",
"graph/page_node_impl.h", "graph/page_node_impl.h",
"graph/page_node_impl_describer.cc",
"graph/page_node_impl_describer.h",
"graph/policies/process_priority_policy.cc", "graph/policies/process_priority_policy.cc",
"graph/policies/process_priority_policy.h", "graph/policies/process_priority_policy.h",
"graph/process_node.cc", "graph/process_node.cc",
...@@ -90,6 +92,8 @@ static_library("performance_manager") { ...@@ -90,6 +92,8 @@ static_library("performance_manager") {
"public/graph/node_attached_data.h", "public/graph/node_attached_data.h",
"public/graph/node_data_describer.h", "public/graph/node_data_describer.h",
"public/graph/node_data_describer_registry.h", "public/graph/node_data_describer_registry.h",
"public/graph/node_data_describer_util.cc",
"public/graph/node_data_describer_util.h",
"public/graph/page_node.h", "public/graph/page_node.h",
"public/graph/policies/background_tab_loading_policy.h", "public/graph/policies/background_tab_loading_policy.h",
"public/graph/process_node.h", "public/graph/process_node.h",
......
...@@ -109,9 +109,10 @@ class PageNodeImpl ...@@ -109,9 +109,10 @@ class PageNodeImpl
private: private:
friend class FrameNodeImpl; friend class FrameNodeImpl;
friend class PageAggregatorAccess;
friend class FrozenFrameAggregatorAccess; friend class FrozenFrameAggregatorAccess;
friend class PageAggregatorAccess;
friend class PageLoadTrackerAccess; friend class PageLoadTrackerAccess;
friend class PageNodeImplDescriber;
// PageNode implementation. // PageNode implementation.
const std::string& GetBrowserContextID() const override; const std::string& GetBrowserContextID() const override;
......
// Copyright 2020 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "components/performance_manager/graph/page_node_impl_describer.h"
#include "base/strings/string_number_conversions.h"
#include "components/performance_manager/graph/page_node_impl.h"
#include "components/performance_manager/public/graph/node_data_describer_registry.h"
#include "components/performance_manager/public/graph/node_data_describer_util.h"
namespace performance_manager {
namespace {
const char kDescriberName[] = "PageNodeImpl";
} // namespace
PageNodeImplDescriber::PageNodeImplDescriber() = default;
PageNodeImplDescriber::~PageNodeImplDescriber() = default;
void PageNodeImplDescriber::OnPassedToGraph(Graph* graph) {
graph->GetNodeDataDescriberRegistry()->RegisterDescriber(this,
kDescriberName);
}
void PageNodeImplDescriber::OnTakenFromGraph(Graph* graph) {
graph->GetNodeDataDescriberRegistry()->UnregisterDescriber(this);
}
base::Value PageNodeImplDescriber::DescribePageNodeData(
const PageNode* page_node) const {
const PageNodeImpl* page_node_impl = PageNodeImpl::FromNode(page_node);
base::Value result(base::Value::Type::DICTIONARY);
result.SetKey(
"visibility_change_time",
TimeDeltaFromNowToValue(page_node_impl->visibility_change_time_));
result.SetKey(
"navigation_committed_time",
TimeDeltaFromNowToValue(page_node_impl->navigation_committed_time_));
result.SetKey("usage_estimate_time",
TimeDeltaFromNowToValue(page_node_impl->usage_estimate_time_));
// TODO(pmonette): Instead of emitting a raw number, this could be a human
// readable string. E.g. "14.8 MiB" instead of "14523".
result.SetStringKey(
"private_footprint_kb_estimate",
base::NumberToString(page_node_impl->private_footprint_kb_estimate_));
result.SetBoolKey("has_nonempty_beforeunload",
page_node_impl->has_nonempty_beforeunload_);
result.SetStringKey("main_frame_url",
page_node_impl->main_frame_url_.value().spec());
result.SetStringKey("navigation_id",
base::NumberToString(page_node_impl->navigation_id_));
result.SetStringKey("contents_mime_type",
page_node_impl->contents_mime_type_);
result.SetStringKey("browser_context_id",
page_node_impl->browser_context_id_);
result.SetBoolKey("is_visible", page_node_impl->is_visible_.value());
result.SetBoolKey("is_audible", page_node_impl->is_audible_.value());
result.SetBoolKey("is_loading", page_node_impl->is_loading_.value());
result.SetStringKey(
"ukm_source_id",
base::NumberToString(page_node_impl->ukm_source_id_.value()));
result.SetStringKey(
"lifecycle_state",
MojoEnumToString(page_node_impl->lifecycle_state_.value()));
result.SetStringKey(
"origin_trial_freeze_policy",
MojoEnumToString(page_node_impl->origin_trial_freeze_policy_.value()));
result.SetBoolKey("is_holding_weblock",
page_node_impl->is_holding_weblock_.value());
result.SetBoolKey("is_holding_indexeddb_lock",
page_node_impl->is_holding_indexeddb_lock_.value());
result.SetBoolKey("had_form_interaction",
page_node_impl->had_form_interaction_.value());
return result;
}
} // namespace performance_manager
// Copyright 2020 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef COMPONENTS_PERFORMANCE_MANAGER_GRAPH_PAGE_NODE_IMPL_DESCRIBER_H_
#define COMPONENTS_PERFORMANCE_MANAGER_GRAPH_PAGE_NODE_IMPL_DESCRIBER_H_
#include "components/performance_manager/public/graph/graph.h"
#include "components/performance_manager/public/graph/node_data_describer.h"
namespace performance_manager {
// Describes the state of of a PageNodeImpl for human consumption.
class PageNodeImplDescriber : public GraphOwned,
public NodeDataDescriberDefaultImpl {
public:
PageNodeImplDescriber();
~PageNodeImplDescriber() override;
PageNodeImplDescriber(const PageNodeImplDescriber&) = delete;
PageNodeImplDescriber& operator=(const PageNodeImplDescriber&) = delete;
// GraphOwned implementation:
void OnPassedToGraph(Graph* graph) override;
void OnTakenFromGraph(Graph* graph) override;
// NodeDataDescriber implementation:
base::Value DescribePageNodeData(const PageNode* page_node) const override;
};
} // namespace performance_manager
#endif // COMPONENTS_PERFORMANCE_MANAGER_GRAPH_PAGE_NODE_IMPL_DESCRIBER_H_
...@@ -7,6 +7,7 @@ ...@@ -7,6 +7,7 @@
#include "base/bind.h" #include "base/bind.h"
#include "components/performance_manager/decorators/page_load_tracker_decorator.h" #include "components/performance_manager/decorators/page_load_tracker_decorator.h"
#include "components/performance_manager/graph/frame_node_impl_describer.h" #include "components/performance_manager/graph/frame_node_impl_describer.h"
#include "components/performance_manager/graph/page_node_impl_describer.h"
#include "components/performance_manager/graph/process_node_impl_describer.h" #include "components/performance_manager/graph/process_node_impl_describer.h"
#include "components/performance_manager/graph/worker_node_impl_describer.h" #include "components/performance_manager/graph/worker_node_impl_describer.h"
#include "components/performance_manager/performance_manager_impl.h" #include "components/performance_manager/performance_manager_impl.h"
...@@ -24,6 +25,7 @@ void DefaultGraphCreatedCallback( ...@@ -24,6 +25,7 @@ void DefaultGraphCreatedCallback(
graph->PassToGraph(std::make_unique<FrameNodeImplDescriber>()); graph->PassToGraph(std::make_unique<FrameNodeImplDescriber>());
graph->PassToGraph(std::make_unique<PageLiveStateDecorator>()); graph->PassToGraph(std::make_unique<PageLiveStateDecorator>());
graph->PassToGraph(std::make_unique<PageLoadTrackerDecorator>()); graph->PassToGraph(std::make_unique<PageLoadTrackerDecorator>());
graph->PassToGraph(std::make_unique<PageNodeImplDescriber>());
graph->PassToGraph(std::make_unique<ProcessNodeImplDescriber>()); graph->PassToGraph(std::make_unique<ProcessNodeImplDescriber>());
graph->PassToGraph(std::make_unique<TabPropertiesDecorator>()); graph->PassToGraph(std::make_unique<TabPropertiesDecorator>());
graph->PassToGraph(std::make_unique<WorkerNodeImplDescriber>()); graph->PassToGraph(std::make_unique<WorkerNodeImplDescriber>());
......
// Copyright 2020 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "components/performance_manager/public/graph/node_data_describer_util.h"
#include "base/i18n/time_formatting.h"
namespace performance_manager {
base::Value TimeDeltaFromNowToValue(base::TimeTicks time_ticks) {
base::TimeDelta delta = base::TimeTicks::Now() - time_ticks;
base::string16 out;
bool succeeded = TimeDurationFormat(delta, base::DURATION_WIDTH_WIDE, &out);
DCHECK(succeeded);
return base::Value(out);
}
} // namespace performance_manager
// Copyright 2020 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef COMPONENTS_PERFORMANCE_MANAGER_PUBLIC_GRAPH_NODE_DATA_DESCRIBER_UTIL_H_
#define COMPONENTS_PERFORMANCE_MANAGER_PUBLIC_GRAPH_NODE_DATA_DESCRIBER_UTIL_H_
#include <sstream>
#include <string>
#include "base/time/time.h"
#include "base/values.h"
namespace performance_manager {
// Converts a Mojo enum to a human-readable string.
template <typename T>
std::string MojoEnumToString(T value) {
std::ostringstream os;
os << value;
return os.str();
}
// Returns a human-friendly string value computed from |time_ticks|. That string
// represents the time delta between |time_ticks| and TimeTicks::Now() in the
// following format: "x hours, y minutes".
base::Value TimeDeltaFromNowToValue(base::TimeTicks time_ticks);
} // namespace performance_manager
#endif // COMPONENTS_PERFORMANCE_MANAGER_PUBLIC_GRAPH_NODE_DATA_DESCRIBER_UTIL_H_
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