public void printPostFrequencies(PrintWriter pw, String indent, DumpFilter filter) {
   SQLiteDatabase db = mHelper.getReadableDatabase();
   long midnight = getMidnightMs();
   String q =
       "SELECT "
           + COL_EVENT_USER_ID
           + ", "
           + COL_PKG
           + ", "
           +
           // Bucket by day by looking at 'floor((midnight - eventTimeMs) / dayMs)'
           "CAST((("
           + midnight
           + " - "
           + COL_EVENT_TIME
           + ") / "
           + DAY_MS
           + ") AS int) "
           + "AS day, "
           + "COUNT(*) AS cnt "
           + "FROM "
           + TAB_LOG
           + " "
           + "WHERE "
           + COL_EVENT_TYPE
           + "="
           + EVENT_TYPE_POST
           + " "
           + "GROUP BY "
           + COL_EVENT_USER_ID
           + ", day, "
           + COL_PKG;
   Cursor cursor = db.rawQuery(q, null);
   try {
     for (cursor.moveToFirst(); !cursor.isAfterLast(); cursor.moveToNext()) {
       int userId = cursor.getInt(0);
       String pkg = cursor.getString(1);
       if (filter != null && !filter.matches(pkg)) continue;
       int day = cursor.getInt(2);
       int count = cursor.getInt(3);
       pw.println(
           indent
               + "post_frequency{user_id="
               + userId
               + ",pkg="
               + pkg
               + ",day="
               + day
               + ",count="
               + count
               + "}");
     }
   } finally {
     cursor.close();
   }
 }
 private JSONArray JsonPostFrequencies(DumpFilter filter) throws JSONException {
   JSONArray frequencies = new JSONArray();
   SQLiteDatabase db = mHelper.getReadableDatabase();
   long midnight = getMidnightMs();
   String q =
       "SELECT "
           + COL_EVENT_USER_ID
           + ", "
           + COL_PKG
           + ", "
           +
           // Bucket by day by looking at 'floor((midnight - eventTimeMs) / dayMs)'
           "CAST((("
           + midnight
           + " - "
           + COL_EVENT_TIME
           + ") / "
           + DAY_MS
           + ") AS int) "
           + "AS day, "
           + "COUNT(*) AS cnt "
           + "FROM "
           + TAB_LOG
           + " "
           + "WHERE "
           + COL_EVENT_TYPE
           + "="
           + EVENT_TYPE_POST
           + " AND "
           + COL_EVENT_TIME
           + " > "
           + filter.since
           + " GROUP BY "
           + COL_EVENT_USER_ID
           + ", day, "
           + COL_PKG;
   Cursor cursor = db.rawQuery(q, null);
   try {
     for (cursor.moveToFirst(); !cursor.isAfterLast(); cursor.moveToNext()) {
       int userId = cursor.getInt(0);
       String pkg = cursor.getString(1);
       if (filter != null && !filter.matches(pkg)) continue;
       int day = cursor.getInt(2);
       int count = cursor.getInt(3);
       JSONObject row = new JSONObject();
       row.put("user_id", userId);
       row.put("package", pkg);
       row.put("day", day);
       row.put("count", count);
       frequencies.put(row);
     }
   } finally {
     cursor.close();
   }
   return frequencies;
 }
 public synchronized void dump(PrintWriter pw, String indent, DumpFilter filter) {
   if (ENABLE_AGGREGATED_IN_MEMORY_STATS) {
     for (AggregatedStats as : mStats.values()) {
       if (filter != null && !filter.matches(as.key)) continue;
       as.dump(pw, indent);
     }
     pw.println(indent + "mStatsArrays.size(): " + mStatsArrays.size());
   }
   if (ENABLE_SQLITE_LOG) {
     mSQLiteLog.dump(pw, indent, filter);
   }
 }
 public synchronized JSONObject dumpJson(DumpFilter filter) {
   JSONObject dump = new JSONObject();
   if (ENABLE_AGGREGATED_IN_MEMORY_STATS) {
     try {
       JSONArray aggregatedStats = new JSONArray();
       for (AggregatedStats as : mStats.values()) {
         if (filter != null && !filter.matches(as.key)) continue;
         aggregatedStats.put(as.dumpJson());
       }
       dump.put("current", aggregatedStats);
     } catch (JSONException e) {
       // pass
     }
   }
   if (ENABLE_SQLITE_LOG) {
     try {
       dump.put("historical", mSQLiteLog.dumpJson(filter));
     } catch (JSONException e) {
       // pass
     }
   }
   return dump;
 }