OSDN Git Service

Logging page load time
authorKristian Monsen <kristianm@google.com>
Tue, 2 Feb 2010 13:37:09 +0000 (13:37 +0000)
committerKristian Monsen <kristianm@google.com>
Tue, 2 Feb 2010 13:37:09 +0000 (13:37 +0000)
Added a log message when a page is loaded. It will handle redirects as a new page load.

src/com/android/browser/LogTag.java
src/com/android/browser/Tab.java

index 2be3134..38fea47 100644 (file)
@@ -16,7 +16,6 @@
 
 package com.android.browser;
 
-import android.util.Log;
 import android.util.EventLog;
 
 public class LogTag {
@@ -36,11 +35,14 @@ public class LogTag {
      * Log when a page has finished loading with how much
      * time the browser used to load the page.
      *
+     * Note that a redirect will restart the timer, so this time is not
+     * always how long it takes for the user to load a page.
+     *
      * @param url the url of that page that finished loading.
      * @param duration the time the browser spent loading the page.
      */
     public static void logPageFinishedLoading(String url, long duration) {
-        EventLog.writeEvent(EventLogTags.BROWSER_BOOKMARK_ADDED, url + "|"
+        EventLog.writeEvent(EventLogTags.BROWSER_PAGE_LOADED, url + "|"
             + duration);
     }
 
@@ -51,7 +53,7 @@ public class LogTag {
      * @param duration the time spent on the webpage.
      */
     public static void logTimeOnPage(String url, long duration) {
-        EventLog.writeEvent(EventLogTags.BROWSER_BOOKMARK_ADDED, url + "|"
+        EventLog.writeEvent(EventLogTags.BROWSER_TIMEONPAGE, url + "|"
             + duration);
     }
 }
index 5db4848..c939a13 100644 (file)
@@ -37,6 +37,7 @@ import android.net.http.SslError;
 import android.os.AsyncTask;
 import android.os.Bundle;
 import android.os.Message;
+import android.os.SystemClock;
 import android.provider.Browser;
 import android.speech.RecognizerResultsIntent;
 import android.util.Log;
@@ -97,6 +98,8 @@ class Tab {
     private boolean mInForeground;
     // If true, the tab is in loading state.
     private boolean mInLoad;
+    // The time the load started, used to find load page time
+    private long mLoadStartTime;
     // Application identifier used to find tabs that another application wants
     // to reuse.
     private String mAppId;
@@ -317,6 +320,7 @@ class Tab {
         @Override
         public void onPageStarted(WebView view, String url, Bitmap favicon) {
             mInLoad = true;
+            mLoadStartTime = SystemClock.uptimeMillis();
             if (mVoiceSearchData != null
                     && !url.equals(mVoiceSearchData.mLastVoiceSearchUrl)) {
                 mVoiceSearchData = null;
@@ -370,6 +374,8 @@ class Tab {
 
         @Override
         public void onPageFinished(WebView view, String url) {
+            LogTag.logPageFinishedLoading(
+                    url, SystemClock.uptimeMillis() - mLoadStartTime);
             mInLoad = false;
 
             if (mInForeground && !mActivity.didUserStopLoading()