Bug 1513057 - P7: Setup Gecko profiler on the socket process r=dragana,mayhemer,mstange
☠☠ backed out by 3f76ed638d83 ☠ ☠
authorKershaw Chang <kershaw@mozilla.com>
Fri, 11 Jan 2019 13:30:47 +0000
changeset 513462 de65c456aad6dbd598f81138509c342152ae4047
parent 513461 f648b5f1a7c2333e10ae9f7d9a91314de4512a70
child 513463 46411c5de3dade8d056fe33b745ee0e4eb7c38f9
push id1953
push userffxbld-merge
push dateMon, 11 Mar 2019 12:10:20 +0000
treeherdermozilla-release@9c35dcbaa899 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersdragana, mayhemer, mstange
bugs1513057
milestone66.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 1513057 - P7: Setup Gecko profiler on the socket process r=dragana,mayhemer,mstange Differential Revision: https://phabricator.services.mozilla.com/D14351
netwerk/ipc/PSocketProcess.ipdl
netwerk/ipc/SocketProcessChild.cpp
netwerk/ipc/SocketProcessChild.h
netwerk/ipc/SocketProcessHost.cpp
--- a/netwerk/ipc/PSocketProcess.ipdl
+++ b/netwerk/ipc/PSocketProcess.ipdl
@@ -1,15 +1,16 @@
 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 include MemoryReportTypes;
 include protocol PSocketProcessBridge;
+include protocol PProfiler;
 include PrefsTypes;
 
 using mozilla::dom::NativeThreadId from "mozilla/dom/TabMessageUtils.h";
 using base::ProcessId from "base/process.h";
 
 namespace mozilla {
 namespace net {
 
@@ -23,12 +24,13 @@ parent:
 child:
   async PreferenceUpdate(Pref pref);
   async RequestMemoryReport(uint32_t generation,
                             bool anonymize,
                             bool minimizeMemoryUsage,
                             MaybeFileDesc DMDFile);
   async SetOffline(bool offline);
   async InitSocketProcessBridgeParent(ProcessId processId, Endpoint<PSocketProcessBridgeParent> endpoint);
+  async InitProfiler(Endpoint<PProfilerChild> aEndpoint);
 };
 
 } // namespace net
 } // namespace mozilla
--- a/netwerk/ipc/SocketProcessChild.cpp
+++ b/netwerk/ipc/SocketProcessChild.cpp
@@ -12,16 +12,20 @@
 #include "mozilla/ipc/CrashReporterClient.h"
 #include "mozilla/ipc/ProcessChild.h"
 #include "mozilla/Preferences.h"
 #include "nsDebugImpl.h"
 #include "nsThreadManager.h"
 #include "ProcessUtils.h"
 #include "SocketProcessBridgeParent.h"
 
