Example #1
0
  /**
   * Notifies the request queue that this request has finished (successfully or with error).
   *
   * <p>Also dumps all events from this request's event log; for debugging.
   */
  void finish(final String tag) {
    if (mRequestQueue != null) {
      mRequestQueue.finish(this);
    }
    if (MarkerLog.ENABLED) {
      final long threadId = Thread.currentThread().getId();
      if (Looper.myLooper() != Looper.getMainLooper()) {
        // If we finish marking off of the main thread, we need to
        // actually do it on the main thread to ensure correct ordering.
        Handler mainThread = new Handler(Looper.getMainLooper());
        mainThread.post(
            new Runnable() {
              @Override
              public void run() {
                mEventLog.add(tag, threadId);
                mEventLog.finish(this.toString());
              }
            });
        return;
      }

      mEventLog.add(tag, threadId);
      mEventLog.finish(this.toString());
    } else {
      long requestTime = SystemClock.elapsedRealtime() - mRequestBirthTime;
      if (requestTime >= SLOW_REQUEST_THRESHOLD_MS) {
        LogUtil.d("%d ms: %s", requestTime, this.toString());
      }
    }
  }
Example #2
0
 /** Adds an event to this request's event log; for debugging. */
 public void addMarker(String tag) {
   if (MarkerLog.ENABLED) {
     mEventLog.add(tag, Thread.currentThread().getId());
   } else if (mRequestBirthTime == 0) {
     mRequestBirthTime = SystemClock.elapsedRealtime();
   }
 }