Bug 870782 - call NS_GetSpecialDirectory on the main thread rather than off-mainthread in telemetry; r=vladan
authorNathan Froyd <froydnj@mozilla.com>
Fri, 10 May 2013 11:37:13 -0400
changeset 131931 85562dbf54ad3e13df7e9e97111e4e2ce3ff13d8
parent 131930 e05b8147a276b7451f0d648f494f38845df45f22
child 131932 0b319e0d62383642b15e675a328a827deb6182d6
push id24678
push userryanvm@gmail.com
push dateThu, 16 May 2013 01:15:09 +0000
treeherdermozilla-central@19cc1efe8097 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersvladan
bugs870782
milestone24.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 870782 - call NS_GetSpecialDirectory on the main thread rather than off-mainthread in telemetry; r=vladan
toolkit/components/telemetry/Telemetry.cpp
--- a/toolkit/components/telemetry/Telemetry.cpp
+++ b/toolkit/components/telemetry/Telemetry.cpp
@@ -309,17 +309,17 @@ private:
   typedef AutoHashtable<AddonHistogramEntryType> AddonHistogramMapType;
   typedef nsBaseHashtableET<nsCStringHashKey, AddonHistogramMapType *> AddonEntryType;
   typedef AutoHashtable<AddonEntryType> AddonMapType;
   static bool AddonHistogramReflector(AddonHistogramEntryType *entry,
                                       JSContext *cx, JS::Handle<JSObject*> obj);
   static bool AddonReflector(AddonEntryType *entry, JSContext *cx, JS::Handle<JSObject*> obj);
   static bool CreateHistogramForAddon(const nsACString &name,
                                       AddonHistogramInfo &info);
-  void ReadLateWritesStacks();
+  void ReadLateWritesStacks(nsIFile* aProfileDir);
   AddonMapType mAddonMap;
 
   // This is used for speedy string->Telemetry::ID conversions
   typedef nsBaseHashtableET<nsCharPtrHashKey, Telemetry::ID> CharPtrEntryType;
   typedef AutoHashtable<CharPtrEntryType> HistogramMapType;
   HistogramMapType mHistogramMap;
   bool mCanRecord;
   static TelemetryImpl *sTelemetry;
@@ -738,60 +738,60 @@ GetFailedLockCount(nsIInputStream* inStr
   nsresult rv;
   rv = NS_ReadInputStreamToString(inStream, bufStr, aCount);
   NS_ENSURE_SUCCESS(rv, false);
   result = bufStr.ToInteger(&rv);
   return NS_SUCCEEDED(rv) && result > 0;
 }
 
 nsresult
-GetFailedProfileLockFile(nsIFile* *aFile, nsIFile* aProfileDir = nullptr)
+GetFailedProfileLockFile(nsIFile* *aFile, nsIFile* aProfileDir)
 {
-  nsresult rv;
-  if (aProfileDir) {
-    rv = aProfileDir->Clone(aFile);
-  } else {
-    rv = NS_GetSpecialDirectory(NS_APP_USER_PROFILE_50_DIR, aFile);
-  }
+  NS_ENSURE_ARG_POINTER(aProfileDir);
+
+  nsresult rv = aProfileDir->Clone(aFile);
   NS_ENSURE_SUCCESS(rv, rv);
 
   (*aFile)->AppendNative(NS_LITERAL_CSTRING("Telemetry.FailedProfileLocks.txt"));
   return NS_OK;
 }
 
 class nsFetchTelemetryData : public nsRunnable
 {
 public:
   nsFetchTelemetryData(const char* aShutdownTimeFilename,
-                       nsIFile* aFailedProfileLockFile)
+                       nsIFile* aFailedProfileLockFile,
+                       nsIFile* aProfileDir)
     : mShutdownTimeFilename(aShutdownTimeFilename),
       mFailedProfileLockFile(aFailedProfileLockFile),
