Line data Source code
1 : /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 : /* vim: set ts=8 sts=2 et sw=2 tw=80: */
3 : /* This Source Code Form is subject to the terms of the Mozilla Public
4 : * License, v. 2.0. If a copy of the MPL was not distributed with this
5 : * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6 :
7 : #ifndef ProfilerParent_h
8 : #define ProfilerParent_h
9 :
10 : #include "mozilla/RefPtr.h"
11 : #include "mozilla/PProfilerParent.h"
12 :
13 : class nsIProfilerStartParams;
14 :
15 : namespace mozilla {
16 :
17 : class ProfilerParentTracker;
18 :
19 : // This is the main process side of the PProfiler protocol.
20 : // ProfilerParent instances only exist on the main thread of the main process.
21 : // The other side (ProfilerChild) lives on a background thread in the other
22 : // process.
23 : // The creation of PProfiler actors is initiated from the main process, after
24 : // the other process has been launched.
25 : // ProfilerParent instances are destroyed once the message channel closes,
26 : // which can be triggered by either process, depending on which one shuts down
27 : // first.
28 : // All ProfilerParent instances are registered with a manager class called
29 : // ProfilerParentTracker, which has the list of living ProfilerParent instances
30 : // and handles shutdown.
31 : class ProfilerParent final : public PProfilerParent
32 : {
33 : public:
34 6 : NS_INLINE_DECL_REFCOUNTING(ProfilerParent)
35 :
36 : static mozilla::ipc::Endpoint<PProfilerChild> CreateForProcess(base::ProcessId aOtherPid);
37 :
38 : typedef MozPromise<nsCString, PromiseRejectReason, false> SingleProcessProfilePromise;
39 :
40 : // The following static methods can be called on any thread, but they are
41 : // no-ops on anything other than the main thread.
42 : // If called on the main thread, the call will be broadcast to all
43 : // registered processes (all processes for which we have a ProfilerParent
44 : // object).
45 : // At the moment, the main process always calls these methods on the main
46 : // thread, and that's the only process in which we need to forward these
47 : // calls to other processes. The other processes will call these methods on
48 : // the ProfilerChild background thread, but those processes don't need to
49 : // forward these calls any further.
50 :
51 : // Returns the number of profiles to expect. The gathered profiles will be
52 : // provided asynchronously with a call to ProfileGatherer::ReceiveGatheredProfile.
53 : static nsTArray<RefPtr<SingleProcessProfilePromise>> GatherProfiles();
54 :
55 : static void ProfilerStarted(nsIProfilerStartParams* aParams);
56 : static void ProfilerStopped();
57 : static void ProfilerPaused();
58 : static void ProfilerResumed();
59 :
60 : private:
61 : friend class ProfilerParentTracker;
62 :
63 : ProfilerParent();
64 : virtual ~ProfilerParent();
65 :
66 : void Init();
67 : void ActorDestroy(ActorDestroyReason aActorDestroyReason) override;
68 : void DeallocPProfilerParent() override;
69 :
70 : RefPtr<ProfilerParent> mSelfRef;
71 : nsTArray<MozPromiseHolder<SingleProcessProfilePromise>> mPendingRequestedProfiles;
72 : bool mDestroyed;
73 : };
74 :
75 : } // namespace mozilla
76 :
77 : #endif // ProfilerParent_h
|