about:startup - open the correct file, error check the fopen, use try/catch to check for failure in the js
authorDaniel Brooks <db48x@db48x.net>
Sun, 01 Aug 2010 04:47:42 -0500
changeset 58820 24a2838d65eb31c2dbf6d9ed1c87b610f9caf679
parent 58819 85dfb7b92d12a28a7a45531303829f33b3dfa8b1
child 58821 c286d24e60a48fbb9a42ceacff3ddaab571452de
push id17440
push userdb48x@yahoo.com
push dateWed, 08 Dec 2010 04:15:54 +0000
treeherdermozilla-central@a89f24bf1798 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
milestone2.0b3pre
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
about:startup - open the correct file, error check the fopen, use try/catch to check for failure in the js
browser/base/content/aboutStartup.js
toolkit/xre/nsAppRunner.cpp
--- a/browser/base/content/aboutStartup.js
+++ b/browser/base/content/aboutStartup.js
@@ -1,15 +1,19 @@
 var Cc = Components.classes;
 var Ci = Components.interfaces;
 
 let launched, startup, restored;
 
 let runtime = Cc["@mozilla.org/xre/runtime;1"].getService(Ci.nsIXULRuntime);
-displayTimestamp("launched", launched = runtime.launchTimestamp);
+
+try {
+  displayTimestamp("launched", launched = runtime.launchTimestamp);
+} catch(x) { }
+
 displayTimestamp("started", startup = runtime.startupTimestamp);
 if (launched)
   displayDuration("started", startup - launched);
 
 let ss = Cc["@mozilla.org/browser/sessionstartup;1"].getService(Ci.nsISessionStartup);
 displayTimestamp("restored", restored = ss.restoredTimestamp);
 displayDuration("restored", restored - startup);
 
--- a/toolkit/xre/nsAppRunner.cpp
+++ b/toolkit/xre/nsAppRunner.cpp
@@ -805,44 +805,46 @@ nsXULAppInfo::InvalidateCachesOnRestart(
   return NS_OK;
 }
 
 /* readonly attribute unsigned long launchTimestamp; */
 NS_IMETHODIMP nsXULAppInfo::GetLaunchTimestamp(PRUint64 *aTimestamp)
 {
 #ifdef XP_UNIX
   FILE *uptime;
+  long tickspersecond = sysconf(_SC_CLK_TCK);
   unsigned long long sec, ssec;
 
   uptime = fopen("/proc/uptime", "r");
   fscanf(uptime, "%lld.%lld", &sec, &ssec);
   PRTime boottime = PR_Now() - (((sec * PR_MSEC_PER_SEC) + (ssec * 10)) * PR_USEC_PER_MSEC);
   fclose(uptime);
 
   FILE *pidstat;
   pid_t pid = getpid();
-  char *statpath = PR_smprintf("/proc/%d/uptime", pid);
+  char *statpath = PR_smprintf("/proc/%d/stat", pid);
   pidstat = fopen(statpath, "r");
-  PR_smprintf_free(statpath);
+  if (!pidstat)
+    return NS_ERROR_FAILURE;
 
   char stat[512];
   memset(&stat, 0, 512);
   int n = fread(&stat, 1, 511, pidstat);
   if (n <= 0)
     return NS_ERROR_FAILURE;
   fclose(pidstat);
+  PR_smprintf_free(statpath);
 
   PRTime starttime = 0;
   sscanf(strrchr(stat, ')') + 2,
          "%*c %*d %*d %*d %*d %*d %*u %*u %*u %*u "
          "%*u %*u %*u %*u %*u %*d %*d %*d %*d %llu",
          &starttime);
 
-  printf("%llu, %llu\n", boottime, starttime * PR_USEC_PER_SEC);
-  *aTimestamp = boottime + (starttime * PR_USEC_PER_SEC);
+  *aTimestamp = boottime + ((starttime / tickspersecond) * PR_USEC_PER_SEC);
   return NS_OK;
 #else
   return NS_ERROR_NOT_IMPLEMENTED;
 #endif
 }
 
 /* readonly attribute unsigned long startupTimestamp; */
 NS_IMETHODIMP nsXULAppInfo::GetStartupTimestamp(PRUint64 *aTimestamp)