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

Unified Diff: content/browser/renderer_host/render_process_host_impl.cc

Issue 1671933002: Create and pass shared-histogram-allocator from browser to renderer. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@hsm-merge
Patch Set: fixed test to not use SharedMemory which doesn't work on all builds (and rebased) Created 4 years, 8 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/renderer_host/render_process_host_impl.cc
diff --git a/content/browser/renderer_host/render_process_host_impl.cc b/content/browser/renderer_host/render_process_host_impl.cc
index 011104d99fc99bac4b3e86e9c48c70729a0b81cb..c6c9d15c2d347473b7ce53a993fb7e7028706fdd 100644
--- a/content/browser/renderer_host/render_process_host_impl.cc
+++ b/content/browser/renderer_host/render_process_host_impl.cc
@@ -24,8 +24,12 @@
#include "base/location.h"
#include "base/logging.h"
#include "base/macros.h"
+#include "base/memory/shared_memory.h"
+#include "base/memory/shared_memory_handle.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/process/process_handle.h"
#include "base/rand_util.h"
#include "base/single_thread_task_runner.h"
@@ -1119,6 +1123,11 @@ ServiceRegistry* RenderProcessHostImpl::GetServiceRegistry() {
return mojo_application_host_->service_registry();
}
+scoped_ptr<base::SharedPersistentMemoryAllocator>
+RenderProcessHostImpl::TakeMetricsAllocator() {
+ return std::move(metrics_allocator_);
+}
+
const base::TimeTicks& RenderProcessHostImpl::GetInitTimeForNavigationMetrics()
const {
return init_time_;
@@ -2359,6 +2368,31 @@ void RenderProcessHostImpl::RegisterProcessHostForSite(
map->RegisterProcess(site, process);
}
+void RenderProcessHostImpl::CreateSharedRendererHistogramAllocator() {
+ DCHECK(!metrics_allocator_);
+
+ // Create a persistent memory segment for renderer histograms only if
+ // they're active in the browser.
+ if (!base::GlobalHistogramAllocator::Get())
+ return;
+
+ // Get handle to the renderer process. Stop if there is none.
+ base::ProcessHandle destination = GetHandle();
+ if (destination == base::kNullProcessHandle)
+ return;
+
+ // TODO(bcwhite): Update this with the correct memory size.
+ scoped_ptr<base::SharedMemory> shm(new base::SharedMemory());
+ shm->CreateAndMapAnonymous(2 << 20); // 2 MiB
+ metrics_allocator_.reset(new base::SharedPersistentMemoryAllocator(
+ std::move(shm), GetID(), "RendererMetrics", /*readonly=*/false));
+
+ base::SharedMemoryHandle shm_handle;
+ metrics_allocator_->shared_memory()->ShareToProcess(destination, &shm_handle);
+ Send(new ChildProcessMsg_SetHistogramMemory(
+ shm_handle, metrics_allocator_->shared_memory()->mapped_size()));
+}
+
void RenderProcessHostImpl::ProcessDied(bool already_dead,
RendererClosedDetails* known_details) {
// Our child process has died. If we didn't expect it, it's a crash.
@@ -2561,6 +2595,9 @@ void RenderProcessHostImpl::OnProcessLaunched() {
#if defined(OS_ANDROID)
UpdateProcessPriority();
#endif
+
+ // Share histograms between the renderer and this process.
+ CreateSharedRendererHistogramAllocator();
}
// NOTE: This needs to be before sending queued messages because
« no previous file with comments | « content/browser/renderer_host/render_process_host_impl.h ('k') | content/child/child_histogram_message_filter.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698