Bug 1434965 - Split StreamFrame into two different implementations for JIT and non-JIT frames. r?njn draft
authorMarkus Stange <mstange@themasta.com>
Sat, 10 Feb 2018 15:14:28 -0500
changeset 754058 b8094547943730f7d3c1e582a3f13dbcb2ecabce
parent 753742 2a5e16ca1c1f3fdf2928c21071dc2976c24d20af
child 754059 6891c97cdeb19401891030ea852eb8215d6d11fb
push id98744
push userbmo:mstange@themasta.com
push dateMon, 12 Feb 2018 19:50:57 +0000
reviewersnjn
bugs1434965
milestone60.0a1
Bug 1434965 - Split StreamFrame into two different implementations for JIT and non-JIT frames. r?njn MozReview-Commit-ID: Ap4FVS8FMKh
tools/profiler/core/ProfileBufferEntry.cpp
tools/profiler/core/ProfileBufferEntry.h
--- a/tools/profiler/core/ProfileBufferEntry.cpp
+++ b/tools/profiler/core/ProfileBufferEntry.cpp
@@ -343,23 +343,26 @@ uint32_t UniqueStacks::GetOrAddFrameInde
   if (aFrame.mJITFrameHandle) {
     void* canonicalAddr = aFrame.mJITFrameHandle->canonicalAddress();
     if (canonicalAddr != *aFrame.mJITAddress) {
       OnStackFrameKey canonicalKey(canonicalAddr, *aFrame.mJITDepth, *aFrame.mJITFrameHandle);
       uint32_t canonicalIndex = GetOrAddFrameIndex(canonicalKey);
       mFrameToIndexMap.Put(aFrame, canonicalIndex);
       return canonicalIndex;
     }
+    // A manual count is used instead of mFrameToIndexMap.Count() due to
+    // forwarding of canonical JIT frames above.
+    index = mFrameCount++;
+    mFrameToIndexMap.Put(aFrame, index);
+    StreamJITFrame(*aFrame.mJITFrameHandle);
+  } else {
+    index = mFrameCount++;
+    mFrameToIndexMap.Put(aFrame, index);
+    StreamNonJITFrame(aFrame);
   }
