Bug 1577658 - Factor PrepareUniqueStacks out of ProfiledThreadData::StreamJSON - r=canaltinova
authorGerald Squelart <gsquelart@mozilla.com>
Thu, 21 Oct 2021 05:47:22 +0000
changeset 596529 622312b0321ab932085901b5f65a1ee28f8d6974
parent 596528 a2a8751250c13a5e8991034fbef35a726b3bc159
child 596530 d3046c6ab51e4c2011f559f1d5e0f2618c91a622
push id38900
push usernfay@mozilla.com
push dateThu, 21 Oct 2021 09:36:31 +0000
treeherdermozilla-central@f12b7ea34395 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerscanaltinova
bugs1577658
milestone95.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1577658 - Factor PrepareUniqueStacks out of ProfiledThreadData::StreamJSON - r=canaltinova The start of StreamJSON is about setting up the UniqueStacks, it can be factored out. In a later patch, this will be used to prepare the UniqueStacks for each thread in one loop, before processing the profile buffer. Differential Revision: https://phabricator.services.mozilla.com/D128437
tools/profiler/core/ProfiledThreadData.cpp
tools/profiler/core/ProfiledThreadData.h
--- a/tools/profiler/core/ProfiledThreadData.cpp
+++ b/tools/profiler/core/ProfiledThreadData.cpp
@@ -25,21 +25,20 @@ ProfiledThreadData::ProfiledThreadData(
                   aThreadInfo.IsMainThread(), aThreadInfo.RegisterTime()) {
   MOZ_COUNT_CTOR(ProfiledThreadData);
 }
 
 ProfiledThreadData::~ProfiledThreadData() {
   MOZ_COUNT_DTOR(ProfiledThreadData);
 }
 