-      mTelemetry(TelemetryImpl::sTelemetry)
+      mTelemetry(TelemetryImpl::sTelemetry),
+      mProfileDir(aProfileDir)
   {
   }
 
 private:
   const char* mShutdownTimeFilename;
   nsCOMPtr<nsIFile> mFailedProfileLockFile;
   nsCOMPtr<TelemetryImpl> mTelemetry;
+  nsCOMPtr<nsIFile> mProfileDir;
 
 public:
   void MainThread() {
     mTelemetry->mCachedTelemetryData = true;
     for (unsigned int i = 0, n = mTelemetry->mCallbacks.Count(); i < n; ++i) {
       mTelemetry->mCallbacks[i]->Complete();
     }
     mTelemetry->mCallbacks.Clear();
   }
 
   NS_IMETHOD Run() {
     LoadFailedLockCount(mTelemetry->mFailedLockCount);
     mTelemetry->mLastShutdownTime = 
       ReadLastShutdownDuration(mShutdownTimeFilename);
-    mTelemetry->ReadLateWritesStacks();
+    mTelemetry->ReadLateWritesStacks(mProfileDir);
     nsCOMPtr<nsIRunnable> e =
       NS_NewRunnableMethod(this, &nsFetchTelemetryData::MainThread);
     NS_ENSURE_STATE(e);
     NS_DispatchToMainThread(e, NS_DISPATCH_NORMAL);
     return NS_OK;
   }
 
 private:
@@ -916,27 +916,39 @@ TelemetryImpl::AsyncFetchTelemetryData(n
   // We have to get the filename from the main thread.
   const char *shutdownTimeFilename = GetShutdownTimeFileName();
   if (!shutdownTimeFilename) {
     mCachedTelemetryData = true;
     aCallback->Complete();
     return NS_OK;
   }
 
+  nsCOMPtr<nsIFile> profileDir;
+  nsresult rv = NS_GetSpecialDirectory(NS_APP_USER_PROFILE_50_DIR,
+                                       getter_AddRefs(profileDir));
+  if (NS_FAILED(rv)) {
+    mCachedTelemetryData = true;
+    aCallback->Complete();
+    return NS_OK;
+  }
+
   nsCOMPtr<nsIFile> failedProfileLockFile;
-  nsresult rv = GetFailedProfileLockFile(getter_AddRefs(failedProfileLockFile));
+  rv = GetFailedProfileLockFile(getter_AddRefs(failedProfileLockFile),
+                                profileDir);
   if (NS_FAILED(rv)) {
     mCachedTelemetryData = true;
     aCallback->Complete();
     return NS_OK;
   }
 
   mCallbacks.AppendObject(aCallback);
+
   nsCOMPtr<nsIRunnable> event = new nsFetchTelemetryData(shutdownTimeFilename,
-                                                         failedProfileLockFile);
+                                                         failedProfileLockFile,
+                                                         profileDir);
 
   targetThread->Dispatch(event, NS_DISPATCH_NORMAL);
   return NS_OK;
 }
 
 TelemetryImpl::TelemetryImpl():
 mHistogramMap(Telemetry::HistogramCount),
 mCanRecord(XRE_GetProcessType() == GeckoProcessType_Default),
@@ -1705,27 +1717,20 @@ ReadStack(const char *aFileName, Telemet
     };
     stack.AddFrame(frame);
   }
 
   aStack = stack;
 }
 
 void
-TelemetryImpl::ReadLateWritesStacks()
+TelemetryImpl::ReadLateWritesStacks(nsIFile* aProfileDir)
 {
-  nsCOMPtr<nsIFile> profileDir;
-  nsresult rv = NS_GetSpecialDirectory(NS_APP_USER_PROFILE_50_DIR,
-                                       getter_AddRefs(profileDir));
-  if (!profileDir || NS_FAILED(rv)) {
-    return;
-  }
-
   nsAutoCString nativePath;
-  rv = profileDir->GetNativePath(nativePath);
+  nsresult rv = aProfileDir->GetNativePath(nativePath);
   if (NS_FAILED(rv)) {
     return;
   }
 
   const char *name = nativePath.get();
   PRDir *dir = PR_OpenDir(name);
   if (!dir) {
     return;