public synchronized void emit() {
   // TODO: expand to package-level counts in the future.
   AggregatedStats stats = getOrCreateAggregatedStatsLocked(DEVICE_GLOBAL_STATS);
   stats.emit();
   mLastEmitTime = SystemClock.elapsedRealtime();
   mHandler.removeMessages(MSG_EMIT);
   mHandler.sendEmptyMessageDelayed(MSG_EMIT, EMIT_PERIOD);
 }
 /** Called when a notification has been updated. */
 public void registerUpdatedByApp(NotificationRecord notification, NotificationRecord old) {
   notification.stats = old.stats;
   AggregatedStats[] aggregatedStatsArray = getAggregatedStatsLocked(notification);
   for (AggregatedStats stats : aggregatedStatsArray) {
     stats.numUpdatedByApp++;
     stats.countApiUse(notification);
   }
   releaseAggregatedStatsLocked(aggregatedStatsArray);
 }
 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);
   }
 }
  /** Called when a notification has been posted. */
  public synchronized void registerPostedByApp(NotificationRecord notification) {
    notification.stats = new SingleNotificationStats();
    notification.stats.posttimeElapsedMs = SystemClock.elapsedRealtime();

    AggregatedStats[] aggregatedStatsArray = getAggregatedStatsLocked(notification);
    for (AggregatedStats stats : aggregatedStatsArray) {
      stats.numPostedByApp++;
      stats.countApiUse(notification);
    }
    releaseAggregatedStatsLocked(aggregatedStatsArray);
    if (ENABLE_SQLITE_LOG) {
      mSQLiteLog.logPosted(notification);
    }
  }
 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;
 }
    public void emit() {
      if (mPrevious == null) {
        mPrevious = new AggregatedStats(null, key);
      }

      maybeCount("note_post", (numPostedByApp - mPrevious.numPostedByApp));
      maybeCount("note_update", (numUpdatedByApp - mPrevious.numUpdatedByApp));
      maybeCount("note_remove", (numRemovedByApp - mPrevious.numRemovedByApp));
      maybeCount("note_with_people", (numWithValidPeople - mPrevious.numWithValidPeople));
      maybeCount("note_with_stars", (numWithStaredPeople - mPrevious.numWithStaredPeople));
      maybeCount("people_cache_hit", (numPeopleCacheHit - mPrevious.numPeopleCacheHit));
      maybeCount("people_cache_miss", (numPeopleCacheMiss - mPrevious.numPeopleCacheMiss));
      maybeCount("note_blocked", (numBlocked - mPrevious.numBlocked));
      maybeCount("note_with_actions", (numWithActions - mPrevious.numWithActions));
      maybeCount("note_private", (numPrivate - mPrevious.numPrivate));
      maybeCount("note_secret", (numSecret - mPrevious.numSecret));
      maybeCount("note_prio_max", (numPriorityMax - mPrevious.numPriorityMax));
      maybeCount("note_prio_high", (numPriorityHigh - mPrevious.numPriorityHigh));
      maybeCount("note_prio_low", (numPriorityLow - mPrevious.numPriorityLow));
      maybeCount("note_prio_min", (numPriorityMin - mPrevious.numPriorityMin));
      maybeCount("note_interupt", (numInterrupt - mPrevious.numInterrupt));
      maybeCount("note_big_text", (numWithBigText - mPrevious.numWithBigText));
      maybeCount("note_big_pic", (numWithBigPicture - mPrevious.numWithBigPicture));
      maybeCount("note_fg", (numForegroundService - mPrevious.numForegroundService));
      maybeCount("note_ongoing", (numOngoing - mPrevious.numOngoing));
      maybeCount("note_auto", (numAutoCancel - mPrevious.numAutoCancel));
      maybeCount("note_large_icon", (numWithLargeIcon - mPrevious.numWithLargeIcon));
      maybeCount("note_inbox", (numWithInbox - mPrevious.numWithInbox));
      maybeCount("note_media", (numWithMediaSession - mPrevious.numWithMediaSession));
      maybeCount("note_title", (numWithTitle - mPrevious.numWithTitle));
      maybeCount("note_text", (numWithText - mPrevious.numWithText));
      maybeCount("note_sub_text", (numWithSubText - mPrevious.numWithSubText));
      maybeCount("note_info_text", (numWithInfoText - mPrevious.numWithInfoText));

      mPrevious.numPostedByApp = numPostedByApp;
      mPrevious.numUpdatedByApp = numUpdatedByApp;
      mPrevious.numRemovedByApp = numRemovedByApp;
      mPrevious.numPeopleCacheHit = numPeopleCacheHit;
      mPrevious.numPeopleCacheMiss = numPeopleCacheMiss;
      mPrevious.numWithStaredPeople = numWithStaredPeople;
      mPrevious.numWithValidPeople = numWithValidPeople;
      mPrevious.numBlocked = numBlocked;
      mPrevious.numWithActions = numWithActions;
      mPrevious.numPrivate = numPrivate;
      mPrevious.numSecret = numSecret;
      mPrevious.numPriorityMax = numPriorityMax;
      mPrevious.numPriorityHigh = numPriorityHigh;
      mPrevious.numPriorityLow = numPriorityLow;
      mPrevious.numPriorityMin = numPriorityMin;
      mPrevious.numInterrupt = numInterrupt;
      mPrevious.numWithBigText = numWithBigText;
      mPrevious.numWithBigPicture = numWithBigPicture;
      mPrevious.numForegroundService = numForegroundService;
      mPrevious.numOngoing = numOngoing;
      mPrevious.numAutoCancel = numAutoCancel;
      mPrevious.numWithLargeIcon = numWithLargeIcon;
      mPrevious.numWithInbox = numWithInbox;
      mPrevious.numWithMediaSession = numWithMediaSession;
      mPrevious.numWithTitle = numWithTitle;
      mPrevious.numWithText = numWithText;
      mPrevious.numWithSubText = numWithSubText;
      mPrevious.numWithInfoText = numWithInfoText;
    }