Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make each render process provide its private memory footprint for bro…
…wser process. Because of the "hidepid=2" mount option for /proc on Android, browser process cannot open /proc/{render process pid}/maps and status, i.e. no such file or directory. So add PrivateMemoryFootprintProvider, which uses MemoryUsageMonitor, to third_party/blink/renderer/controller and provides the calculated private memory footprint for browser process by using render_host.mojom. Bug: 1393283 Change-Id: Ibb00262afc2ed0552e3f0c2ec5fb7449878b93c9 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4124620 Reviewed-by: Arthur Sonzogni <arthursonzogni@chromium.org> Reviewed-by: Daniel Cheng <dcheng@chromium.org> Reviewed-by: Kinuko Yasuda <kinuko@chromium.org> Commit-Queue: Takashi Sakamoto <tasak@google.com> Cr-Commit-Position: refs/heads/main@{#1096563}
- Loading branch information
Showing
14 changed files
with
195 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
44 changes: 44 additions & 0 deletions
44
third_party/blink/renderer/controller/private_memory_footprint_provider.cc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
// Copyright 2023 The Chromium Authors | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
#include "third_party/blink/renderer/controller/private_memory_footprint_provider.h" | ||
|
||
#include "base/task/task_runner.h" | ||
#include "base/time/default_tick_clock.h" | ||
#include "third_party/blink/public/platform/platform.h" | ||
|
||
namespace blink { | ||
|
||
void PrivateMemoryFootprintProvider::Initialize( | ||
scoped_refptr<base::SingleThreadTaskRunner> task_runner) { | ||
DEFINE_STATIC_LOCAL(PrivateMemoryFootprintProvider, provider, | ||
(std::move(task_runner))); | ||
(void)provider; | ||
} | ||
|
||
PrivateMemoryFootprintProvider::PrivateMemoryFootprintProvider( | ||
scoped_refptr<base::SingleThreadTaskRunner> task_runner) | ||
: PrivateMemoryFootprintProvider(std::move(task_runner), | ||
base::DefaultTickClock::GetInstance()) {} | ||
|
||
PrivateMemoryFootprintProvider::PrivateMemoryFootprintProvider( | ||
scoped_refptr<base::SingleThreadTaskRunner> task_runner, | ||
const base::TickClock* clock) | ||
: task_runner_(std::move(task_runner)), clock_(clock) { | ||
MemoryUsageMonitor::Instance().AddObserver(this); | ||
} | ||
|
||
void PrivateMemoryFootprintProvider::OnMemoryPing(MemoryUsage usage) { | ||
DCHECK(IsMainThread()); | ||
SetPrivateMemoryFootprint( | ||
static_cast<uint64_t>(usage.private_footprint_bytes)); | ||
} | ||
|
||
void PrivateMemoryFootprintProvider::SetPrivateMemoryFootprint( | ||
uint64_t private_memory_footprint_bytes) { | ||
Platform::Current()->SetPrivateMemoryFootprint( | ||
private_memory_footprint_bytes); | ||
} | ||
|
||
} // namespace blink |
52 changes: 52 additions & 0 deletions
52
third_party/blink/renderer/controller/private_memory_footprint_provider.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
// Copyright 2023 The Chromium Authors | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
#ifndef THIRD_PARTY_BLINK_RENDERER_CONTROLLER_PRIVATE_MEMORY_FOOTPRINT_PROVIDER_H_ | ||
#define THIRD_PARTY_BLINK_RENDERER_CONTROLLER_PRIVATE_MEMORY_FOOTPRINT_PROVIDER_H_ | ||
|
||
#include "base/time/time.h" | ||
#include "third_party/blink/renderer/controller/controller_export.h" | ||
#include "third_party/blink/renderer/controller/memory_usage_monitor.h" | ||
#include "third_party/blink/renderer/platform/timer.h" | ||
#include "third_party/blink/renderer/platform/wtf/allocator/allocator.h" | ||
|
||
namespace base { | ||
class SingleThreadTaskRunner; | ||
class TickClock; | ||
} // namespace base | ||
|
||
namespace blink { | ||
|
||
// Provides this renderer process' private memory footprint for browser process. | ||
class CONTROLLER_EXPORT PrivateMemoryFootprintProvider | ||
: public MemoryUsageMonitor::Observer { | ||
USING_FAST_MALLOC(PrivateMemoryFootprintProvider); | ||
|
||
public: | ||
// Initializes the shared instance. Has no effect if called more than once. | ||
static void Initialize( | ||
scoped_refptr<base::SingleThreadTaskRunner> task_runner); | ||
|
||
private: | ||
explicit PrivateMemoryFootprintProvider( | ||
scoped_refptr<base::SingleThreadTaskRunner> task_runner); | ||
|
||
PrivateMemoryFootprintProvider( | ||
scoped_refptr<base::SingleThreadTaskRunner> task_runner_for_testing, | ||
const base::TickClock* clock); | ||
|
||
// MemoryUsageMonitor::Observer: | ||
void OnMemoryPing(MemoryUsage) override; | ||
|
||
// Use mojom to provide private memory footprint for this RendererHost in | ||
// the browser process. | ||
void SetPrivateMemoryFootprint(uint64_t private_memory_footprint_bytes); | ||
|
||
scoped_refptr<base::SingleThreadTaskRunner> task_runner_; | ||
const base::TickClock* clock_; | ||
}; | ||
|
||
} // namespace blink | ||
|
||
#endif // THIRD_PARTY_BLINK_RENDERER_CONTROLLER_PMF_REPORTER_H_ |