From 0ebf5bdf043a27fd3dfb7f92e0cb63d88954c44d Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Fri, 19 Apr 2024 03:47:29 +0200 Subject: Adding upstream version 115.8.0esr. Signed-off-by: Daniel Baumann --- tools/profiler/gecko/nsProfiler.h | 117 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 117 insertions(+) create mode 100644 tools/profiler/gecko/nsProfiler.h (limited to 'tools/profiler/gecko/nsProfiler.h') diff --git a/tools/profiler/gecko/nsProfiler.h b/tools/profiler/gecko/nsProfiler.h new file mode 100644 index 0000000000..3757df3079 --- /dev/null +++ b/tools/profiler/gecko/nsProfiler.h @@ -0,0 +1,117 @@ +/* -*- 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 nsProfiler_h +#define nsProfiler_h + +#include "base/process.h" +#include "mozilla/Attributes.h" +#include "mozilla/Maybe.h" +#include "mozilla/MozPromise.h" +#include "mozilla/ProfileJSONWriter.h" +#include "mozilla/ProportionValue.h" +#include "mozilla/TimeStamp.h" +#include "mozilla/UniquePtr.h" +#include "mozilla/Vector.h" +#include "nsIProfiler.h" +#include "nsITimer.h" +#include "nsServiceManagerUtils.h" +#include "ProfilerCodeAddressService.h" +#include "ProfileAdditionalInformation.h" + +namespace Json { +class Value; +} // namespace Json + +class nsProfiler final : public nsIProfiler { + public: + nsProfiler(); + + NS_DECL_ISUPPORTS + NS_DECL_NSIPROFILER + + nsresult Init(); + + static nsProfiler* GetOrCreate() { + nsCOMPtr iprofiler = + do_GetService("@mozilla.org/tools/profiler;1"); + return static_cast(iprofiler.get()); + } + + private: + ~nsProfiler(); + + using GatheringPromiseAndroid = + mozilla::MozPromise, nsresult, true>; + using GatheringPromise = + mozilla::MozPromise; + using SymbolTablePromise = + mozilla::MozPromise; + + RefPtr StartGathering(double aSinceTime); + void GatheredOOPProfile( + base::ProcessId aChildPid, const nsACString& aProfile, + mozilla::Maybe&& + aAdditionalInformation); + void FinishGathering(); + void ResetGathering(nsresult aPromiseRejectionIfPending); + static void GatheringTimerCallback(nsITimer* aTimer, void* aClosure); + void RestartGatheringTimer(); + + RefPtr GetSymbolTableMozPromise( + const nsACString& aDebugPath, const nsACString& aBreakpadID); + + struct ExitProfile { + nsCString mJSON; + uint64_t mBufferPositionAtGatherTime; + }; + + struct PendingProfile { + base::ProcessId childPid; + + mozilla::ProportionValue progressProportion; + nsCString progressLocation; + + mozilla::TimeStamp lastProgressRequest; + mozilla::TimeStamp lastProgressResponse; + mozilla::TimeStamp lastProgressChange; + + explicit PendingProfile(base::ProcessId aChildPid) : childPid(aChildPid) {} + }; + + PendingProfile* GetPendingProfile(base::ProcessId aChildPid); + // Returns false if the request could not be sent. + bool SendProgressRequest(PendingProfile& aPendingProfile); + + // If the log is active, call aJsonLogObjectUpdater(Json::Value&) on the log's + // root object. + template + void Log(JsonLogObjectUpdater&& aJsonLogObjectUpdater); + // If the log is active, call aJsonArrayAppender(Json::Value&) on a Json + // array that already contains a timestamp, and to which event-related + // elements may be appended. + template + void LogEvent(JsonArrayAppender&& aJsonArrayAppender); + void LogEventLiteralString(const char* aEventString); + + // These fields are all related to profile gathering. + mozilla::Vector mExitProfiles; + mozilla::Maybe> mPromiseHolder; + nsCOMPtr mSymbolTableThread; + mozilla::Maybe mFailureLatchSource; + mozilla::Maybe mWriter; + mozilla::Maybe + mProfileGenerationAdditionalInformation; + mozilla::Vector mPendingProfiles; + bool mGathering; + nsCOMPtr mGatheringTimer; + // Supplemental log to the profiler's "profilingLog" (which has already been + // completed in JSON profiles that are gathered). + mozilla::UniquePtr mGatheringLog; +}; + +#endif // nsProfiler_h -- cgit v1.2.3