Commit 5d32f1de authored by Ulan Degenbaev's avatar Ulan Degenbaev Committed by Commit Bot

Move content/renderer/performance_manager to blink/renderer/controller

Bug: 1085129
Change-Id: I5ad0528aac918934395eca23b0bb66157638e9fc
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2329592Reviewed-by: default avatarWill Harris <wfh@chromium.org>
Reviewed-by: default avatarChris Hamilton <chrisha@chromium.org>
Reviewed-by: default avatarKentaro Hara <haraken@chromium.org>
Commit-Queue: Ulan Degenbaev <ulan@chromium.org>
Cr-Commit-Position: refs/heads/master@{#794245}
parent 80dfe45f
......@@ -10,6 +10,7 @@ include_rules = [
"+services/service_manager/public/cpp",
"+third_party/blink/public/common/tokens",
"+third_party/blink/public/mojom/favicon",
"+third_party/blink/public/mojom/performance_manager",
"+third_party/blink/public/mojom/service_worker",
"+third_party/blink/public/mojom/tokens",
"+third_party/leveldatabase",
......
......@@ -20,7 +20,7 @@
#include "components/performance_manager/public/graph/process_node.h"
#include "components/performance_manager/public/render_process_host_id.h"
#include "content/public/browser/global_routing_id.h"
#include "content/public/common/performance_manager/v8_per_frame_memory.mojom.h"
#include "third_party/blink/public/mojom/performance_manager/v8_per_frame_memory.mojom.h"
namespace performance_manager {
......@@ -493,7 +493,7 @@ namespace internal {
// communicate with the given process. Exposed so that it can be overridden to
// implement the interface with a test fake.
using BindV8PerFrameMemoryReporterCallback = base::RepeatingCallback<void(
mojo::PendingReceiver<performance_manager::mojom::V8PerFrameMemoryReporter>,
mojo::PendingReceiver<blink::mojom::V8PerFrameMemoryReporter>,
RenderProcessHostProxy)>;
// Sets a callback that will be used to bind the V8PerFrameMemoryReporter
......
......@@ -49,7 +49,7 @@ namespace {
// Forwards the pending receiver to the RenderProcessHost and binds it on the
// UI thread.
void BindReceiverOnUIThread(
mojo::PendingReceiver<performance_manager::mojom::V8PerFrameMemoryReporter>
mojo::PendingReceiver<blink::mojom::V8PerFrameMemoryReporter>
pending_receiver,
RenderProcessHostProxy proxy) {
auto* render_process_host = proxy.Get();
......@@ -157,12 +157,11 @@ class NodeAttachedProcessData
void StartMeasurement();
void EnsureRemote();
void OnPerFrameV8MemoryUsageData(
performance_manager::mojom::PerProcessV8MemoryUsageDataPtr result);
blink::mojom::PerProcessV8MemoryUsageDataPtr result);
const ProcessNode* const process_node_;
mojo::Remote<performance_manager::mojom::V8PerFrameMemoryReporter>
resource_usage_reporter_;
mojo::Remote<blink::mojom::V8PerFrameMemoryReporter> resource_usage_reporter_;
enum class State {
kWaiting, // Waiting to take a measurement.
......@@ -243,7 +242,7 @@ void NodeAttachedProcessData::StartMeasurement() {
}
void NodeAttachedProcessData::OnPerFrameV8MemoryUsageData(
performance_manager::mojom::PerProcessV8MemoryUsageDataPtr result) {
blink::mojom::PerProcessV8MemoryUsageDataPtr result) {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
DCHECK_EQ(state_, State::kMeasuring);
......@@ -254,14 +253,15 @@ void NodeAttachedProcessData::OnPerFrameV8MemoryUsageData(
uint64_t unassociated_v8_bytes_used = result->unassociated_bytes_used;
// Create a mapping from token to per-frame usage for the merge below.
std::vector<std::pair<FrameToken, mojom::PerFrameV8MemoryUsageDataPtr>> tmp;
std::vector<std::pair<FrameToken, blink::mojom::PerFrameV8MemoryUsageDataPtr>>
tmp;
for (auto& entry : result->associated_memory) {
tmp.emplace_back(
std::make_pair(FrameToken(entry->frame_token), std::move(entry)));
}
DCHECK_EQ(tmp.size(), result->associated_memory.size());
base::flat_map<FrameToken, mojom::PerFrameV8MemoryUsageDataPtr>
base::flat_map<FrameToken, blink::mojom::PerFrameV8MemoryUsageDataPtr>
associated_memory(std::move(tmp));
// Validate that the frame tokens were all unique. If there are duplicates,
// the map will arbirarily drop all but one record per unique token.
......@@ -315,7 +315,7 @@ void NodeAttachedProcessData::EnsureRemote() {
return;
// This interface is implemented in //content/renderer/performance_manager.
mojo::PendingReceiver<performance_manager::mojom::V8PerFrameMemoryReporter>
mojo::PendingReceiver<blink::mojom::V8PerFrameMemoryReporter>
pending_receiver = resource_usage_reporter_.BindNewPipeAndPassReceiver();
RenderProcessHostProxy proxy = process_node_->GetRenderProcessHostProxy();
......
......@@ -309,7 +309,6 @@ mojom("interfaces") {
"browser_controls_state.mojom",
"drop_data.mojom",
"fullscreen_video_element.mojom",
"performance_manager/v8_per_frame_memory.mojom",
"resource_usage_reporter.mojom",
"was_activated_option.mojom",
"webplugininfo.mojom",
......
......@@ -189,8 +189,6 @@ target(link_target_type, "renderer") {
"navigation_state.h",
"net_info_helper.cc",
"net_info_helper.h",
"performance_manager/v8_per_frame_memory_reporter_impl.cc",
"performance_manager/v8_per_frame_memory_reporter_impl.h",
"peripheral_content_heuristic.cc",
"peripheral_content_heuristic.h",
"queue_message_swap_promise.cc",
......
......@@ -33,10 +33,6 @@
#include "mojo/public/cpp/bindings/self_owned_receiver.h"
#include "v8/include/v8.h"
#if !defined(OS_ANDROID)
#include "content/renderer/performance_manager/v8_per_frame_memory_reporter_impl.h"
#endif
namespace content {
namespace {
......@@ -225,14 +221,6 @@ void ExposeRendererInterfacesToBrowser(
binders->Add(base::BindRepeating(&CreateFrameFactory),
base::ThreadTaskRunnerHandle::Get());
#if !defined(OS_ANDROID)
// Currently nothing on Android samples V8PerFrameMemory, so only initialize
// the reporter on desktop to save memory.
binders->Add(base::BindRepeating(
&performance_manager::V8PerFrameMemoryReporterImpl::Create),
base::SequencedTaskRunnerHandle::Get());
#endif
GetContentClient()->renderer()->ExposeInterfacesToBrowser(binders);
}
......
......@@ -116,6 +116,7 @@ mojom("mojom_platform") {
"page/widget.mojom",
"payments/payment_app.mojom",
"peerconnection/peer_connection_tracker.mojom",
"performance_manager/v8_per_frame_memory.mojom",
"permissions/permission.mojom",
"permissions/permission_automation.mojom",
"permissions/permission_status.mojom",
......
......@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
module performance_manager.mojom;
module blink.mojom;
import "mojo/public/mojom/base/unguessable_token.mojom";
......
......@@ -61,6 +61,11 @@ jumbo_component("controller") {
"oom_intervention_impl.cc",
"oom_intervention_impl.h",
]
} else {
sources += [
"performance_manager/v8_per_frame_memory_reporter_impl.cc",
"performance_manager/v8_per_frame_memory_reporter_impl.h",
]
}
if (is_win) {
sources += [
......
......@@ -63,6 +63,8 @@
#if defined(OS_ANDROID)
#include "third_party/blink/renderer/controller/crash_memory_metrics_reporter_impl.h"
#include "third_party/blink/renderer/controller/oom_intervention_impl.h"
#else
#include "third_party/blink/renderer/controller/performance_manager/v8_per_frame_memory_reporter_impl.h"
#endif
#if defined(OS_LINUX)
......@@ -203,7 +205,14 @@ void BlinkInitializer::RegisterInterfaces(mojo::BinderMap& binders) {
binders.Add(ConvertToBaseRepeatingCallback(CrossThreadBindRepeating(
&CrashMemoryMetricsReporterImpl::Bind)),
main_thread->GetTaskRunner());
#else
// Currently nothing on Android samples V8PerFrameMemory, so only initialize
// the reporter on desktop to save memory.
binders.Add(ConvertToBaseRepeatingCallback(CrossThreadBindRepeating(
&V8PerFrameMemoryReporterImpl::Create)),
main_thread->GetTaskRunner());
#endif
#if defined(OS_LINUX)
binders.Add(ConvertToBaseRepeatingCallback(
CrossThreadBindRepeating(&MemoryUsageMonitorPosix::Bind)),
......
......@@ -2,24 +2,35 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "content/renderer/performance_manager/v8_per_frame_memory_reporter_impl.h"
#include "third_party/blink/renderer/controller/performance_manager/v8_per_frame_memory_reporter_impl.h"
#include "base/containers/flat_map.h"
#include "content/public/common/isolated_world_ids.h"
#include "mojo/public/cpp/bindings/self_owned_receiver.h"
#include "third_party/blink/public/platform/web_isolated_world_info.h"
#include "third_party/blink/public/web/web_local_frame.h"
#include "third_party/blink/public/web/web_local_frame_client.h"
#include "third_party/blink/renderer/platform/bindings/dom_wrapper_world.h"
#include "third_party/blink/renderer/platform/wtf/hash_map.h"
#include "v8/include/v8.h"
namespace performance_manager {
namespace WTF {
template <>
struct HashTraits<::blink::mojom::blink::PerFrameV8MemoryUsageDataPtr>
: GenericHashTraits<::blink::mojom::blink::PerFrameV8MemoryUsageDataPtr> {
// The default PeekOutType is a value type that requires a copy constructor
// in the at() getter. Override it to a reference.
typedef const ::blink::mojom::blink::PerFrameV8MemoryUsageDataPtr&
PeekOutType;
};
} // namespace WTF
namespace blink {
namespace {
class FrameAssociatedMeasurementDelegate : public v8::MeasureMemoryDelegate {
public:
using GetPerFrameV8MemoryUsageDataCallback =
mojom::V8PerFrameMemoryReporter::GetPerFrameV8MemoryUsageDataCallback;
using GetPerFrameV8MemoryUsageDataCallback = mojom::blink::
V8PerFrameMemoryReporter::GetPerFrameV8MemoryUsageDataCallback;
explicit FrameAssociatedMeasurementDelegate(
GetPerFrameV8MemoryUsageDataCallback&& callback)
......@@ -27,7 +38,8 @@ class FrameAssociatedMeasurementDelegate : public v8::MeasureMemoryDelegate {
~FrameAssociatedMeasurementDelegate() override {
if (callback_) {
std::move(callback_).Run(mojom::PerProcessV8MemoryUsageData::New());
std::move(callback_).Run(
mojom::blink::PerProcessV8MemoryUsageData::New());
}
}
......@@ -41,13 +53,14 @@ class FrameAssociatedMeasurementDelegate : public v8::MeasureMemoryDelegate {
const std::vector<std::pair<v8::Local<v8::Context>, size_t>>&
context_sizes_in_bytes,
size_t unattributed_size_in_bytes) override {
mojom::PerProcessV8MemoryUsageDataPtr result =
mojom::PerProcessV8MemoryUsageData::New();
mojom::blink::PerProcessV8MemoryUsageDataPtr result =
mojom::blink::PerProcessV8MemoryUsageData::New();
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>
WTF::HashMap<blink::WebLocalFrame*,
mojom::blink::PerFrameV8MemoryUsageDataPtr>
frames;
for (const auto& context_and_size : context_sizes_in_bytes) {
const v8::Local<v8::Context>& context = context_and_size.first;
......@@ -63,45 +76,45 @@ class FrameAssociatedMeasurementDelegate : public v8::MeasureMemoryDelegate {
++(result->num_unassociated_contexts);
result->unassociated_context_bytes_used += size;
} else {
mojom::PerFrameV8MemoryUsageData* per_frame_resources =
frames[frame].get();
mojom::blink::PerFrameV8MemoryUsageData* per_frame_resources =
frames.at(frame).get();
if (!per_frame_resources) {
#if DCHECK_IS_ON()
// Check that the frame token didn't already occur.
for (const auto& entry : frames) {
// This frame was already added to the map by frames[frame] above.
if (frame == entry.first)
if (frame == entry.key)
continue;
DCHECK_NE(entry.first->GetFrameToken(), frame->GetFrameToken());
DCHECK_NE(entry.key->GetFrameToken(), frame->GetFrameToken());
}
#endif
auto new_resources = mojom::PerFrameV8MemoryUsageData::New();
auto new_resources = mojom::blink::PerFrameV8MemoryUsageData::New();
new_resources->frame_token = frame->GetFrameToken();
per_frame_resources = new_resources.get();
frames[frame] = std::move(new_resources);
frames.Set(frame, std::move(new_resources));
}
mojom::V8IsolatedWorldMemoryUsagePtr isolated_world_usage =
mojom::V8IsolatedWorldMemoryUsage::New();
mojom::blink::V8IsolatedWorldMemoryUsagePtr isolated_world_usage =
mojom::blink::V8IsolatedWorldMemoryUsage::New();
isolated_world_usage->bytes_used = size;
int32_t world_id = frame->GetScriptContextWorldId(context);
if (world_id != content::ISOLATED_WORLD_ID_GLOBAL) {
if (world_id != DOMWrapperWorld::WorldId::kMainWorldId) {
isolated_world_usage->stable_id =
blink::GetIsolatedWorldStableId(context).Utf8();
blink::GetIsolatedWorldStableId(context);
isolated_world_usage->human_readable_name =
blink::GetIsolatedWorldHumanReadableName(context).Utf8();
blink::GetIsolatedWorldHumanReadableName(context);
}
DCHECK(
!base::Contains(per_frame_resources->associated_bytes, world_id));
per_frame_resources->associated_bytes[world_id] =
std::move(isolated_world_usage);
per_frame_resources->associated_bytes.Set(
world_id, 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));
result->associated_memory.push_back(std::move(entry.value));
std::move(callback_).Run(std::move(result));
}
......@@ -113,7 +126,7 @@ class FrameAssociatedMeasurementDelegate : public v8::MeasureMemoryDelegate {
// static
void V8PerFrameMemoryReporterImpl::Create(
mojo::PendingReceiver<mojom::V8PerFrameMemoryReporter> receiver) {
mojo::PendingReceiver<mojom::blink::V8PerFrameMemoryReporter> receiver) {
mojo::MakeSelfOwnedReceiver(std::make_unique<V8PerFrameMemoryReporterImpl>(),
std::move(receiver));
}
......@@ -122,7 +135,7 @@ void V8PerFrameMemoryReporterImpl::GetPerFrameV8MemoryUsageData(
GetPerFrameV8MemoryUsageDataCallback callback) {
v8::Isolate* isolate = v8::Isolate::GetCurrent();
if (!isolate) {
std::move(callback).Run(mojom::PerProcessV8MemoryUsageData::New());
std::move(callback).Run(mojom::blink::PerProcessV8MemoryUsageData::New());
} else {
std::unique_ptr<FrameAssociatedMeasurementDelegate> delegate =
std::make_unique<FrameAssociatedMeasurementDelegate>(
......@@ -132,4 +145,4 @@ void V8PerFrameMemoryReporterImpl::GetPerFrameV8MemoryUsageData(
}
}
} // namespace performance_manager
} // namespace blink
......@@ -2,23 +2,24 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CONTENT_RENDERER_PERFORMANCE_MANAGER_V8_PER_FRAME_MEMORY_REPORTER_IMPL_H_
#define CONTENT_RENDERER_PERFORMANCE_MANAGER_V8_PER_FRAME_MEMORY_REPORTER_IMPL_H_
#ifndef THIRD_PARTY_BLINK_RENDERER_CONTROLLER_PERFORMANCE_MANAGER_V8_PER_FRAME_MEMORY_REPORTER_IMPL_H_
#define THIRD_PARTY_BLINK_RENDERER_CONTROLLER_PERFORMANCE_MANAGER_V8_PER_FRAME_MEMORY_REPORTER_IMPL_H_
#include "content/public/common/performance_manager/v8_per_frame_memory.mojom.h"
#include "third_party/blink/public/mojom/performance_manager/v8_per_frame_memory.mojom-blink.h"
namespace performance_manager {
namespace blink {
// Exposes V8 per-frame associated memory metrics to the browser.
class V8PerFrameMemoryReporterImpl : public mojom::V8PerFrameMemoryReporter {
class V8PerFrameMemoryReporterImpl
: public mojom::blink::V8PerFrameMemoryReporter {
public:
static void Create(
mojo::PendingReceiver<mojom::V8PerFrameMemoryReporter> receiver);
mojo::PendingReceiver<mojom::blink::V8PerFrameMemoryReporter> receiver);
void GetPerFrameV8MemoryUsageData(
GetPerFrameV8MemoryUsageDataCallback callback) override;
};
} // namespace performance_manager
} // namespace blink
#endif // CONTENT_RENDERER_PERFORMANCE_MANAGER_V8_PER_FRAME_MEMORY_REPORTER_IMPL_H_
#endif // THIRD_PARTY_BLINK_CONTROLLER_PERFORMANCE_MANAGER_V8_PER_FRAME_MEMORY_REPORTER_IMPL_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