Bug 686435 - Add a telemetry probe on nsAppShellService::CreateTopLevelWindow. r=taras
authorMike Hommey <mh+mozilla@glandium.org>
Fri, 23 Sep 2011 14:30:49 +0200
changeset 77415 c0b96cb41fc1f4a808afbe5278320f18429e0f7a
parent 77414 41e4d29fb76d1924c7415d5fda73c9437697b89a
child 77416 e299d7fed89dd5fe24a234c226b4f3353a4eb338
push id3
push userfelipc@gmail.com
push dateFri, 30 Sep 2011 20:09:13 +0000
reviewerstaras
bugs686435
milestone9.0a1
Bug 686435 - Add a telemetry probe on nsAppShellService::CreateTopLevelWindow. r=taras
toolkit/components/startup/nsAppStartup.cpp
toolkit/components/telemetry/TelemetryHistograms.h
xpfe/appshell/src/nsAppShellService.cpp
--- a/toolkit/components/startup/nsAppStartup.cpp
+++ b/toolkit/components/startup/nsAppStartup.cpp
@@ -95,16 +95,19 @@
 #endif
 
 #include "mozilla/Telemetry.h"
 
 static NS_DEFINE_CID(kAppShellCID, NS_APPSHELL_CID);
 
 using namespace mozilla;
 extern PRTime gXRE_mainTimestamp;
