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
--- 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;