Commit 7efd9afd authored by Sigurdur Asgeirsson's avatar Sigurdur Asgeirsson Committed by Commit Bot

PM: Only enable instrumentation under the chrome embedder.

As of https://chromium-review.googlesource.com/c/1425042, content/
no longer provides forwarding for the ResourceCoordinator
instrumentation interfaces. This was a step in a larger refactoring,
but had the effect of orphaning the instrumentation in all but the
chrome/browser embedder. This in turn led to a memory regression in
the Android WebView.
This CL makes the initialization and the usage of the instrumentation
interfaces conditional on a runtime flag, which is only set by the
ChromeContentRendererClient.
This is still an intermediate state in the refactoring, as the
interfaces in question will be moved and simplified.

Bug: 926426
Change-Id: Ia640f544b536bf86d53e853de6178aeaf9c9b6f5
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1496303
Commit-Queue: Sigurður Ásgeirsson <siggi@chromium.org>
Reviewed-by: default avatarDaniel Cheng <dcheng@chromium.org>
Reviewed-by: default avatarStephen White <senorblanco@chromium.org>
Reviewed-by: default avatarChris Hamilton <chrisha@chromium.org>
Cr-Commit-Position: refs/heads/master@{#638575}
parent a9fc6c03
...@@ -1520,6 +1520,10 @@ void ChromeContentRendererClient::RunScriptsAtDocumentIdle( ...@@ -1520,6 +1520,10 @@ void ChromeContentRendererClient::RunScriptsAtDocumentIdle(
void ChromeContentRendererClient:: void ChromeContentRendererClient::
SetRuntimeFeaturesDefaultsBeforeBlinkInitialization() { SetRuntimeFeaturesDefaultsBeforeBlinkInitialization() {
// The performance manager service interfaces are provided by the chrome
// embedder only.
blink::WebRuntimeFeatures::EnablePerformanceManagerInstrumentation(true);
// Web Share is shipped on Android, experimental otherwise. It is enabled here, // Web Share is shipped on Android, experimental otherwise. It is enabled here,
// in chrome/, to avoid it being made available in other clients of content/ // in chrome/, to avoid it being made available in other clients of content/
// that do not have a Web Share Mojo implementation. // that do not have a Web Share Mojo implementation.
......
...@@ -148,6 +148,8 @@ class WebRuntimeFeatures { ...@@ -148,6 +148,8 @@ class WebRuntimeFeatures {
BLINK_PLATFORM_EXPORT static void EnablePaymentRequest(bool); BLINK_PLATFORM_EXPORT static void EnablePaymentRequest(bool);
BLINK_PLATFORM_EXPORT static void EnablePaymentRequestHasEnrolledInstrument( BLINK_PLATFORM_EXPORT static void EnablePaymentRequestHasEnrolledInstrument(
bool); bool);
BLINK_PLATFORM_EXPORT static void EnablePerformanceManagerInstrumentation(
bool);
BLINK_PLATFORM_EXPORT static void EnablePermissionsAPI(bool); BLINK_PLATFORM_EXPORT static void EnablePermissionsAPI(bool);
BLINK_PLATFORM_EXPORT static void EnablePictureInPicture(bool); BLINK_PLATFORM_EXPORT static void EnablePictureInPicture(bool);
BLINK_PLATFORM_EXPORT static void EnablePictureInPictureAPI(bool); BLINK_PLATFORM_EXPORT static void EnablePictureInPictureAPI(bool);
......
...@@ -32,7 +32,8 @@ BloatedRendererDetector::OnNearV8HeapLimitOnMainThreadImpl() { ...@@ -32,7 +32,8 @@ BloatedRendererDetector::OnNearV8HeapLimitOnMainThreadImpl() {
} }
} }
last_detection_time_ = now; last_detection_time_ = now;
RendererResourceCoordinator::Get().OnRendererIsBloated(); if (auto* renderer_resource_coordinator = RendererResourceCoordinator::Get())
renderer_resource_coordinator->OnRendererIsBloated();
return NearV8HeapLimitHandling::kForwardedToBrowser; return NearV8HeapLimitHandling::kForwardedToBrowser;
} }
......
...@@ -1350,7 +1350,7 @@ FrameResourceCoordinator* LocalFrame::GetFrameResourceCoordinator() { ...@@ -1350,7 +1350,7 @@ FrameResourceCoordinator* LocalFrame::GetFrameResourceCoordinator() {
auto* local_frame_client = Client(); auto* local_frame_client = Client();
if (!local_frame_client) if (!local_frame_client)
return nullptr; return nullptr;
frame_resource_coordinator_ = FrameResourceCoordinator::Create( frame_resource_coordinator_ = FrameResourceCoordinator::MaybeCreate(
local_frame_client->GetInterfaceProvider()); local_frame_client->GetInterfaceProvider());
} }
return frame_resource_coordinator_.get(); return frame_resource_coordinator_.get();
......
...@@ -220,7 +220,7 @@ void Platform::InitializeCommon(Platform* platform, ...@@ -220,7 +220,7 @@ void Platform::InitializeCommon(Platform* platform,
ParkableStringManagerDumpProvider::Instance(), "ParkableStrings", ParkableStringManagerDumpProvider::Instance(), "ParkableStrings",
base::ThreadTaskRunnerHandle::Get()); base::ThreadTaskRunnerHandle::Get());
RendererResourceCoordinator::Initialize(); RendererResourceCoordinator::MaybeInitialize();
} }
void Platform::SetCurrentPlatformForTesting(Platform* platform) { void Platform::SetCurrentPlatformForTesting(Platform* platform) {
......
...@@ -354,6 +354,10 @@ void WebRuntimeFeatures::EnablePaymentRequestHasEnrolledInstrument( ...@@ -354,6 +354,10 @@ void WebRuntimeFeatures::EnablePaymentRequestHasEnrolledInstrument(
RuntimeEnabledFeatures::SetPaymentRequestHasEnrolledInstrumentEnabled(enable); RuntimeEnabledFeatures::SetPaymentRequestHasEnrolledInstrumentEnabled(enable);
} }
void WebRuntimeFeatures::EnablePerformanceManagerInstrumentation(bool enable) {
RuntimeEnabledFeatures::SetPerformanceManagerInstrumentationEnabled(enable);
}
void WebRuntimeFeatures::EnablePermissionsAPI(bool enable) { void WebRuntimeFeatures::EnablePermissionsAPI(bool enable) {
RuntimeEnabledFeatures::SetPermissionsEnabled(enable); RuntimeEnabledFeatures::SetPermissionsEnabled(enable);
} }
......
include_rules = [ include_rules = [
"+services/resource_coordinator/public", "+services/resource_coordinator/public",
] "+third_party/blink/renderer/platform/runtime_enabled_features.h",
\ No newline at end of file ]
...@@ -4,8 +4,11 @@ ...@@ -4,8 +4,11 @@
#include "third_party/blink/renderer/platform/instrumentation/resource_coordinator/frame_resource_coordinator.h" #include "third_party/blink/renderer/platform/instrumentation/resource_coordinator/frame_resource_coordinator.h"
#include <memory>
#include "base/memory/ptr_util.h" #include "base/memory/ptr_util.h"
#include "services/service_manager/public/cpp/interface_provider.h" #include "services/service_manager/public/cpp/interface_provider.h"
#include "third_party/blink/renderer/platform/runtime_enabled_features.h"
namespace blink { namespace blink {
...@@ -17,8 +20,11 @@ using resource_coordinator::mojom::PolicyControlledIntervention; ...@@ -17,8 +20,11 @@ using resource_coordinator::mojom::PolicyControlledIntervention;
} // namespace } // namespace
// static // static
std::unique_ptr<FrameResourceCoordinator> FrameResourceCoordinator::Create( std::unique_ptr<FrameResourceCoordinator> FrameResourceCoordinator::MaybeCreate(
service_manager::InterfaceProvider* interface_provider) { service_manager::InterfaceProvider* interface_provider) {
if (!RuntimeEnabledFeatures::PerformanceManagerInstrumentationEnabled())
return nullptr;
return base::WrapUnique(new FrameResourceCoordinator(interface_provider)); return base::WrapUnique(new FrameResourceCoordinator(interface_provider));
} }
......
...@@ -5,6 +5,8 @@ ...@@ -5,6 +5,8 @@
#ifndef THIRD_PARTY_BLINK_RENDERER_PLATFORM_INSTRUMENTATION_RESOURCE_COORDINATOR_FRAME_RESOURCE_COORDINATOR_H_ #ifndef THIRD_PARTY_BLINK_RENDERER_PLATFORM_INSTRUMENTATION_RESOURCE_COORDINATOR_FRAME_RESOURCE_COORDINATOR_H_
#define THIRD_PARTY_BLINK_RENDERER_PLATFORM_INSTRUMENTATION_RESOURCE_COORDINATOR_FRAME_RESOURCE_COORDINATOR_H_ #define THIRD_PARTY_BLINK_RENDERER_PLATFORM_INSTRUMENTATION_RESOURCE_COORDINATOR_FRAME_RESOURCE_COORDINATOR_H_
#include <memory>
#include "base/macros.h" #include "base/macros.h"
#include "services/resource_coordinator/public/mojom/coordination_unit.mojom-blink.h" #include "services/resource_coordinator/public/mojom/coordination_unit.mojom-blink.h"
#include "third_party/blink/renderer/platform/platform_export.h" #include "third_party/blink/renderer/platform/platform_export.h"
...@@ -20,7 +22,8 @@ class PLATFORM_EXPORT FrameResourceCoordinator final { ...@@ -20,7 +22,8 @@ class PLATFORM_EXPORT FrameResourceCoordinator final {
USING_FAST_MALLOC(FrameResourceCoordinator); USING_FAST_MALLOC(FrameResourceCoordinator);
public: public:
static std::unique_ptr<FrameResourceCoordinator> Create( // Returns nullptr if instrumentation is not enabled.
static std::unique_ptr<FrameResourceCoordinator> MaybeCreate(
service_manager::InterfaceProvider*); service_manager::InterfaceProvider*);
~FrameResourceCoordinator(); ~FrameResourceCoordinator();
......
...@@ -7,6 +7,7 @@ ...@@ -7,6 +7,7 @@
#include "services/service_manager/public/cpp/connector.h" #include "services/service_manager/public/cpp/connector.h"
#include "third_party/blink/public/platform/platform.h" #include "third_party/blink/public/platform/platform.h"
#include "third_party/blink/renderer/platform/heap/thread_state.h" #include "third_party/blink/renderer/platform/heap/thread_state.h"
#include "third_party/blink/renderer/platform/runtime_enabled_features.h"
namespace blink { namespace blink {
...@@ -17,7 +18,10 @@ RendererResourceCoordinator* g_renderer_resource_coordinator = nullptr; ...@@ -17,7 +18,10 @@ RendererResourceCoordinator* g_renderer_resource_coordinator = nullptr;
} // namespace } // namespace
// static // static
void RendererResourceCoordinator::Initialize() { void RendererResourceCoordinator::MaybeInitialize() {
if (!RuntimeEnabledFeatures::PerformanceManagerInstrumentationEnabled())
return;
blink::Platform* platform = Platform::Current(); blink::Platform* platform = Platform::Current();
DCHECK(IsMainThread()); DCHECK(IsMainThread());
DCHECK(platform); DCHECK(platform);
...@@ -33,9 +37,8 @@ void RendererResourceCoordinator:: ...@@ -33,9 +37,8 @@ void RendererResourceCoordinator::
} }
// static // static
RendererResourceCoordinator& RendererResourceCoordinator::Get() { RendererResourceCoordinator* RendererResourceCoordinator::Get() {
DCHECK(g_renderer_resource_coordinator); return g_renderer_resource_coordinator;
return *g_renderer_resource_coordinator;
} }
RendererResourceCoordinator::RendererResourceCoordinator( RendererResourceCoordinator::RendererResourceCoordinator(
......
...@@ -20,8 +20,9 @@ class PLATFORM_EXPORT RendererResourceCoordinator { ...@@ -20,8 +20,9 @@ class PLATFORM_EXPORT RendererResourceCoordinator {
USING_FAST_MALLOC(RendererResourceCoordinator); USING_FAST_MALLOC(RendererResourceCoordinator);
public: public:
static void Initialize(); // Only initializes if the instrumentation runtime feature is enabled.
static RendererResourceCoordinator& Get(); static void MaybeInitialize();
static RendererResourceCoordinator* Get();
// Used to switch the current renderer resource coordinator only for testing. // Used to switch the current renderer resource coordinator only for testing.
static void SetCurrentRendererResourceCoordinatorForTesting( static void SetCurrentRendererResourceCoordinatorForTesting(
......
...@@ -1066,6 +1066,9 @@ ...@@ -1066,6 +1066,9 @@
name: "PaymentRetry", name: "PaymentRetry",
status: "experimental", status: "experimental",
}, },
{
name: "PerformanceManagerInstrumentation",
},
{ {
// Flag enabling the performance observers buffered flag. The buffered // Flag enabling the performance observers buffered flag. The buffered
// flag indicates whether or not the buffered entries should be loaded // flag indicates whether or not the buffered entries should be loaded
......
...@@ -576,15 +576,18 @@ void MainThreadMetricsHelper::ReportLowThreadLoadForPageAlmostIdleSignal( ...@@ -576,15 +576,18 @@ void MainThreadMetricsHelper::ReportLowThreadLoadForPageAlmostIdleSignal(
static const int main_thread_task_load_low_threshold = static const int main_thread_task_load_low_threshold =
::resource_coordinator::GetMainThreadTaskLoadLowThreshold(); ::resource_coordinator::GetMainThreadTaskLoadLowThreshold();
// Avoid sending duplicate IPCs when the state doesn't change. if (auto* renderer_resource_coordinator =
if (load_percentage <= main_thread_task_load_low_threshold && RendererResourceCoordinator::Get()) {
main_thread_task_load_state_ != MainThreadTaskLoadState::kLow) { // Avoid sending duplicate IPCs when the state doesn't change.
RendererResourceCoordinator::Get().SetMainThreadTaskLoadIsLow(true); if (load_percentage <= main_thread_task_load_low_threshold &&
main_thread_task_load_state_ = MainThreadTaskLoadState::kLow; main_thread_task_load_state_ != MainThreadTaskLoadState::kLow) {
} else if (load_percentage > main_thread_task_load_low_threshold && renderer_resource_coordinator->SetMainThreadTaskLoadIsLow(true);
main_thread_task_load_state_ != MainThreadTaskLoadState::kHigh) { main_thread_task_load_state_ = MainThreadTaskLoadState::kLow;
RendererResourceCoordinator::Get().SetMainThreadTaskLoadIsLow(false); } else if (load_percentage > main_thread_task_load_low_threshold &&
main_thread_task_load_state_ = MainThreadTaskLoadState::kHigh; main_thread_task_load_state_ != MainThreadTaskLoadState::kHigh) {
renderer_resource_coordinator->SetMainThreadTaskLoadIsLow(false);
main_thread_task_load_state_ = MainThreadTaskLoadState::kHigh;
}
} }
} }
......
...@@ -2537,8 +2537,11 @@ void MainThreadSchedulerImpl::OnQueueingTimeForWindowEstimated( ...@@ -2537,8 +2537,11 @@ void MainThreadSchedulerImpl::OnQueueingTimeForWindowEstimated(
"estimated_queueing_time_for_window", "estimated_queueing_time_for_window",
queueing_time.InMillisecondsF()); queueing_time.InMillisecondsF());
RendererResourceCoordinator::Get().SetExpectedTaskQueueingDuration( if (auto* renderer_resource_coordinator =
queueing_time); RendererResourceCoordinator::Get()) {
renderer_resource_coordinator->SetExpectedTaskQueueingDuration(
queueing_time);
}
} }
void MainThreadSchedulerImpl::OnReportFineGrainedExpectedQueueingTime( void MainThreadSchedulerImpl::OnReportFineGrainedExpectedQueueingTime(
......
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