Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(409)

Unified Diff: content/browser/browser_child_process_host_impl.cc

Issue 2224063002: Use persistent memory for receiving metrics from sub-processes. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: create helper method; make test appear to be on UI thread Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: content/browser/browser_child_process_host_impl.cc
diff --git a/content/browser/browser_child_process_host_impl.cc b/content/browser/browser_child_process_host_impl.cc
index afc52015320fecafb9abc463abf4a979e56945f4..726a525aa978e8fc08ca1be0aac751ce157c37ce 100644
--- a/content/browser/browser_child_process_host_impl.cc
+++ b/content/browser/browser_child_process_host_impl.cc
@@ -15,6 +15,8 @@
#include "base/macros.h"
#include "base/metrics/field_trial.h"
#include "base/metrics/histogram.h"
+#include "base/metrics/persistent_histogram_allocator.h"
+#include "base/metrics/persistent_memory_allocator.h"
#include "base/stl_util.h"
#include "base/strings/string_util.h"
#include "base/synchronization/waitable_event.h"
@@ -168,6 +170,9 @@ BrowserChildProcessHostImpl::BrowserChildProcessHostImpl(
GetContentClient()->browser()->BrowserChildProcessHostCreated(this);
power_monitor_message_broadcaster_.Init();
+
+ // Create a persistent memory segment for subprocess histograms.
+ CreateMetricsAllocator();
}
BrowserChildProcessHostImpl::~BrowserChildProcessHostImpl() {
@@ -268,6 +273,11 @@ const base::Process& BrowserChildProcessHostImpl::GetProcess() const {
return child_process_->GetProcess();
}
+std::unique_ptr<base::SharedPersistentMemoryAllocator>
+BrowserChildProcessHostImpl::TakeMetricsAllocator() {
+ return std::move(metrics_allocator_);
+}
+
void BrowserChildProcessHostImpl::SetName(const base::string16& name) {
DCHECK_CURRENTLY_ON(BrowserThread::IO);
data_.name = name;
@@ -335,6 +345,7 @@ void BrowserChildProcessHostImpl::OnChannelConnected(int32_t peer_pid) {
delegate_->OnChannelConnected(peer_pid);
if (IsProcessLaunched()) {
+ ShareMetricsAllocatorToProcess();
BrowserThread::PostTask(BrowserThread::UI, FROM_HERE,
base::Bind(&NotifyProcessLaunchedAndConnected,
data_));
@@ -436,6 +447,47 @@ bool BrowserChildProcessHostImpl::Send(IPC::Message* message) {
return child_process_host_->Send(message);
}
+void BrowserChildProcessHostImpl::CreateMetricsAllocator() {
+ // Create a persistent memory segment for subprocess histograms only if
+ // they're active in the browser.
+ // TODO(bcwhite): Remove this once persistence is always enabled.
+ if (!base::GlobalHistogramAllocator::Get())
+ return;
+
+ // Determine the correct parameters based on the process type.
+ size_t memory_size;
+ base::StringPiece metrics_name;
+ switch (data_.process_type) {
+ case PROCESS_TYPE_GPU:
+ memory_size = 100 << 10; // 100 KiB
+ metrics_name = "GpuMetrics";
+ break;
+
+ default:
+ return;
+ }
+
+ // Create the shared memory segment and attach an allocator to it.
+ // Mapping the memory shouldn't fail but be safe if it does; everything
+ // will continue to work but just as if persistence weren't available.
+ std::unique_ptr<base::SharedMemory> shm(new base::SharedMemory());
+ if (!shm->CreateAndMapAnonymous(memory_size))
+ return;
+ metrics_allocator_.reset(new base::SharedPersistentMemoryAllocator(
+ std::move(shm), static_cast<uint64_t>(data_.id), metrics_name,
+ /*readonly=*/false));
+}
+
+void BrowserChildProcessHostImpl::ShareMetricsAllocatorToProcess() {
+ if (metrics_allocator_) {
+ base::SharedMemoryHandle shm_handle;
+ metrics_allocator_->shared_memory()->ShareToProcess(data_.handle,
+ &shm_handle);
+ Send(new ChildProcessMsg_SetHistogramMemory(
+ shm_handle, metrics_allocator_->shared_memory()->mapped_size()));
+ }
+}
+
void BrowserChildProcessHostImpl::OnProcessLaunchFailed(int error_code) {
delegate_->OnProcessLaunchFailed(error_code);
notify_child_disconnected_ = false;
@@ -462,6 +514,7 @@ void BrowserChildProcessHostImpl::OnProcessLaunched() {
delegate_->OnProcessLaunched();
if (is_channel_connected_) {
+ ShareMetricsAllocatorToProcess();
BrowserThread::PostTask(BrowserThread::UI, FROM_HERE,
base::Bind(&NotifyProcessLaunchedAndConnected,
data_));

Powered by Google App Engine
This is Rietveld 408576698