Bug 632526 - Report startup time correctly; r=mwu a=blocking-fennec-b5+
authorTaras Glek <tglek@mozilla.com>
Wed, 09 Feb 2011 14:58:17 -0500
changeset 62249 000682b4204a61fd6599c1d450c0f2c4a41e250d
parent 62248 e71960b6957c068088d74ee3cd0f5e16a38f6eb3
child 62250 e79e4e9768e6a9650ff6e88be1fd37675513844f
push idunknown
push userunknown
push dateunknown
reviewersmwu, blocking-fennec-b5
bugs632526
milestone2.0b12pre
Bug 632526 - Report startup time correctly; r=mwu a=blocking-fennec-b5+
embedding/android/GeckoApp.java
embedding/android/GeckoConnectivityReceiver.java
toolkit/components/startup/src/nsAppStartup.cpp
--- a/embedding/android/GeckoApp.java
+++ b/embedding/android/GeckoApp.java
@@ -64,16 +64,17 @@ abstract public class GeckoApp
 {
     public static final String ACTION_ALERT_CLICK = "org.mozilla.gecko.ACTION_ALERT_CLICK";
     public static final String ACTION_ALERT_CLEAR = "org.mozilla.gecko.ACTION_ALERT_CLEAR";
 
     public static FrameLayout mainLayout;
     public static GeckoSurfaceView surfaceView;
     public static GeckoApp mAppContext;
     public static boolean mFullscreen = false;
+    public static boolean mStartedEarly = false;
     public static File sGREDir = null;
     static Thread mLibLoadThread = null;
 
     enum LaunchState {PreLaunch, Launching, WaitButton,
                       Launched, GeckoRunning, GeckoExiting};
     private static LaunchState sLaunchState = LaunchState.PreLaunch;
 
     
@@ -121,16 +122,17 @@ abstract public class GeckoApp
         if (!checkAndSetLaunchState(LaunchState.Launching, LaunchState.Launched))
             return false;
 
         if (intent == null)
             intent = getIntent();
         final Intent i = intent;
         new Thread() { 
             public void run() {
+                long startup_time = System.currentTimeMillis();
                 try {
                     if (mLibLoadThread != null)
                         mLibLoadThread.join();
                 } catch (InterruptedException ie) {}
                 surfaceView.mSplashStatusMsg = 
                     getResources().getString(R.string.splash_screen_label);
                 surfaceView.drawSplashScreen();
                 // unpack files in the components directory
@@ -151,16 +153,19 @@ abstract public class GeckoApp
                     else
                         showErrorDialog(getString(R.string.error_loading_file));
                     Looper.loop();
                     return;
                 }
         
                 // and then fire us up
                 String env = i.getStringExtra("env0");
+                if (GeckoApp.mStartedEarly) {
+                    GeckoAppShell.putenv("MOZ_APP_RESTART=" + startup_time);
+                }
                 GeckoAppShell.runGecko(getApplication().getPackageResourcePath(),
                                        i.getStringExtra("args"),
                                        i.getDataString());
             }
         }.start();
         return true;
     }
 
--- a/embedding/android/GeckoConnectivityReceiver.java
+++ b/embedding/android/GeckoConnectivityReceiver.java
@@ -53,10 +53,12 @@ public class GeckoConnectivityReceiver
             status = "unknown";
         else if (!info.isConnected())
             status = "down";
         else
             status = "up";
 
         if (GeckoApp.checkLaunchState(GeckoApp.LaunchState.GeckoRunning))
             GeckoAppShell.onChangeNetworkLinkStatus(status);
+        else
+            GeckoApp.mStartedEarly = true;
     }
 }
--- a/toolkit/components/startup/src/nsAppStartup.cpp
+++ b/toolkit/components/startup/src/nsAppStartup.cpp
@@ -293,17 +293,17 @@ nsAppStartup::Quit(PRUint32 aMode)
     mShuttingDown = PR_TRUE;
     if (!mRestart) {
       mRestart = (aMode & eRestart) != 0;
       gRestartMode = (aMode & 0xF0);
     }
 
     if (mRestart) {
       // Firefox-restarts reuse the process. Process start-time isn't a useful indicator of startup time
-      PR_SetEnv(PR_smprintf("MOZ_APP_RESTART=%lld", (PRInt64) PR_Now()));
+      PR_SetEnv(PR_smprintf("MOZ_APP_RESTART=%lld", (PRInt64) PR_Now() / PR_USEC_PER_MSEC));
     }
 
     obsService = mozilla::services::GetObserverService();
 
     if (!mAttemptingQuit) {
       mAttemptingQuit = PR_TRUE;
 #ifdef XP_MACOSX
       // now even the Mac wants to quit when the last window is closed
@@ -690,17 +690,17 @@ nsAppStartup::GetStartupInfo()
   NS_ENSURE_SUCCESS(rv, rv);
 
   JSObject *obj = JS_NewObject(cx, NULL, NULL, NULL);
   *retvalPtr = OBJECT_TO_JSVAL(obj);
   ncc->SetReturnValueWasSet(PR_TRUE);
 
   char *moz_app_restart = PR_GetEnv("MOZ_APP_RESTART");
   if (moz_app_restart) {
-    gProcessCreationTimestamp = nsCRT::atoll(moz_app_restart);
+    gProcessCreationTimestamp = nsCRT::atoll(moz_app_restart) * PR_USEC_PER_MSEC;
   } else if (!gProcessCreationTimestamp) {
     gProcessCreationTimestamp = CalculateProcessCreationTimestamp();
   }
 
   MaybeDefineProperty(cx, obj, "process", gProcessCreationTimestamp);
 #ifdef MOZ_ENABLE_LIBXUL
   MaybeDefineProperty(cx, obj, "main", gXRE_mainTimestamp);
   MaybeDefineProperty(cx, obj, "firstPaint", gFirstPaintTimestamp);