about:config - implement nsXULAppInfo::GetLaunchTimestamp for linux
authorDaniel Brooks <db48x@db48x.net>
Sat, 31 Jul 2010 09:06:11 -0500
changeset 58819 85dfb7b92d12a28a7a45531303829f33b3dfa8b1
parent 58818 f05783938aa6c8a4524b5d1c55d54a3f073ef87c
child 58820 24a2838d65eb31c2dbf6d9ed1c87b610f9caf679
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:config - implement nsXULAppInfo::GetLaunchTimestamp for linux
browser/base/content/aboutStartup.js
toolkit/xre/nsAppRunner.cpp
--- a/browser/base/content/aboutStartup.js
+++ b/browser/base/content/aboutStartup.js
@@ -1,15 +1,18 @@
 var Cc = Components.classes;
 var Ci = Components.interfaces;
 
-let launched = startup = restored = 0;
+let launched, startup, restored;
 
 let runtime = Cc["@mozilla.org/xre/runtime;1"].getService(Ci.nsIXULRuntime);
+displayTimestamp("launched", launched = runtime.launchTimestamp);
 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);
 
 function displayTimestamp(id, µs)
 {
   document.getElementById(id).textContent = new Date(µs/1000) +" ("+ µs +" µs)";
--- a/toolkit/xre/nsAppRunner.cpp
+++ b/toolkit/xre/nsAppRunner.cpp
@@ -803,17 +803,50 @@ nsXULAppInfo::InvalidateCachesOnRestart(
       return rv;
   }
   return NS_OK;
 }
 
 /* readonly attribute unsigned long launchTimestamp; */
 NS_IMETHODIMP nsXULAppInfo::GetLaunchTimestamp(PRUint64 *aTimestamp)
 {
-    return NS_ERROR_NOT_IMPLEMENTED;
+#ifdef XP_UNIX
+  FILE *uptime;
+  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);
+  pidstat = fopen(statpath, "r");
+  PR_smprintf_free(statpath);
+
+  char stat[512];
+  memset(&stat, 0, 512);
+  int n = fread(&stat, 1, 511, pidstat);
+  if (n <= 0)
+    return NS_ERROR_FAILURE;
+  fclose(pidstat);
+
+  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);
+  return NS_OK;
+#else
+  return NS_ERROR_NOT_IMPLEMENTED;
+#endif
 }
 
 /* readonly attribute unsigned long startupTimestamp; */
 NS_IMETHODIMP nsXULAppInfo::GetStartupTimestamp(PRUint64 *aTimestamp)
 {
   *aTimestamp = gAppData->startupTimestamp;
   return NS_OK;
 }