Bug 1330184 - Allow StreamMetaObject to be called on a background thread, but only include startTime and version for those calls. r=njn draft
authorMarkus Stange <mstange@themasta.com>
Mon, 29 May 2017 13:44:28 -0400
changeset 586674 8c5d2b4ccacbbec92711a9561d4166e1e7c376c7
parent 586673 b04504b06aa80635a50d7ce1dcec43a994d6ba8d
child 586675 64def3fc572c55e2865f5adc570eb841fc759352
push id61485
push userbmo:mstange@themasta.com
push dateTue, 30 May 2017 22:11:39 +0000
reviewersnjn
bugs1330184
milestone55.0a1
Bug 1330184 - Allow StreamMetaObject to be called on a background thread, but only include startTime and version for those calls. r=njn MozReview-Commit-ID: 3AuX0a2Brrd
tools/profiler/core/platform.cpp
--- a/tools/profiler/core/platform.cpp
+++ b/tools/profiler/core/platform.cpp
@@ -1398,42 +1398,52 @@ StreamTaskTracer(PSLockRef aLock, Splice
   aWriter.DoubleProperty(
     "start", static_cast<double>(mozilla::tasktracer::GetStartTime()));
 #endif
 }
 
 static void
 StreamMetaJSCustomObject(PSLockRef aLock, SpliceableJSONWriter& aWriter)
 {
-  MOZ_RELEASE_ASSERT(NS_IsMainThread());
   MOZ_RELEASE_ASSERT(CorePS::Exists() && ActivePS::Exists(aLock));
 
   aWriter.IntProperty("version", 6);
+
+  // The "startTime" field holds the number of milliseconds since midnight
+  // January 1, 1970 GMT. This grotty code computes (Now - (Now -
+  // ProcessStartTime)) to convert CorePS::ProcessStartTime() into that form.
+  mozilla::TimeDuration delta =
+    mozilla::TimeStamp::Now() - CorePS::ProcessStartTime(aLock);
+  aWriter.DoubleProperty(
+    "startTime", static_cast<double>(PR_Now()/1000.0 - delta.ToMilliseconds()));
+
+  if (!NS_IsMainThread()) {
+    // Leave the rest of the properties out if we're not on the main thread.
+    // At the moment, the only case in which this function is called on a
+    // background thread is if we're in a content process and are going to
+    // send this profile to the parent process. In that case, the parent
+    // process profile's "meta" object already has the rest of the properties,
+    // and the parent process profile is dumped on that process's main thread.
+    return;
+  }
+
   aWriter.DoubleProperty("interval", ActivePS::Interval(aLock));
   aWriter.IntProperty("stackwalk", ActivePS::FeatureStackWalk(aLock));
 
 #ifdef DEBUG
   aWriter.IntProperty("debug", 1);
 #else
   aWriter.IntProperty("debug", 0);
 #endif
 
   aWriter.IntProperty("gcpoison", JS::IsGCPoisoning() ? 1 : 0);
 
   bool asyncStacks = Preferences::GetBool("javascript.options.asyncstack");
   aWriter.IntProperty("asyncstack", asyncStacks);
 
-  // The "startTime" field holds the number of milliseconds since midnight
-  // January 1, 1970 GMT. This grotty code computes (Now - (Now -
-  // ProcessStartTime)) to convert CorePS::ProcessStartTime() into that form.
-  mozilla::TimeDuration delta =
-    mozilla::TimeStamp::Now() - CorePS::ProcessStartTime(aLock);
-  aWriter.DoubleProperty(
-    "startTime", static_cast<double>(PR_Now()/1000.0 - delta.ToMilliseconds()));
-
   aWriter.IntProperty("processType", XRE_GetProcessType());
 
   nsresult res;
   nsCOMPtr<nsIHttpProtocolHandler> http =
     do_GetService(NS_NETWORK_PROTOCOL_CONTRACTID_PREFIX "http", &res);
 
   if (!NS_FAILED(res)) {
     nsAutoCString string;