Add heap profiling support for utility processes.
This CL adds two new heap profiling modes: "utility-sampling" and
"utility-and-browser". The former mode will profile all utility processes at
startup, with 1/3 probability. The latter will profile all utility processes and
the browser process [currently just useful for tests].
In addition to some small plumbing and tests, this CL modifies
UtilityThreadImpl::Init to call
"GetContentClient()->OnServiceManagerConnected(connection);". The callback
OnServiceManagerConnected() was not getting propagated to the
ChromeContentClient in the utility process [this was a bug].
The profiling process itself is a utility process and must never be profiled --
that will cause deadlock. This is avoided by adding an early out to
Client::StartProfiling for the utility process. The newly added tests confirm
that we don't deadlock even when attempting to profile all utility processes.
Change-Id: I74e2921d7ceff6150080c182db756be9ac0d076b
Bug: 878431
Reviewed-on: https://chromium-review.googlesource.com/1195836
Reviewed-by: John Abd-El-Malek <[email protected]>
Commit-Queue: Erik Chen <[email protected]>
Cr-Commit-Position: refs/heads/master@{#587699}
diff --git a/components/heap_profiling/client_connection_manager.cc b/components/heap_profiling/client_connection_manager.cc
index 4d998d3d..00295cd 100644
--- a/components/heap_profiling/client_connection_manager.cc
+++ b/components/heap_profiling/client_connection_manager.cc
@@ -85,6 +85,16 @@
// Renderer logic is handled in ClientConnectionManager::Observe.
return false;
+ case Mode::kUtilitySampling:
+ // Sample each utility process with 1/3 probability.
+ if (process_type == content::ProcessType::PROCESS_TYPE_UTILITY)
+ return (base::RandUint64() % 3) < 1;
+ return false;
+
+ case Mode::kUtilityAndBrowser:
+ return process_type == content::ProcessType::PROCESS_TYPE_UTILITY ||
+ process_type == content::ProcessType::PROCESS_TYPE_BROWSER;
+
case Mode::kNone:
return false;