From f66295c49c35e6e9fad6cb54ade798f56ffe1794 Mon Sep 17 00:00:00 2001 From: Kershaw Chang Date: Fri, 11 Jan 2019 13:30:47 +0000 Subject: [PATCH] Bug 1513057 - P7: Setup Gecko profiler on the socket process r=dragana,mayhemer,mstange Differential Revision: https://phabricator.services.mozilla.com/D14351 --HG-- extra : moz-landing-system : lando --- netwerk/ipc/PSocketProcess.ipdl | 2 ++ netwerk/ipc/SocketProcessChild.cpp | 20 ++++++++++++++++++++ netwerk/ipc/SocketProcessChild.h | 10 ++++++++++ netwerk/ipc/SocketProcessHost.cpp | 9 +++++++++ 4 files changed, 41 insertions(+) diff --git a/netwerk/ipc/PSocketProcess.ipdl b/netwerk/ipc/PSocketProcess.ipdl index db9d4a50620e..0c7f583bea0a 100644 --- a/netwerk/ipc/PSocketProcess.ipdl +++ b/netwerk/ipc/PSocketProcess.ipdl @@ -5,6 +5,7 @@ include MemoryReportTypes; include protocol PSocketProcessBridge; +include protocol PProfiler; include PrefsTypes; using mozilla::dom::NativeThreadId from "mozilla/dom/TabMessageUtils.h"; @@ -28,6 +29,7 @@ child: MaybeFileDesc DMDFile); async SetOffline(bool offline); async InitSocketProcessBridgeParent(ProcessId processId, Endpoint endpoint); + async InitProfiler(Endpoint aEndpoint); }; } // namespace net diff --git a/netwerk/ipc/SocketProcessChild.cpp b/netwerk/ipc/SocketProcessChild.cpp index 730fcc81302d..192c6ed7d328 100644 --- a/netwerk/ipc/SocketProcessChild.cpp +++ b/netwerk/ipc/SocketProcessChild.cpp @@ -17,6 +17,10 @@ #include "ProcessUtils.h" #include "SocketProcessBridgeParent.h" +#ifdef MOZ_GECKO_PROFILER +#include "ChildProfilerController.h" +#endif + namespace mozilla { namespace net { @@ -76,6 +80,13 @@ void SocketProcessChild::ActorDestroy(ActorDestroyReason aWhy) { ProcessChild::QuickExit(); } +#ifdef MOZ_GECKO_PROFILER + if (mProfilerController) { + mProfilerController->Shutdown(); + mProfilerController = nullptr; + } +#endif + CrashReporterClient::DestroySingleton(); XRE_ShutdownChildProcess(); } @@ -131,6 +142,15 @@ mozilla::ipc::IPCResult SocketProcessChild::RecvInitSocketProcessBridgeParent( return IPC_OK(); } +mozilla::ipc::IPCResult SocketProcessChild::RecvInitProfiler( + Endpoint&& 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()); diff --git a/netwerk/ipc/SocketProcessChild.h b/netwerk/ipc/SocketProcessChild.h index e58be0d1c571..99c2a4480189 100644 --- a/netwerk/ipc/SocketProcessChild.h +++ b/netwerk/ipc/SocketProcessChild.h @@ -9,6 +9,10 @@ #include "mozilla/net/PSocketProcessChild.h" #include "nsRefPtrHashtable.h" +namespace mozilla { +class ChildProfilerController; +} + namespace mozilla { namespace net { @@ -36,6 +40,8 @@ class SocketProcessChild final : public PSocketProcessChild { mozilla::ipc::IPCResult RecvInitSocketProcessBridgeParent( const ProcessId& aContentProcessId, Endpoint&& aEndpoint) override; + mozilla::ipc::IPCResult RecvInitProfiler( + Endpoint&& aEndpoint) override; void CleanUp(); void DestroySocketProcessBridgeParent(ProcessId aId); @@ -45,6 +51,10 @@ class SocketProcessChild final : public PSocketProcessChild { // This table keeps SocketProcessBridgeParent alive in socket process. nsRefPtrHashtable mSocketProcessBridgeParentMap; + +#ifdef MOZ_GECKO_PROFILER + RefPtr mProfilerController; +#endif }; } // namespace net diff --git a/netwerk/ipc/SocketProcessHost.cpp b/netwerk/ipc/SocketProcessHost.cpp index 2f976b51dda9..86f8406917f9 100644 --- a/netwerk/ipc/SocketProcessHost.cpp +++ b/netwerk/ipc/SocketProcessHost.cpp @@ -9,6 +9,10 @@ #include "nsIObserverService.h" #include "SocketProcessParent.h" +#ifdef MOZ_GECKO_PROFILER +#include "ProfilerParent.h" +#endif + namespace mozilla { namespace net { @@ -213,6 +217,11 @@ void SocketProcessHost::InitAfterConnect(bool aSucceeded) { DebugOnly 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);