Bug 1329114 - Put profiles from other processes into a 'processes' array, not into the threads array, and don't stringify them. r?njn draft
authorMarkus Stange <mstange@themasta.com>
Sat, 08 Apr 2017 16:00:30 -0400
changeset 558974 7f4064e8d29261b63619a274804e5174217e4249
parent 558973 8b4f96095a48906cad2d3d3e560393b2d895939c
child 558975 37d80135ecb58eef37aba5528f271925091b9f07
push id52998
push userbmo:mstange@themasta.com
push dateSat, 08 Apr 2017 20:07:55 +0000
reviewersnjn
bugs1329114
milestone55.0a1
Bug 1329114 - Put profiles from other processes into a 'processes' array, not into the threads array, and don't stringify them. r?njn MozReview-Commit-ID: Ccl6JIbRMyX
tools/profiler/core/platform.cpp
--- a/tools/profiler/core/platform.cpp
+++ b/tools/profiler/core/platform.cpp
@@ -1200,17 +1200,17 @@ StreamTaskTracer(PS::LockRef aLock, Spli
 #endif
 }
 
 static void
 StreamMetaJSCustomObject(PS::LockRef aLock, SpliceableJSONWriter& aWriter)
 {
   MOZ_RELEASE_ASSERT(NS_IsMainThread());
 
-  aWriter.IntProperty("version", 4);
+  aWriter.IntProperty("version", 5);
   aWriter.DoubleProperty("interval", gPS->Interval(aLock));
   aWriter.IntProperty("stackwalk", gPS->FeatureStackWalk(aLock));
 
 #ifdef DEBUG
   aWriter.IntProperty("debug", 1);
 #else
   aWriter.IntProperty("debug", 0);
 #endif
@@ -1287,18 +1287,19 @@ struct SubprocessClosure
 };
 
 static void
 SubProcessCallback(const char* aProfile, void* aClosure)
 {
   // Called by the observer to get their profile data included as a sub profile.
   SubprocessClosure* closure = (SubprocessClosure*)aClosure;
 
-  // Add the string profile into the profile.
-  closure->mWriter->StringElement(aProfile);
+  // Add the subprocess profile into the profile, as an element in the
+  // "processes" array.
+  closure->mWriter->Splice(aProfile);
 }
 
 #if defined(PROFILE_JAVA)
 static void
 BuildJavaThreadJSObject(SpliceableJSONWriter& aWriter)
 {
   aWriter.StringProperty("name", "Java Main Thread");
 
@@ -1397,33 +1398,16 @@ StreamJSON(PS::LockRef aLock, Spliceable
           // Note that we intentionally include thread profiles which
           // have been marked for pending delete.
 
           info->StreamJSON(gPS->Buffer(aLock), aWriter, gPS->StartTime(aLock),
                            aSinceTime);
         }
       }
 
-      // When notifying observers in other places in this file we are careful
-      // to do it when gPSMutex is unlocked, to avoid deadlocks. But that's not
-      // necessary here, because "profiler-subprocess" observers just call back
-      // into SubprocessCallback, which is simple and doesn't lock gPSMutex.
-      if (CanNotifyObservers()) {
-        // Send a event asking any subprocesses (plugins) to
-        // give us their information
-        SubprocessClosure closure(&aWriter);
-        nsCOMPtr<nsIObserverService> os =
-          mozilla::services::GetObserverService();
-        if (os) {
-          RefPtr<ProfileSaveEvent> pse =
-            new ProfileSaveEvent(SubProcessCallback, &closure);
-          os->NotifyObservers(pse, "profiler-subprocess", nullptr);
-        }
-      }
-
 #if defined(PROFILE_JAVA)
       if (gPS->FeatureJava(aLock)) {
         java::GeckoJavaSampler::Pause();
 
         aWriter.Start();
         {
           BuildJavaThreadJSObject(aWriter);
         }
@@ -1431,16 +1415,35 @@ StreamJSON(PS::LockRef aLock, Spliceable
 
         java::GeckoJavaSampler::Unpause();
       }
 #endif
 
       gPS->SetIsPaused(aLock, false);
     }
     aWriter.EndArray();
+
+    aWriter.StartArrayProperty("processes");
+    // When notifying observers in other places in this file we are careful
+    // to do it when gPSMutex is unlocked, to avoid deadlocks. But that's not
+    // necessary here, because "profiler-subprocess" observers just call back
+    // into SubprocessCallback, which is simple and doesn't lock gPSMutex.
+    if (CanNotifyObservers()) {
+      // Send a event asking any subprocesses (plugins) to
+      // give us their information
+      SubprocessClosure closure(&aWriter);
+      nsCOMPtr<nsIObserverService> os =
+        mozilla::services::GetObserverService();
+      if (os) {
+        RefPtr<ProfileSaveEvent> pse =
+          new ProfileSaveEvent(SubProcessCallback, &closure);
+        os->NotifyObservers(pse, "profiler-subprocess", nullptr);
+      }
+    }
+    aWriter.EndArray();
   }
   aWriter.End();
 }
 
 // END saving/streaming code
 ////////////////////////////////////////////////////////////////////////
 
 ProfilerMarker::ProfilerMarker(const char* aMarkerName,