+#ifdef MOZ_GECKO_PROFILER
+#include "ChildProfilerController.h"
+#endif
+
 namespace mozilla {
 namespace net {
 
 using namespace ipc;
 
 static SocketProcessChild* sSocketProcessChild;
 
 SocketProcessChild::SocketProcessChild() {
@@ -71,16 +75,23 @@ bool SocketProcessChild::Init(base::Proc
 void SocketProcessChild::ActorDestroy(ActorDestroyReason aWhy) {
   LOG(("SocketProcessChild::ActorDestroy\n"));
 
   if (AbnormalShutdown == aWhy) {
     NS_WARNING("Shutting down Socket process early due to a crash!");
     ProcessChild::QuickExit();
   }
 
+#ifdef MOZ_GECKO_PROFILER
+  if (mProfilerController) {
+    mProfilerController->Shutdown();
+    mProfilerController = nullptr;
+  }
+#endif
+
   CrashReporterClient::DestroySingleton();
   XRE_ShutdownChildProcess();
 }
 
 void SocketProcessChild::CleanUp() {
   LOG(("SocketProcessChild::CleanUp\n"));
 
   NS_ShutdownXPCOM(nullptr);
@@ -126,16 +137,25 @@ mozilla::ipc::IPCResult SocketProcessChi
   MOZ_ASSERT(!mSocketProcessBridgeParentMap.Get(aContentProcessId, nullptr));
 
   mSocketProcessBridgeParentMap.Put(
       aContentProcessId,
       new SocketProcessBridgeParent(aContentProcessId, std::move(aEndpoint)));
   return IPC_OK();
 }
 
+mozilla::ipc::IPCResult SocketProcessChild::RecvInitProfiler(
+    Endpoint<PProfilerChild>&& aEndpoint) {
+#ifdef MOZ_GECKO_PROFILER
+  mProfilerController =
+      mozilla::ChildProfilerController::Create(std::move(aEndpoint));
+#endif
+  return IPC_OK();
+}
+
 void SocketProcessChild::DestroySocketProcessBridgeParent(ProcessId aId) {
   MOZ_ASSERT(NS_IsMainThread());
 
   mSocketProcessBridgeParentMap.Remove(aId);
 }
 
 }  // namespace net
 }  // namespace mozilla
--- a/netwerk/ipc/SocketProcessChild.h
+++ b/netwerk/ipc/SocketProcessChild.h
@@ -5,16 +5,20 @@
 
 #ifndef mozilla_net_SocketProcessChild_h
 #define mozilla_net_SocketProcessChild_h
 
 #include "mozilla/net/PSocketProcessChild.h"
 #include "nsRefPtrHashtable.h"
 
 namespace mozilla {
+class ChildProfilerController;
+}
+
+namespace mozilla {
 namespace net {
 
 class SocketProcessBridgeParent;
 
 // The IPC actor implements PSocketProcessChild in child process.
 // This is allocated and kept alive by SocketProcessImpl.
 class SocketProcessChild final : public PSocketProcessChild {
  public:
@@ -31,23 +35,29 @@ class SocketProcessChild final : public 
   mozilla::ipc::IPCResult RecvPreferenceUpdate(const Pref& aPref) override;
   mozilla::ipc::IPCResult RecvRequestMemoryReport(
       const uint32_t& generation, const bool& anonymize,
       const bool& minimizeMemoryUsage, const MaybeFileDesc& DMDFile) override;
   mozilla::ipc::IPCResult RecvSetOffline(const bool& aOffline) override;
   mozilla::ipc::IPCResult RecvInitSocketProcessBridgeParent(
       const ProcessId& aContentProcessId,
       Endpoint<mozilla::net::PSocketProcessBridgeParent>&& aEndpoint) override;
+  mozilla::ipc::IPCResult RecvInitProfiler(
+      Endpoint<mozilla::PProfilerChild>&& aEndpoint) override;
 
   void CleanUp();
   void DestroySocketProcessBridgeParent(ProcessId aId);
 
  private:
   // Mapping of content process id and the SocketProcessBridgeParent.
   // This table keeps SocketProcessBridgeParent alive in socket process.
   nsRefPtrHashtable<nsUint32HashKey, SocketProcessBridgeParent>
       mSocketProcessBridgeParentMap;
+
+#ifdef MOZ_GECKO_PROFILER
+  RefPtr<ChildProfilerController> mProfilerController;
+#endif
 };
 
 }  // namespace net
 }  // namespace mozilla
 
 #endif  // mozilla_net_SocketProcessChild_h
--- a/netwerk/ipc/SocketProcessHost.cpp
+++ b/netwerk/ipc/SocketProcessHost.cpp
@@ -4,16 +4,20 @@
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #include "SocketProcessHost.h"
 
 #include "nsAppRunner.h"
 #include "nsIObserverService.h"
 #include "SocketProcessParent.h"
 
+#ifdef MOZ_GECKO_PROFILER
+#include "ProfilerParent.h"
+#endif
+
 namespace mozilla {
 namespace net {
 
 #define NS_IPC_IOSERVICE_SET_OFFLINE_TOPIC "ipc:network:set-offline"
 
 class OfflineObserver final : public nsIObserver {
  public:
   NS_DECL_THREADSAFE_ISUPPORTS
@@ -208,16 +212,21 @@ void SocketProcessHost::InitAfterConnect
     MOZ_ASSERT(rv);
 
     nsCOMPtr<nsIIOService> ioService(do_GetIOService());
     MOZ_ASSERT(ioService, "No IO service?");
     bool offline = false;
     DebugOnly<nsresult> result = ioService->GetOffline(&offline);
     MOZ_ASSERT(NS_SUCCEEDED(result), "Failed getting offline?");
 
+#ifdef MOZ_GECKO_PROFILER
+    Unused << GetActor()->SendInitProfiler(
+        ProfilerParent::CreateForProcess(GetActor()->OtherPid()));
+#endif
+
     Unused << GetActor()->SendSetOffline(offline);
 
     mOfflineObserver = new OfflineObserver(this);
   }
 
   if (mListener) {
     mListener->OnProcessLaunchComplete(this, aSucceeded);
   }