tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

commit 228757a213b5af66eb8f71acb0070b54087f52db
parent 26749bd5991b4fc8e0f24a83dcd5aa0234bb7f10
Author: Nazım Can Altınova <canaltinova@gmail.com>
Date:   Tue, 21 Oct 2025 23:59:06 +0000

Bug 1979114 - Include JS sources in the profile additional information r=mstange,profiler-reviewers

This patch adds the JS sources inside the profile additional information
so we can send them through IPC.

Differential Revision: https://phabricator.services.mozilla.com/D259265

Diffstat:
Mtools/profiler/core/ProfileAdditionalInformation.cpp | 31++++++++++++++++++++++++++++++-
Mtools/profiler/core/platform.cpp | 6+++++-
Mtools/profiler/gecko/nsProfiler.cpp | 5+++--
Mtools/profiler/public/ProfileAdditionalInformation.h | 33++++++++++++++++++++++++++++++---
4 files changed, 68 insertions(+), 7 deletions(-)

diff --git a/tools/profiler/core/ProfileAdditionalInformation.cpp b/tools/profiler/core/ProfileAdditionalInformation.cpp @@ -64,6 +64,14 @@ struct ParamTraits<ProfilerJSSourceData> { static bool Read(MessageReader* aReader, paramType* aResult); }; +template <> +struct ParamTraits<mozilla::JSSourceEntry> { + typedef mozilla::JSSourceEntry paramType; + + static void Write(MessageWriter* aWriter, const paramType& aParam); + static bool Read(MessageReader* aReader, paramType* aResult); +}; + void IPC::ParamTraits<SharedLibrary>::Write(MessageWriter* aWriter, const paramType& aParam) { WriteParam(aWriter, aParam.mStart); @@ -240,14 +248,35 @@ bool IPC::ParamTraits<ProfilerJSSourceData>::Read(MessageReader* aReader, } } +void IPC::ParamTraits<mozilla::JSSourceEntry>::Write(MessageWriter* aWriter, + const paramType& aParam) { + WriteParam(aWriter, aParam.uuid); + WriteParam(aWriter, aParam.sourceData); +} + +bool IPC::ParamTraits<mozilla::JSSourceEntry>::Read(MessageReader* aReader, + paramType* aResult) { + return (ReadParam(aReader, &aResult->uuid) && + ReadParam(aReader, &aResult->sourceData)); +} + void IPC::ParamTraits<mozilla::ProfileGenerationAdditionalInformation>::Write( MessageWriter* aWriter, const paramType& aParam) { WriteParam(aWriter, aParam.mSharedLibraries); + WriteParam(aWriter, aParam.mJSSourceEntries); } bool IPC::ParamTraits<mozilla::ProfileGenerationAdditionalInformation>::Read( MessageReader* aReader, paramType* aResult) { - return ReadParam(aReader, &aResult->mSharedLibraries); + if (!ReadParam(aReader, &aResult->mSharedLibraries)) { + return false; + } + + if (!ReadParam(aReader, &aResult->mJSSourceEntries)) { + return false; + } + + return true; } } // namespace IPC diff --git a/tools/profiler/core/platform.cpp b/tools/profiler/core/platform.cpp @@ -3828,6 +3828,9 @@ locked_profiler_stream_json_for_this_process( } SLOW_DOWN_FOR_TESTING(); + // FIXME: Build the JS sources + nsTArray<mozilla::JSSourceEntry> jsSourceEntries; + // Lists the samples for each thread profile aWriter.StartArrayProperty("threads"); { @@ -3977,7 +3980,8 @@ locked_profiler_stream_json_for_this_process( } #endif // DEBUG - return ProfileGenerationAdditionalInformation{std::move(sharedLibraryInfo)}; + return ProfileGenerationAdditionalInformation{std::move(sharedLibraryInfo), + std::move(jsSourceEntries)}; } // Keep this internal function non-static, so it may be used by tests. diff --git a/tools/profiler/gecko/nsProfiler.cpp b/tools/profiler/gecko/nsProfiler.cpp @@ -1178,8 +1178,7 @@ RefPtr<nsProfiler::GatheringPromise> nsProfiler::StartGathering( } // Start building shared library info starting from the current process. - mProfileGenerationAdditionalInformation.emplace( - SharedLibraryInfo::GetInfoForSelf()); + mProfileGenerationAdditionalInformation.emplace(); // Request profiles from the other processes. This will trigger asynchronous // calls to ProfileGatherer::GatheredOOPProfile as the profiles arrive. @@ -1216,6 +1215,8 @@ RefPtr<nsProfiler::GatheringPromise> nsProfiler::StartGathering( return GatheringPromise::CreateAndReject(NS_ERROR_NOT_AVAILABLE, __func__); } + mProfileGenerationAdditionalInformation->Append(rv.unwrap()); + LogEvent([&](Json::Value& aEvent) { aEvent.append( Json::StaticString{"Generated parent process profile, size:"}); diff --git a/tools/profiler/public/ProfileAdditionalInformation.h b/tools/profiler/public/ProfileAdditionalInformation.h @@ -16,8 +16,10 @@ #include "SharedLibraries.h" #include "js/Value.h" +#include "js/Utility.h" #include "js/ProfilingSources.h" #include "nsString.h" +#include "nsTArray.h" namespace IPC { class MessageReader; @@ -27,15 +29,38 @@ struct ParamTraits; } // namespace IPC namespace mozilla { + +// Entry pairing UUID strings with JS source data for WebChannel requests +struct JSSourceEntry { + nsCString uuid; + ProfilerJSSourceData sourceData; + + JSSourceEntry() = default; + JSSourceEntry(nsCString&& aUuid, ProfilerJSSourceData&& aSourceData) + : uuid(std::move(aUuid)), sourceData(std::move(aSourceData)) {} + + size_t SizeOf() const { return uuid.Length() + sourceData.SizeOf(); } +}; + // This structure contains additional information gathered while generating the // profile json and iterating the buffer. struct ProfileGenerationAdditionalInformation { ProfileGenerationAdditionalInformation() = default; explicit ProfileGenerationAdditionalInformation( - SharedLibraryInfo&& aSharedLibraries) - : mSharedLibraries(std::move(aSharedLibraries)) {} + SharedLibraryInfo&& aSharedLibraries, + nsTArray<JSSourceEntry>&& aJSSourceEntries) + : mSharedLibraries(std::move(aSharedLibraries)), + mJSSourceEntries(std::move(aJSSourceEntries)) {} - size_t SizeOf() const { return mSharedLibraries.SizeOf(); } + size_t SizeOf() const { + size_t size = mSharedLibraries.SizeOf(); + + for (const auto& entry : mJSSourceEntries) { + size += entry.SizeOf(); + } + + return size; + } ProfileGenerationAdditionalInformation( const ProfileGenerationAdditionalInformation& other) = delete; @@ -49,6 +74,7 @@ struct ProfileGenerationAdditionalInformation { void Append(ProfileGenerationAdditionalInformation&& aOther) { mSharedLibraries.AddAllSharedLibraries(aOther.mSharedLibraries); + mJSSourceEntries.AppendElements(std::move(aOther.mJSSourceEntries)); } void FinishGathering() { mSharedLibraries.DeduplicateEntries(); } @@ -56,6 +82,7 @@ struct ProfileGenerationAdditionalInformation { void ToJSValue(JSContext* aCx, JS::MutableHandle<JS::Value> aRetVal) const; SharedLibraryInfo mSharedLibraries; + nsTArray<JSSourceEntry> mJSSourceEntries; }; struct ProfileAndAdditionalInformation {