Bug 1756802 - Set Utility Process name for profiler r=gerald
authorAlexandre Lissy <lissyx+mozillians@lissyx.dyndns.org>
Tue, 01 Mar 2022 08:27:22 +0000
changeset 609233 51adfda473058e70324723762cd0834f165c3ac7
parent 609232 cab0588a0babf27a5e3e2d517b602d4a93bdf6c9
child 609234 ae499200e1453979088223ab10cc7313f3b1c180
push id39353
push userabutkovits@mozilla.com
push dateTue, 01 Mar 2022 16:17:59 +0000
treeherdermozilla-central@365268736d5b [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersgerald
bugs1756802
milestone99.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1756802 - Set Utility Process name for profiler r=gerald Differential Revision: https://phabricator.services.mozilla.com/D139840
ipc/docs/processes.rst
ipc/glue/UtilityProcessChild.cpp
ipc/glue/test/browser/browser_utility_profiler.js
--- a/ipc/docs/processes.rst
+++ b/ipc/docs/processes.rst
@@ -328,16 +328,18 @@ Profiler
 - Add definition of ``PProfiler`` to your new IPDL
 
   + Type inclusion `protocol PProfiler <https://searchfox.org/mozilla-central/rev/fc4d4a8d01b0e50d20c238acbb1739ccab317ebc/ipc/glue/PUtilityProcess.ipdl#9>`_
   + Child-side `InitProfiler <https://searchfox.org/mozilla-central/rev/fc4d4a8d01b0e50d20c238acbb1739ccab317ebc/ipc/glue/PUtilityProcess.ipdl#42>`_
 
 - Make sure your initialization path contains a `SendInitProfiler <https://searchfox.org/mozilla-central/rev/fc4d4a8d01b0e50d20c238acbb1739ccab317ebc/ipc/glue/UtilityProcessHost.cpp#222-223>`_. You will want to perform the call once a ``OnChannelConnected`` is issued, thus ensuring your new process is connected to IPC.
 - Provide an implementation for `InitProfiler <https://searchfox.org/mozilla-central/rev/fc4d4a8d01b0e50d20c238acbb1739ccab317ebc/ipc/glue/UtilityProcessChild.cpp#147-151>`_
 
+- You will probably want to make sure your child process code register within the profiler a proper name, otherwise it will default to ``GeckoMain`` ; this can be done by issuing ``profiler_set_process_name(nsCString("XxX"))`` on the child init side.
+
 Static Components
 #################
 
 The amount of changes required here are significant, `Bug 1740485: Improve
 StaticComponents code generation
 <https://bugzilla.mozilla.org/show_bug.cgi?id=1740485>`_ tracks improving that.
 
 - Update allowance in those configuration files to match new process selector
--- a/ipc/glue/UtilityProcessChild.cpp
+++ b/ipc/glue/UtilityProcessChild.cpp
@@ -25,16 +25,17 @@
 
 #if defined(XP_WIN)
 #  include "mozilla/WinDllServices.h"
 #endif
 
 #include "nsDebugImpl.h"
 #include "nsIXULRuntime.h"
 #include "nsThreadManager.h"
+#include "GeckoProfiler.h"
 
 #include "mozilla/ipc/ProcessChild.h"
 #include "mozilla/FOGIPC.h"
 #include "mozilla/glean/GleanMetrics.h"
 
 namespace mozilla::ipc {
 
 using namespace layers;
@@ -93,16 +94,17 @@ bool UtilityProcessChild::Init(base::Pro
 
   if (NS_FAILED(NS_InitMinimalXPCOM())) {
     return false;
   }
 
   mSandbox = (SandboxingKind)aSandboxingKind;
 
   mozilla::ipc::SetThisProcessName("Utility Process");
+  profiler_set_process_name(nsCString("Utility Process"));
 
   // Notify the parent process that we have finished our init and that it can
   // now resolve the pending promise of process startup
   SendInitCompleted();
 
   return true;
 }
 
--- a/ipc/glue/test/browser/browser_utility_profiler.js
+++ b/ipc/glue/test/browser/browser_utility_profiler.js
@@ -25,22 +25,35 @@ add_task(async () => {
     );
   }, "Give time for the profiler to start and collect some samples");
 
   info(`Check that the utility process ${utilityPid} is present.`);
   let utilityProcessIndex = profile.processes.findIndex(
     p => p.threads[0].pid == utilityPid
   );
   Assert.notEqual(utilityProcessIndex, -1, "Could find index of utility");
+
   Assert.equal(
     profile.processes[utilityProcessIndex].threads[0].processType,
     "utility",
     "Profile has processType utility"
   );
 
+  Assert.equal(
+    profile.processes[utilityProcessIndex].threads[0].name,
+    "GeckoMain",
+    "Profile has correct main thread name"
+  );
+
+  Assert.equal(
+    profile.processes[utilityProcessIndex].threads[0].processName,
+    "Utility Process",
+    "Profile has correct process name"
+  );
+
   Assert.greater(
     profile.processes[utilityProcessIndex].threads.length,
     0,
     "The utility process should have threads"
   );
 
   Assert.equal(
     profile.threads.length,