diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-28 14:29:10 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-28 14:29:10 +0000 |
commit | 2aa4a82499d4becd2284cdb482213d541b8804dd (patch) | |
tree | b80bf8bf13c3766139fbacc530efd0dd9d54394c /tools/profiler/public/ProfilerParent.h | |
parent | Initial commit. (diff) | |
download | firefox-2aa4a82499d4becd2284cdb482213d541b8804dd.tar.xz firefox-2aa4a82499d4becd2284cdb482213d541b8804dd.zip |
Adding upstream version 86.0.1.upstream/86.0.1upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'tools/profiler/public/ProfilerParent.h')
-rw-r--r-- | tools/profiler/public/ProfilerParent.h | 95 |
1 files changed, 95 insertions, 0 deletions
diff --git a/tools/profiler/public/ProfilerParent.h b/tools/profiler/public/ProfilerParent.h new file mode 100644 index 0000000000..fe9457e678 --- /dev/null +++ b/tools/profiler/public/ProfilerParent.h @@ -0,0 +1,95 @@ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* vim: set ts=8 sts=2 et sw=2 tw=80: */ +/* 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/. */ + +#ifndef ProfilerParent_h +#define ProfilerParent_h + +#include "mozilla/PProfilerParent.h" +#include "mozilla/RefPtr.h" + +class nsIProfilerStartParams; + +namespace mozilla { + +class ProfileBufferGlobalController; +class ProfilerParentTracker; + +// This is the main process side of the PProfiler protocol. +// ProfilerParent instances only exist on the main thread of the main process. +// The other side (ProfilerChild) lives on a background thread in the other +// process. +// The creation of PProfiler actors is initiated from the main process, after +// the other process has been launched. +// ProfilerParent instances are destroyed once the message channel closes, +// which can be triggered by either process, depending on which one shuts down +// first. +// All ProfilerParent instances are registered with a manager class called +// ProfilerParentTracker, which has the list of living ProfilerParent instances +// and handles shutdown. +class ProfilerParent final : public PProfilerParent { + public: + NS_INLINE_DECL_REFCOUNTING(ProfilerParent) + + static mozilla::ipc::Endpoint<PProfilerChild> CreateForProcess( + base::ProcessId aOtherPid); + + typedef MozPromise<Shmem, ResponseRejectReason, true> + SingleProcessProfilePromise; + + // The following static methods can be called on any thread, but they are + // no-ops on anything other than the main thread. + // If called on the main thread, the call will be broadcast to all + // registered processes (all processes for which we have a ProfilerParent + // object). + // At the moment, the main process always calls these methods on the main + // thread, and that's the only process in which we need to forward these + // calls to other processes. The other processes will call these methods on + // the ProfilerChild background thread, but those processes don't need to + // forward these calls any further. + + // Returns the number of profiles to expect. The gathered profiles will be + // provided asynchronously with a call to + // ProfileGatherer::ReceiveGatheredProfile. + static nsTArray<RefPtr<SingleProcessProfilePromise>> GatherProfiles(); + + static void ProfilerStarted(nsIProfilerStartParams* aParams); + static void ProfilerWillStopIfStarted(); + static void ProfilerStopped(); + static void ProfilerPaused(); + static void ProfilerResumed(); + static void ProfilerPausedSampling(); + static void ProfilerResumedSampling(); + static void ClearAllPages(); + + // Create a "Final" update that the Child can return to its Parent. + static ProfileBufferChunkManagerUpdate MakeFinalUpdate(); + + // True if the ProfilerParent holds a lock on this thread. + static bool IsLockedOnCurrentThread(); + + private: + friend class ProfileBufferGlobalController; + friend class ProfilerParentTracker; + + explicit ProfilerParent(base::ProcessId aChildPid); + virtual ~ProfilerParent(); + + void Init(); + void ActorDestroy(ActorDestroyReason aActorDestroyReason) override; + void ActorDealloc() override; + + void RequestChunkManagerUpdate(); + + RefPtr<ProfilerParent> mSelfRef; + base::ProcessId mChildPid; + nsTArray<MozPromiseHolder<SingleProcessProfilePromise>> + mPendingRequestedProfiles; + bool mDestroyed; +}; + +} // namespace mozilla + +#endif // ProfilerParent_h |