| 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..c5f61aba6b38953d91fcdbaa7818bf06ea3a8059 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"
|
| @@ -84,15 +86,15 @@ BrowserChildProcessHost* BrowserChildProcessHost::Create(
|
| content::ProcessType process_type,
|
| BrowserChildProcessHostDelegate* delegate) {
|
| return new BrowserChildProcessHostImpl(
|
| - process_type, delegate, mojo::edk::GenerateRandomToken());
|
| + process_type, delegate, mojo::edk::GenerateRandomToken(), 0, nullptr);
|
| }
|
|
|
| BrowserChildProcessHost* BrowserChildProcessHost::Create(
|
| content::ProcessType process_type,
|
| BrowserChildProcessHostDelegate* delegate,
|
| const std::string& mojo_child_token) {
|
| - return new BrowserChildProcessHostImpl(
|
| - process_type, delegate, mojo_child_token);
|
| + return new BrowserChildProcessHostImpl(process_type, delegate,
|
| + mojo_child_token, 0, nullptr);
|
| }
|
|
|
| BrowserChildProcessHost* BrowserChildProcessHost::FromID(int child_process_id) {
|
| @@ -135,7 +137,9 @@ void BrowserChildProcessHostImpl::RemoveObserver(
|
| BrowserChildProcessHostImpl::BrowserChildProcessHostImpl(
|
| content::ProcessType process_type,
|
| BrowserChildProcessHostDelegate* delegate,
|
| - const std::string& mojo_child_token)
|
| + const std::string& mojo_child_token,
|
| + size_t shared_metrics_memory_size,
|
| + base::StringPiece shared_metrics_name)
|
| : data_(process_type),
|
| delegate_(delegate),
|
| mojo_child_token_(mojo_child_token),
|
| @@ -168,6 +172,16 @@ BrowserChildProcessHostImpl::BrowserChildProcessHostImpl(
|
| GetContentClient()->browser()->BrowserChildProcessHostCreated(this);
|
|
|
| power_monitor_message_broadcaster_.Init();
|
| +
|
| + // Create a persistent memory segment for subprocess histograms only if
|
| + // they're active in the browser.
|
| + if (shared_metrics_memory_size > 0 && base::GlobalHistogramAllocator::Get()) {
|
| + std::unique_ptr<base::SharedMemory> shm(new base::SharedMemory());
|
| + shm->CreateAndMapAnonymous(shared_metrics_memory_size);
|
| + metrics_allocator_.reset(new base::SharedPersistentMemoryAllocator(
|
| + std::move(shm), static_cast<uint64_t>(data_.id), shared_metrics_name,
|
| + /*readonly=*/false));
|
| + }
|
| }
|
|
|
| BrowserChildProcessHostImpl::~BrowserChildProcessHostImpl() {
|
| @@ -268,6 +282,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 +354,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 +456,16 @@ bool BrowserChildProcessHostImpl::Send(IPC::Message* message) {
|
| return child_process_host_->Send(message);
|
| }
|
|
|
| +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 +492,7 @@ void BrowserChildProcessHostImpl::OnProcessLaunched() {
|
| delegate_->OnProcessLaunched();
|
|
|
| if (is_channel_connected_) {
|
| + ShareMetricsAllocatorToProcess();
|
| BrowserThread::PostTask(BrowserThread::UI, FROM_HERE,
|
| base::Bind(&NotifyProcessLaunchedAndConnected,
|
| data_));
|
|
|