+// The following tracks our overhead between reaching XRE_main and loading any XUL
+extern PRTime gCreateTopLevelWindowTimestamp;// Timestamp of the first call to
+                                             // nsAppShellService::CreateTopLevelWindow
 extern PRTime gFirstPaintTimestamp;
 // mfinklesessionstore-browser-state-restored might be a better choice than the one below
 static PRTime gRestoredTimestamp = 0;       // Timestamp of sessionstore-windows-restored
 static PRTime gProcessCreationTimestamp = 0;// Timestamp of sessionstore-windows-restored
 
 PRUint32 gRestartMode = 0;
 
 class nsAppExitEvent : public nsRunnable {
@@ -708,17 +711,18 @@ MaybeDefineProperty(JSContext *cx, JSObj
   JSObject *date = js_NewDateObjectMsec(cx, timestamp/PR_USEC_PER_MSEC);
   JS_DefineProperty(cx, obj, name, OBJECT_TO_JSVAL(date), NULL, NULL, JSPROP_ENUMERATE);     
 }
 
 enum {
   INVALID_PROCESS_CREATION = 0,
   INVALID_MAIN,
   INVALID_FIRST_PAINT,
-  INVALID_SESSION_RESTORED
+  INVALID_SESSION_RESTORED,
+  INVALID_CREATE_TOP_LEVEL_WINDOW
 };
 
 NS_IMETHODIMP
 nsAppStartup::GetStartupInfo()
 {
   nsAXPCNativeCallContext *ncc = nsnull;
   nsresult rv;
   nsCOMPtr<nsIXPConnect> xpConnect = do_GetService(nsIXPConnect::GetCID(), &rv);
@@ -758,16 +762,21 @@ nsAppStartup::GetStartupInfo()
 
   MaybeDefineProperty(cx, obj, "process", gProcessCreationTimestamp);
 
   if (gXRE_mainTimestamp >= gProcessCreationTimestamp)
     MaybeDefineProperty(cx, obj, "main", gXRE_mainTimestamp);
   else
     Telemetry::Accumulate(Telemetry::STARTUP_MEASUREMENT_ERRORS, INVALID_MAIN);
 
+  if (gCreateTopLevelWindowTimestamp >= gProcessCreationTimestamp)
+    MaybeDefineProperty(cx, obj, "createTopLevelWindow", gCreateTopLevelWindowTimestamp);
+  else
+    Telemetry::Accumulate(Telemetry::STARTUP_MEASUREMENT_ERRORS, INVALID_CREATE_TOP_LEVEL_WINDOW);
+
   if (gFirstPaintTimestamp >= gXRE_mainTimestamp)
     MaybeDefineProperty(cx, obj, "firstPaint", gFirstPaintTimestamp);
   else
     Telemetry::Accumulate(Telemetry::STARTUP_MEASUREMENT_ERRORS, INVALID_FIRST_PAINT);
 
   if (gRestoredTimestamp >= gXRE_mainTimestamp)
     MaybeDefineProperty(cx, obj, "sessionRestored", gRestoredTimestamp);
   else
--- a/toolkit/components/telemetry/TelemetryHistograms.h
+++ b/toolkit/components/telemetry/TelemetryHistograms.h
@@ -169,17 +169,17 @@ SQLITE_TIME_PER_FILE(SYNC, "Time spent o
 HISTOGRAM(MOZ_SQLITE_OTHER_READ_B, 1, 32768, 3, LINEAR, "SQLite read() (bytes)")
 HISTOGRAM(MOZ_SQLITE_PLACES_READ_B, 1, 32768, 3, LINEAR, "SQLite read() (bytes)")
 HISTOGRAM(MOZ_SQLITE_COOKIES_READ_B, 1, 32768, 3, LINEAR, "SQLite read() (bytes)")
 HISTOGRAM(MOZ_SQLITE_URLCLASSIFIER_READ_B, 1, 32768, 3, LINEAR, "SQLite read() (bytes)")
 HISTOGRAM(MOZ_SQLITE_PLACES_WRITE_B, 1, 32768, 3, LINEAR, "SQLite write (bytes)")
 HISTOGRAM(MOZ_SQLITE_COOKIES_WRITE_B, 1, 32768, 3, LINEAR, "SQLite write (bytes)")
 HISTOGRAM(MOZ_SQLITE_URLCLASSIFIER_WRITE_B, 1, 32768, 3, LINEAR, "SQLite write (bytes)")
 HISTOGRAM(MOZ_SQLITE_OTHER_WRITE_B, 1, 32768, 3, LINEAR, "SQLite write (bytes)")
-HISTOGRAM(STARTUP_MEASUREMENT_ERRORS, 1, 3, 4, LINEAR, "Flags errors in startup calculation()")
+HISTOGRAM(STARTUP_MEASUREMENT_ERRORS, 1, 4, 5, LINEAR, "Flags errors in startup calculation()")
 HISTOGRAM(NETWORK_DISK_CACHE_OPEN, 1, 10000, 10, EXPONENTIAL, "Time spent opening disk cache (ms)")
 HISTOGRAM(NETWORK_DISK_CACHE_TRASHRENAME, 1, 10000, 10, EXPONENTIAL, "Time spent renaming bad Cache to Cache.Trash (ms)")
 HISTOGRAM(NETWORK_DISK_CACHE_DELETEDIR, 1, 10000, 10, EXPONENTIAL, "Time spent deleting disk cache (ms)")
 
 /**
  * Url-Classifier telemetry
  */
 #ifdef MOZ_URL_CLASSIFIER
--- a/xpfe/appshell/src/nsAppShellService.cpp
+++ b/xpfe/appshell/src/nsAppShellService.cpp
@@ -151,31 +151,36 @@ nsAppShellService::DestroyHiddenWindow()
     mHiddenWindow->Destroy();
 
     mHiddenWindow = nsnull;
   }
 
   return NS_OK;
 }
 
+PRTime gCreateTopLevelWindowTimestamp = 0;
+
 /*
  * Create a new top level window and display the given URL within it...
  */
 NS_IMETHODIMP
 nsAppShellService::CreateTopLevelWindow(nsIXULWindow *aParent,
                                         nsIURI *aUrl, 
                                         PRUint32 aChromeMask,
                                         PRInt32 aInitialWidth,
                                         PRInt32 aInitialHeight,
                                         nsIAppShell* aAppShell,
                                         nsIXULWindow **aResult)
 
 {
   nsresult rv;
 
+  if (!gCreateTopLevelWindowTimestamp)
+    gCreateTopLevelWindowTimestamp = PR_Now();
+
   nsWebShellWindow *newWindow = nsnull;
   rv = JustCreateTopWindow(aParent, aUrl,
                            aChromeMask, aInitialWidth, aInitialHeight,
                            PR_FALSE, aAppShell, &newWindow);  // addrefs
 
   *aResult = newWindow; // transfer ref
 
   if (NS_SUCCEEDED(rv)) {