Bug 741042 - Add telemetry support for timing XUL profile import. r=blassey
authorGian-Carlo Pascutto <gpascutto@mozilla.com>
Thu, 12 Apr 2012 23:19:57 +0200
changeset 94876 89e69819fa98621f398f8af831f0a6275cd01bb6
parent 94875 845bd13a5ebec41086571fcae956ec8e04203232
child 94877 d5bc0234936939b5284b61e931875b89d56c0545
push id886
push userlsblakk@mozilla.com
push dateMon, 04 Jun 2012 19:57:52 +0000
treeherdermozilla-beta@bbd8d5efd6d1 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersblassey
bugs741042
milestone14.0a1
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
Bug 741042 - Add telemetry support for timing XUL profile import. r=blassey
mobile/android/base/ProfileMigrator.java
toolkit/components/telemetry/TelemetryHistograms.h
--- a/mobile/android/base/ProfileMigrator.java
+++ b/mobile/android/base/ProfileMigrator.java
@@ -152,16 +152,22 @@ public class ProfileMigrator {
     private final String kFaviconUrl       = "f_url";
     private final String kFaviconGuid      = "f_guid";
 
     // Helper constants
     private static final int kPlacesTypeBookmark = 1;
     private static final int kPlacesTypeFolder   = 2;
 
     /*
+      For statistics keeping.
+    */
+    private final String kHistoryCountQuery =
+        "SELECT COUNT(*) FROM moz_historyvisits";
+
+    /*
       The sort criterion here corresponds to the one used for the
       Awesomebar results. It's a simplification of Frecency.
       We must divide date by 1000 due to the micro (Places)
       vs milli (Android) distiction.
     */
     private final String kHistoryQuery =
         "SELECT places.url              AS p_url, "       +
         "       places.title            AS p_title, "     +
@@ -195,17 +201,26 @@ public class ProfileMigrator {
 
     public ProfileMigrator(Context context, File profileDir) {
         mProfileDir = profileDir;
         mContext = context;
         mCr = mContext.getContentResolver();
     }
 
     public void launch() {
+        boolean timeThisRun = false;
+        Telemetry.Timer timer = null;
+        // First run, time things
+        if (!hasMigrationRun()) {
+            timeThisRun = true;
+            timer = new Telemetry.Timer("BROWSERPROVIDER_XUL_IMPORT_TIME");
+        }
         launch(DEFAULT_HISTORY_MIGRATE_COUNT);
+        if (timeThisRun)
+            timer.stop();
     }
 
     public void launch(int maxEntries) {
         new PlacesRunnable(maxEntries).run();
     }
 
     public boolean areBookmarksMigrated() {
         return getPreferences().getBoolean(PREFS_MIGRATE_BOOKMARKS_DONE, false);
@@ -476,25 +491,31 @@ public class ProfileMigrator {
 
         protected void doMigrateHistoryBatch(SQLiteBridge db,
                                              int maxEntries, int currentEntries) {
             final ArrayList<String> placesHistory = new ArrayList<String>();
             mOperations = new ArrayList<ContentProviderOperation>();
             int queryResultEntries = 0;
 
             try {
+                Cursor cursor = db.rawQuery(kHistoryCountQuery, null);
+                cursor.moveToFirst();
+                int historyCount = cursor.getInt(0);
+                Telemetry.HistogramAdd("BROWSERPROVIDER_XUL_IMPORT_HISTORY",
+                                       historyCount);
+
                 final String currentTime = Long.toString(System.currentTimeMillis());
                 final String[] queryParams = new String[] {
                     /* current time */
                     currentTime,
                     currentTime,
                     Integer.toString(maxEntries),
                     Integer.toString(currentEntries)
                 };
-                Cursor cursor = db.rawQuery(kHistoryQuery, queryParams);
+                cursor = db.rawQuery(kHistoryQuery, queryParams);
                 queryResultEntries = cursor.getCount();
 
                 final int urlCol = cursor.getColumnIndex(kHistoryUrl);
                 final int titleCol = cursor.getColumnIndex(kHistoryTitle);
                 final int dateCol = cursor.getColumnIndex(kHistoryDate);
                 final int visitsCol = cursor.getColumnIndex(kHistoryVisits);
                 final int faviconMimeCol = cursor.getColumnIndex(kFaviconMime);
                 final int faviconDataCol = cursor.getColumnIndex(kFaviconData);
@@ -652,16 +673,21 @@ public class ProfileMigrator {
                 final int addedCol = cursor.getColumnIndex(kBookmarkAdded);
                 final int modifiedCol = cursor.getColumnIndex(kBookmarkModified);
                 final int positionCol = cursor.getColumnIndex(kBookmarkPosition);
                 final int faviconMimeCol = cursor.getColumnIndex(kFaviconMime);
                 final int faviconDataCol = cursor.getColumnIndex(kFaviconData);
                 final int faviconUrlCol = cursor.getColumnIndex(kFaviconUrl);
                 final int faviconGuidCol = cursor.getColumnIndex(kFaviconGuid);
 
+                // Keep statistics
+                int bookmarkCount = cursor.getCount();
+                Telemetry.HistogramAdd("BROWSERPROVIDER_XUL_IMPORT_BOOKMARKS",
+                                       bookmarkCount);
+
                 // The keys are places IDs.
                 Set<Long> openFolders = new HashSet<Long>();
                 Set<Long> knownFolders = new HashSet<Long>(mRerootMap.keySet());
 
                 // We iterate over all bookmarks, and add all bookmarks that
                 // have their parent folders present. If there are bookmarks
                 // that we can't add, we remember what these are and try again
                 // on the next iteration. The number of iterations scales
--- a/toolkit/components/telemetry/TelemetryHistograms.h
+++ b/toolkit/components/telemetry/TelemetryHistograms.h
@@ -429,11 +429,20 @@ HISTOGRAM(TOTAL_COUNT_LOW_ERRORS, 1, 300
 HISTOGRAM_FLAG(TELEMETRY_TEST_FLAG, "a testing histogram; not meant to be touched")
 
 /**
  * Startup Crash Detection
  */
 HISTOGRAM_FLAG(STARTUP_CRASH_DETECTED, "Whether there was a crash during the last startup")
 HISTOGRAM_ENUMERATED_VALUES(SAFE_MODE_USAGE, 3, "Whether the user is in safe mode (No, Yes, Forced)")
 
+/**
+ * Native Fennec Telemetry
+ */
+#if defined(ANDROID)
+HISTOGRAM(BROWSERPROVIDER_XUL_IMPORT_TIME, 20, 600000, 20, EXPONENTIAL, "Time for the initial conversion of a XUL places database (ms)")
+HISTOGRAM(BROWSERPROVIDER_XUL_IMPORT_BOOKMARKS, 1, 50000, 20, EXPONENTIAL, "Time for the initial conversion of a XUL places database (ms)")
+HISTOGRAM(BROWSERPROVIDER_XUL_IMPORT_HISTORY, 1, 1000000, 20, EXPONENTIAL, "Time for the initial conversion of a XUL places database (ms)")
+#endif
+
 #undef HISTOGRAM_ENUMERATED_VALUES
 #undef HISTOGRAM_BOOLEAN
 #undef HISTOGRAM_FLAG