Bug 1577658 - Factor StreamTablesAndTraceLogger out of ProfiledThreadData::StreamJSON - r=canaltinova
authorGerald Squelart <gsquelart@mozilla.com>
Thu, 21 Oct 2021 05:47:24 +0000
changeset 596533 ba7fdaf84afb5a29d15a35bd2b2103c51607ea20
parent 596532 6c17f87fab6e1801a05a2be39445dca1de40172c
child 596534 b9eb9afeae642c69ae3304242dc300b351fd4d2e
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 StreamTablesAndTraceLogger out of ProfiledThreadData::StreamJSON - r=canaltinova This new function will be used a second time in a later patch. Differential Revision: https://phabricator.services.mozilla.com/D128441
tools/profiler/core/ProfiledThreadData.cpp
--- a/tools/profiler/core/ProfiledThreadData.cpp
+++ b/tools/profiler/core/ProfiledThreadData.cpp
@@ -114,16 +114,65 @@ static void StreamTraceLoggerJSON(JSCont
     }
     aWriter.EndArray();
 
     aWriter.IntProperty("length", length);
   }
   aWriter.EndObject();
 }
 
+static void StreamTablesAndTraceLogger(
+    UniqueStacks&& aUniqueStacks, JSContext* aCx, SpliceableJSONWriter& aWriter,
+    const mozilla::TimeStamp& aProcessStartTime, bool JSTracerEnabled) {
+  aWriter.StartObjectProperty("stackTable");
+  {
+    {
+      JSONSchemaWriter schema(aWriter);
+      schema.WriteField("prefix");
+      schema.WriteField("frame");
+    }
+
+    aWriter.StartArrayProperty("data");
+    { aUniqueStacks.SpliceStackTableElements(aWriter); }
+    aWriter.EndArray();
+  }
+  aWriter.EndObject();
+
+  aWriter.StartObjectProperty("frameTable");
+  {
+    {
+      JSONSchemaWriter schema(aWriter);
+      schema.WriteField("location");
+      schema.WriteField("relevantForJS");
+      schema.WriteField("innerWindowID");
+      schema.WriteField("implementation");
+      schema.WriteField("optimizations");
+      schema.WriteField("line");
+      schema.WriteField("column");
+      schema.WriteField("category");
+      schema.WriteField("subcategory");
+    }
+
+    aWriter.StartArrayProperty("data");
+    { aUniqueStacks.SpliceFrameTableElements(aWriter); }
+    aWriter.EndArray();
+  }
+  aWriter.EndObject();
+
+  aWriter.StartArrayProperty("stringTable");
+  {
+    std::move(*aUniqueStacks.mUniqueStrings).SpliceStringTableElements(aWriter);
+  }
+  aWriter.EndArray();
+
+  if (aCx && JSTracerEnabled) {
+    StreamTraceLoggerJSON(aCx, aWriter, aProcessStartTime);
+  }
+}
+
 mozilla::NotNull<mozilla::UniquePtr<UniqueStacks>>
 ProfiledThreadData::PrepareUniqueStacks(const ProfileBuffer& aBuffer,
                                         JSContext* aCx,
                                         ProfilerCodeAddressService* aService) {
   if (mJITFrameInfoForPreviousJSContexts &&
       mJITFrameInfoForPreviousJSContexts->HasExpired(
           aBuffer.BufferRangeStart())) {
     mJITFrameInfoForPreviousJSContexts = nullptr;
@@ -158,63 +207,19 @@ void ProfiledThreadData::StreamJSON(
 
   aWriter.Start();
   {
     StreamSamplesAndMarkers(mThreadInfo.Name(), mThreadInfo.ThreadId(), aBuffer,
                             aWriter, aProcessName, aETLDplus1,
                             aProcessStartTime, mThreadInfo.RegisterTime(),
                             mUnregisterTime, aSinceTime, *uniqueStacks);
 
-    aWriter.StartObjectProperty("stackTable");
-    {
-      {
-        JSONSchemaWriter schema(aWriter);
-        schema.WriteField("prefix");
-        schema.WriteField("frame");
-      }
-
-      aWriter.StartArrayProperty("data");
-      { uniqueStacks->SpliceStackTableElements(aWriter); }
-      aWriter.EndArray();
-    }
-    aWriter.EndObject();
-
-    aWriter.StartObjectProperty("frameTable");
-    {
-      {
-        JSONSchemaWriter schema(aWriter);
-        schema.WriteField("location");
-        schema.WriteField("relevantForJS");
-        schema.WriteField("innerWindowID");
-        schema.WriteField("implementation");
-        schema.WriteField("optimizations");
-        schema.WriteField("line");
-        schema.WriteField("column");
-        schema.WriteField("category");
-        schema.WriteField("subcategory");
-      }
-
-      aWriter.StartArrayProperty("data");
-      { uniqueStacks->SpliceFrameTableElements(aWriter); }
-      aWriter.EndArray();
-    }
-    aWriter.EndObject();
-
-    aWriter.StartArrayProperty("stringTable");
-    {
-      std::move(*uniqueStacks->mUniqueStrings)
-          .SpliceStringTableElements(aWriter);
-    }
-    aWriter.EndArray();
+    StreamTablesAndTraceLogger(std::move(*uniqueStacks), aCx, aWriter,
+                               aProcessStartTime, JSTracerEnabled);
   }
-
-  if (aCx && JSTracerEnabled) {
-    StreamTraceLoggerJSON(aCx, aWriter, aProcessStartTime);
-  }
-
   aWriter.End();
 
   aWriter.ResetUniqueStrings();
 }
 
 // StreamSamplesDataCallback: () -> ProfilerThreadId
 // StreamMarkersDataCallback: () -> void
 // Returns the ProfilerThreadId returned by StreamSamplesDataCallback, which