-
-  // A manual count is used instead of mFrameToIndexMap.Count() due to
-  // forwarding of canonical JIT frames above.
-  index = mFrameCount++;
-  mFrameToIndexMap.Put(aFrame, index);
-  StreamFrame(aFrame);
   return index;
 }
 
 uint32_t UniqueStacks::LookupJITFrameDepth(void* aAddr)
 {
   uint32_t depth;
 
   auto it = mJITFrameDepthMap.find(aAddr);
@@ -397,92 +400,103 @@ void UniqueStacks::StreamStack(const Sta
 
   AutoArraySchemaWriter writer(mStackTableWriter, mUniqueStrings);
   if (aStack.mPrefixStackIndex.isSome()) {
     writer.IntElement(PREFIX, *aStack.mPrefixStackIndex);
   }
   writer.IntElement(FRAME, aStack.mFrameIndex);
 }
 
-void UniqueStacks::StreamFrame(const OnStackFrameKey& aFrame)
+void
+UniqueStacks::StreamNonJITFrame(const FrameKey& aFrame)
+{
+  enum Schema : uint32_t {
+    LOCATION = 0,
+    IMPLEMENTATION = 1,
+    OPTIMIZATIONS = 2,
+    LINE = 3,
+    CATEGORY = 4
+  };
+
+  AutoArraySchemaWriter writer(mFrameTableWriter, mUniqueStrings);
+
+  writer.StringElement(LOCATION, aFrame.mLocation.get());
+  if (aFrame.mLine.isSome()) {
+    writer.IntElement(LINE, *aFrame.mLine);
+  }
+  if (aFrame.mCategory.isSome()) {
+    writer.IntElement(CATEGORY, *aFrame.mCategory);
+  }
+}
+
+void
+UniqueStacks::StreamJITFrame(const JS::ProfiledFrameHandle& aJITFrame)
 {
   enum Schema : uint32_t {
     LOCATION = 0,
     IMPLEMENTATION = 1,
     OPTIMIZATIONS = 2,
     LINE = 3,
     CATEGORY = 4
   };
 
   AutoArraySchemaWriter writer(mFrameTableWriter, mUniqueStrings);
 
-  if (!aFrame.mJITFrameHandle) {
-    writer.StringElement(LOCATION, aFrame.mLocation.get());
-    if (aFrame.mLine.isSome()) {
-      writer.IntElement(LINE, *aFrame.mLine);
-    }
-    if (aFrame.mCategory.isSome()) {
-      writer.IntElement(CATEGORY, *aFrame.mCategory);
-    }
-  } else {
-    const JS::ProfiledFrameHandle& jitFrame = *aFrame.mJITFrameHandle;
+  writer.StringElement(LOCATION, aJITFrame.label());
 
-    writer.StringElement(LOCATION, jitFrame.label());
+  JS::ProfilingFrameIterator::FrameKind frameKind = aJITFrame.frameKind();
+  MOZ_ASSERT(frameKind == JS::ProfilingFrameIterator::Frame_Ion ||
+              frameKind == JS::ProfilingFrameIterator::Frame_Baseline);
+  writer.StringElement(IMPLEMENTATION,
+                        frameKind == JS::ProfilingFrameIterator::Frame_Ion
+                        ? "ion"
+                        : "baseline");
 
-    JS::ProfilingFrameIterator::FrameKind frameKind = jitFrame.frameKind();
-    MOZ_ASSERT(frameKind == JS::ProfilingFrameIterator::Frame_Ion ||
-               frameKind == JS::ProfilingFrameIterator::Frame_Baseline);
-    writer.StringElement(IMPLEMENTATION,
-                         frameKind == JS::ProfilingFrameIterator::Frame_Ion
-                         ? "ion"
-                         : "baseline");
+  if (aJITFrame.hasTrackedOptimizations()) {
+    writer.FillUpTo(OPTIMIZATIONS);
+    mFrameTableWriter.StartObjectElement();
+    {
+      mFrameTableWriter.StartArrayProperty("types");
+      {
+        StreamOptimizationTypeInfoOp typeInfoOp(mFrameTableWriter, mUniqueStrings);
+        aJITFrame.forEachOptimizationTypeInfo(typeInfoOp);
+      }
+      mFrameTableWriter.EndArray();
 
-    if (jitFrame.hasTrackedOptimizations()) {
-      writer.FillUpTo(OPTIMIZATIONS);
-      mFrameTableWriter.StartObjectElement();
+      JS::Rooted<JSScript*> script(mContext);
+      jsbytecode* pc;
+      mFrameTableWriter.StartObjectProperty("attempts");
       {
-        mFrameTableWriter.StartArrayProperty("types");
         {
-          StreamOptimizationTypeInfoOp typeInfoOp(mFrameTableWriter, mUniqueStrings);
-          jitFrame.forEachOptimizationTypeInfo(typeInfoOp);
+          JSONSchemaWriter schema(mFrameTableWriter);
+          schema.WriteField("strategy");
+          schema.WriteField("outcome");
+        }
+
+        mFrameTableWriter.StartArrayProperty("data");
+        {
+          StreamOptimizationAttemptsOp attemptOp(mFrameTableWriter, mUniqueStrings);
+          aJITFrame.forEachOptimizationAttempt(attemptOp, script.address(), &pc);
         }
         mFrameTableWriter.EndArray();
-
-        JS::Rooted<JSScript*> script(mContext);
-        jsbytecode* pc;
-        mFrameTableWriter.StartObjectProperty("attempts");
-        {
-          {
-            JSONSchemaWriter schema(mFrameTableWriter);
-            schema.WriteField("strategy");
-            schema.WriteField("outcome");
-          }
-
-          mFrameTableWriter.StartArrayProperty("data");
-          {
-            StreamOptimizationAttemptsOp attemptOp(mFrameTableWriter, mUniqueStrings);
-            jitFrame.forEachOptimizationAttempt(attemptOp, script.address(), &pc);
-          }
-          mFrameTableWriter.EndArray();
-        }
-        mFrameTableWriter.EndObject();
-
-        if (JSAtom* name = js::GetPropertyNameFromPC(script, pc)) {
-          char buf[512];
-          JS_PutEscapedFlatString(buf, mozilla::ArrayLength(buf), js::AtomToFlatString(name), 0);
-          mUniqueStrings.WriteProperty(mFrameTableWriter, "propertyName", buf);
-        }
-
-        unsigned line, column;
-        line = JS_PCToLineNumber(script, pc, &column);
-        mFrameTableWriter.IntProperty("line", line);
-        mFrameTableWriter.IntProperty("column", column);
       }
       mFrameTableWriter.EndObject();
+
+      if (JSAtom* name = js::GetPropertyNameFromPC(script, pc)) {
+        char buf[512];
+        JS_PutEscapedFlatString(buf, mozilla::ArrayLength(buf), js::AtomToFlatString(name), 0);
+        mUniqueStrings.WriteProperty(mFrameTableWriter, "propertyName", buf);
+      }
+
+      unsigned line, column;
+      line = JS_PCToLineNumber(script, pc, &column);
+      mFrameTableWriter.IntProperty("line", line);
+      mFrameTableWriter.IntProperty("column", column);
     }
+    mFrameTableWriter.EndObject();
   }
 }
 
 struct ProfileSample
 {
   uint32_t mStack;
   double mTime;
   Maybe<double> mResponsiveness;
--- a/tools/profiler/core/ProfileBufferEntry.h
+++ b/tools/profiler/core/ProfileBufferEntry.h
@@ -286,17 +286,18 @@ public:
   MOZ_MUST_USE uint32_t GetOrAddStackIndex(const StackKey& aStack);
 
   uint32_t LookupJITFrameDepth(void* aAddr);
   void AddJITFrameDepth(void* aAddr, unsigned depth);
   void SpliceFrameTableElements(SpliceableJSONWriter& aWriter);
   void SpliceStackTableElements(SpliceableJSONWriter& aWriter);
 
 private:
-  void StreamFrame(const OnStackFrameKey& aFrame);
+  void StreamNonJITFrame(const FrameKey& aFrame);
+  void StreamJITFrame(const JS::ProfiledFrameHandle& aJITFrame);
   void StreamStack(const StackKey& aStack);
 
 public:
   UniqueJSONStrings mUniqueStrings;
 
 private:
   JSContext* mContext;