-void ProfiledThreadData::StreamJSON(
-    const ProfileBuffer& aBuffer, JSContext* aCx, SpliceableJSONWriter& aWriter,
-    const nsACString& aProcessName, const nsACString& aETLDplus1,
-    const mozilla::TimeStamp& aProcessStartTime, double aSinceTime,
-    bool JSTracerEnabled, ProfilerCodeAddressService* aService) {
+mozilla::NotNull<mozilla::UniquePtr<UniqueStacks>>
+ProfiledThreadData::PrepareUniqueStacks(const ProfileBuffer& aBuffer,
+                                        JSContext* aCx,
+                                        ProfilerCodeAddressService* aService) {
   if (mJITFrameInfoForPreviousJSContexts &&
       mJITFrameInfoForPreviousJSContexts->HasExpired(
           aBuffer.BufferRangeStart())) {
     mJITFrameInfoForPreviousJSContexts = nullptr;
   }
 
   // If we have an existing JITFrameInfo in mJITFrameInfoForPreviousJSContexts,
   // copy the data from it.
@@ -48,38 +47,48 @@ void ProfiledThreadData::StreamJSON(
           ? JITFrameInfo(*mJITFrameInfoForPreviousJSContexts)
           : JITFrameInfo();
 
   if (aCx && mBufferPositionWhenReceivedJSContext) {
     aBuffer.AddJITInfoForRange(*mBufferPositionWhenReceivedJSContext,
                                mThreadInfo.ThreadId(), aCx, jitFrameInfo);
   }
 
-  UniqueStacks uniqueStacks(std::move(jitFrameInfo), aService);
+  return mozilla::MakeNotNull<mozilla::UniquePtr<UniqueStacks>>(
+      std::move(jitFrameInfo), aService);
+}
 
-  MOZ_ASSERT(uniqueStacks.mUniqueStrings);
-  aWriter.SetUniqueStrings(*uniqueStacks.mUniqueStrings);
+void ProfiledThreadData::StreamJSON(
+    const ProfileBuffer& aBuffer, JSContext* aCx, SpliceableJSONWriter& aWriter,
+    const nsACString& aProcessName, const nsACString& aETLDplus1,
+    const mozilla::TimeStamp& aProcessStartTime, double aSinceTime,
+    bool JSTracerEnabled, ProfilerCodeAddressService* aService) {
+  mozilla::NotNull<mozilla::UniquePtr<UniqueStacks>> uniqueStacks =
+      PrepareUniqueStacks(aBuffer, aCx, aService);
+
+  MOZ_ASSERT(uniqueStacks->mUniqueStrings);
+  aWriter.SetUniqueStrings(*uniqueStacks->mUniqueStrings);
 
   aWriter.Start();
   {
     StreamSamplesAndMarkers(mThreadInfo.Name(), mThreadInfo.ThreadId(), aBuffer,
                             aWriter, aProcessName, aETLDplus1,
                             aProcessStartTime, mThreadInfo.RegisterTime(),
-                            mUnregisterTime, aSinceTime, uniqueStacks);
+                            mUnregisterTime, aSinceTime, *uniqueStacks);
 
     aWriter.StartObjectProperty("stackTable");
     {
       {
         JSONSchemaWriter schema(aWriter);
         schema.WriteField("prefix");
         schema.WriteField("frame");
       }
 
       aWriter.StartArrayProperty("data");
-      { uniqueStacks.SpliceStackTableElements(aWriter); }
+      { uniqueStacks->SpliceStackTableElements(aWriter); }
       aWriter.EndArray();
     }
     aWriter.EndObject();
 
     aWriter.StartObjectProperty("frameTable");
     {
       {
         JSONSchemaWriter schema(aWriter);
@@ -90,24 +99,24 @@ void ProfiledThreadData::StreamJSON(
         schema.WriteField("optimizations");
         schema.WriteField("line");
         schema.WriteField("column");
         schema.WriteField("category");
         schema.WriteField("subcategory");
       }
 
       aWriter.StartArrayProperty("data");
-      { uniqueStacks.SpliceFrameTableElements(aWriter); }
+      { uniqueStacks->SpliceFrameTableElements(aWriter); }
       aWriter.EndArray();
     }
     aWriter.EndObject();
 
     aWriter.StartArrayProperty("stringTable");
     {
-      std::move(*uniqueStacks.mUniqueStrings)
+      std::move(*uniqueStacks->mUniqueStrings)
           .SpliceStringTableElements(aWriter);
     }
     aWriter.EndArray();
   }
 
   if (aCx && JSTracerEnabled) {
     StreamTraceLoggerJSON(aCx, aWriter, aProcessStartTime);
   }
--- a/tools/profiler/core/ProfiledThreadData.h
+++ b/tools/profiler/core/ProfiledThreadData.h
@@ -3,29 +3,29 @@
 /* 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 ProfiledThreadData_h
 #define ProfiledThreadData_h
 
 #include "platform.h"
+#include "ProfileBuffer.h"
+#include "ProfileBufferEntry.h"
 
 #include "mozilla/Maybe.h"
+#include "mozilla/NotNull.h"
 #include "mozilla/ProfilerThreadRegistrationInfo.h"
+#include "mozilla/RefPtr.h"
 #include "mozilla/TimeStamp.h"
 #include "mozilla/UniquePtr.h"
-#include "mozilla/RefPtr.h"
 #include "nsStringFwd.h"
 
-class ProfileBuffer;
+class nsIEventTarget;
 class ProfilerCodeAddressService;
-class UniqueStacks;
-class nsIEventTarget;
-struct JITFrameInfo;
 struct JSContext;
 
 namespace mozilla::baseprofiler {
 class SpliceableJSONWriter;
 }
 
 // This class contains information about a thread that is only relevant while
 // the profiler is running, for any threads (both alive and dead) whose thread
@@ -67,16 +67,20 @@ class ProfiledThreadData final {
     mPreviousThreadRunningTimes.Clear();
   }
   mozilla::Maybe<uint64_t> BufferPositionWhenUnregistered() {
     return mBufferPositionWhenUnregistered;
   }
 
   mozilla::Maybe<uint64_t>& LastSample() { return mLastSample; }
 
+  mozilla::NotNull<mozilla::UniquePtr<UniqueStacks>> PrepareUniqueStacks(
+      const ProfileBuffer& aBuffer, JSContext* aCx,
+      ProfilerCodeAddressService* aService);
+
   void StreamJSON(const ProfileBuffer& aBuffer, JSContext* aCx,
                   mozilla::baseprofiler::SpliceableJSONWriter& aWriter,
                   const nsACString& aProcessName, const nsACString& aETLDplus1,
                   const mozilla::TimeStamp& aProcessStartTime,
                   double aSinceTime, bool aJSTracerEnabled,
                   ProfilerCodeAddressService* aService);
 
   void StreamTraceLoggerJSON(