Bug 764021 - Add Startup Timeline probe for when entering main(). r=taras,r=bsmedberg
authorMike Hommey <mh+mozilla@glandium.org>
Fri, 15 Jun 2012 08:23:08 +0200
changeset 96802 c1c12246f5acb5e11f4439f07202b1a85f906c3d
parent 96801 da76a072b2b0fcaefbf5f50540209f6df557a1ff
child 96803 a81526647059621e4a5a3f7e0d047dda4eac5cae
push id10717
push useremorley@mozilla.com
push dateFri, 15 Jun 2012 13:04:50 +0000
treeherdermozilla-inbound@d4fc8a49540c [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerstaras, bsmedberg
bugs764021
milestone16.0a1
first release with
nightly linux32
c1c12246f5ac / 16.0a1 / 20120615030531 / files
nightly linux64
c1c12246f5ac / 16.0a1 / 20120615030531 / files
nightly mac
c1c12246f5ac / 16.0a1 / 20120615030531 / files
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
releases
nightly linux32
nightly linux64
nightly mac
Bug 764021 - Add Startup Timeline probe for when entering main(). r=taras,r=bsmedberg
browser/app/nsBrowserApp.cpp
toolkit/components/startup/StartupTimeline.cpp
toolkit/components/startup/StartupTimeline.h
xpcom/build/nsXULAppAPI.h
--- a/browser/app/nsBrowserApp.cpp
+++ b/browser/app/nsBrowserApp.cpp
@@ -85,26 +85,28 @@ public:
 
 XRE_GetFileFromPathType XRE_GetFileFromPath;
 XRE_CreateAppDataType XRE_CreateAppData;
 XRE_FreeAppDataType XRE_FreeAppData;
 #ifdef XRE_HAS_DLL_BLOCKLIST
 XRE_SetupDllBlocklistType XRE_SetupDllBlocklist;
 #endif
 XRE_TelemetryAccumulateType XRE_TelemetryAccumulate;
+XRE_StartupTimelineRecordType XRE_StartupTimelineRecord;
 XRE_mainType XRE_main;
 
 static const nsDynamicFunctionLoad kXULFuncs[] = {
     { "XRE_GetFileFromPath", (NSFuncPtr*) &XRE_GetFileFromPath },
     { "XRE_CreateAppData", (NSFuncPtr*) &XRE_CreateAppData },
     { "XRE_FreeAppData", (NSFuncPtr*) &XRE_FreeAppData },
 #ifdef XRE_HAS_DLL_BLOCKLIST
     { "XRE_SetupDllBlocklist", (NSFuncPtr*) &XRE_SetupDllBlocklist },
 #endif
     { "XRE_TelemetryAccumulate", (NSFuncPtr*) &XRE_TelemetryAccumulate },
+    { "XRE_StartupTimelineRecord", (NSFuncPtr*) &XRE_StartupTimelineRecord },
     { "XRE_main", (NSFuncPtr*) &XRE_main },
     { nsnull, nsnull }
 };
 
 static int do_main(int argc, char* argv[])
 {
   nsCOMPtr<nsIFile> appini;
   nsresult rv;
@@ -184,18 +186,41 @@ bool IsPrefetchDisabledViaService()
   RegQueryValueExW(baseKey, L"FFPrefetchDisabled", 0, NULL,
                    reinterpret_cast<LPBYTE>(&disabledValue),
                    &disabledValueSize);
   RegCloseKey(baseKey);
   return disabledValue == 1;
 }
 #endif
 
+/* Local implementation of PR_Now, since the executable can't depend on NSPR */
+static PRTime _PR_Now()
+{
+#ifdef XP_WIN
+  MOZ_STATIC_ASSERT(sizeof(PRTime) == sizeof(FILETIME), "PRTime must have the same size as FILETIME");
+  FILETIME ft;
+  GetSystemTimeAsFileTime(&ft);
+  PRTime now;
+  CopyMemory(&now, &ft, sizeof(PRTime));
+#ifdef __GNUC__
+  return (now - 116444736000000000LL) / 10LL;
+#else
+  return (now - 116444736000000000i64) / 10i64;
+#endif
+
+#else
+  struct timeval tm;
+  gettimeofday(&tm, 0);
+  return (((PRTime)tm.tv_sec * 1000000LL) + (PRTime)tm.tv_usec);
+#endif
+}
+
 int main(int argc, char* argv[])
 {
+  PRTime start = _PR_Now();
   char exePath[MAXPATHLEN];
 
 #ifdef XP_MACOSX
   TriggerQuirks();
 #endif
 
   nsresult rv = mozilla::BinaryPath::Get(argv[0], exePath);
   if (NS_FAILED(rv)) {
@@ -242,16 +267,18 @@ int main(int argc, char* argv[])
   *lastSlash = 0;
 
   rv = XPCOMGlueLoadXULFunctions(kXULFuncs);
   if (NS_FAILED(rv)) {
     Output("Couldn't load XRE functions.\n");
     return 255;
   }
 
+  XRE_StartupTimelineRecord(mozilla::StartupTimeline::START, start);
+
 #ifdef XRE_HAS_DLL_BLOCKLIST
   XRE_SetupDllBlocklist();
 #endif
 
 #if defined(XP_WIN)
   XRE_TelemetryAccumulate(mozilla::Telemetry::STARTUP_USING_PRELOAD,
                           preloadReason);
 #endif
--- a/toolkit/components/startup/StartupTimeline.cpp
+++ b/toolkit/components/startup/StartupTimeline.cpp
@@ -1,16 +1,28 @@
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #include "StartupTimeline.h"
+#include "nsXULAppAPI.h"
 
 namespace mozilla {
 
 PRTime StartupTimeline::sStartupTimeline[StartupTimeline::MAX_EVENT_ID];
 const char *StartupTimeline::sStartupTimelineDesc[StartupTimeline::MAX_EVENT_ID] = {
 #define mozilla_StartupTimeline_Event(ev, desc) desc,
 #include "StartupTimeline.h"
 #undef mozilla_StartupTimeline_Event
 };
 
+} /* namespace mozilla */
+
+/**
+ * The XRE_StartupTimeline_Record function is to be used by embedding applications
+ * that can't use mozilla::StartupTimeline::Record() directly.
+ */
+void
+XRE_StartupTimelineRecord(int aEvent, PRTime aWhen)
+{
+  mozilla::StartupTimeline::Record((mozilla::StartupTimeline::Event) aEvent, aWhen);
 }
+
--- a/toolkit/components/startup/StartupTimeline.h
+++ b/toolkit/components/startup/StartupTimeline.h
@@ -1,14 +1,15 @@
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #ifdef mozilla_StartupTimeline_Event
 mozilla_StartupTimeline_Event(PROCESS_CREATION, "process")
+mozilla_StartupTimeline_Event(START, "start")
 mozilla_StartupTimeline_Event(MAIN, "main")
 // Record the beginning and end of startup crash detection to compare with crash stats to know whether
 // detection should be improved to start or end sooner.
 mozilla_StartupTimeline_Event(STARTUP_CRASH_DETECTION_BEGIN, "startupCrashDetectionBegin")
 mozilla_StartupTimeline_Event(STARTUP_CRASH_DETECTION_END, "startupCrashDetectionEnd")
 mozilla_StartupTimeline_Event(FIRST_PAINT, "firstPaint")
 mozilla_StartupTimeline_Event(SESSION_RESTORED, "sessionRestored")
 mozilla_StartupTimeline_Event(CREATE_TOP_LEVEL_WINDOW, "createTopLevelWindow")
--- a/xpcom/build/nsXULAppAPI.h
+++ b/xpcom/build/nsXULAppAPI.h
@@ -435,16 +435,19 @@ XRE_API(void,
 XRE_API(void,
         XRE_SetupDllBlocklist, ())
 #endif
 
 XRE_API(void,
         XRE_TelemetryAccumulate, (int aID, PRUint32 aSample))
 
 XRE_API(void,
+        XRE_StartupTimelineRecord, (int aEvent, PRTime aWhen))
+
+XRE_API(void,
         XRE_InitOmnijar, (nsIFile* greOmni,
                           nsIFile* appOmni))
 
 #ifdef XP_WIN
 /**
  * Valid environment types for XRE_GetWindowsEnvironment.
  */
 enum WindowsEnvironmentType {