Esempio n. 1
0
    /** Called by {@link Tracer#stop()} to create a stop event. */
    void endEvent(Tracer t, int silenceThreshold) {
      boolean wasOutstanding = outstandingEvents.remove(t);
      if (!wasOutstanding) {
        if (isOutstandingEventsTruncated) {
          // The events stack overflowed and was truncated, so just log a
          // warning. Otherwise, we get an exception which is extremely
          // confusing.
          logger.log(
              Level.WARNING,
              "event not found, probably because the event stack " + "overflowed and was truncated",
              new Throwable());
        } else {
          // throw an exception if the event was not found and the events stack
          // is pristine
          throw new IllegalStateException();
        }
      }

      long elapsed = t.stopTimeMs - t.startTimeMs;

      if (silenceThreshold == -1) { // use default
        silenceThreshold = defaultSilenceThreshold;
      }

      if (elapsed < silenceThreshold) {
        // If this one is silent then we need to remove the start Event
        boolean removed = false;
        for (int i = 0; i < events.size(); i++) {
          Event e = events.get(i);
          if (e.tracer == t) {
            Preconditions.checkState(e.isStart);
            events.remove(i);
            removed = true;
            break;
          }
        }

        // Only assert if we didn't find the original and the events
        // weren't truncated.
        Preconditions.checkState(removed || isEventsTruncated);
      } else {
        events.add(new Event(false, t));
      }

      if (t.type != null) {
        Stat stat = stats.get(t.type);
        if (stat == null) {
          stat = new Stat();
          if (!extraTracingStatistics.isEmpty()) {
            stat.extraInfo = new int[extraTracingStatistics.size()];
          }
          stats.put(t.type, stat);
        }

        stat.count++;
        if (typeToCountMap != null) {
          typeToCountMap.incrementBy(t.type, 1);
        }

        stat.clockTime += elapsed;
        if (typeToTimeMap != null) {
          typeToTimeMap.incrementBy(t.type, elapsed);
        }

        if (stat.extraInfo != null && t.extraTracingValues != null) {
          int overlapLength = Math.min(stat.extraInfo.length, t.extraTracingValues.length);
          for (int i = 0; i < overlapLength; i++) {
            stat.extraInfo[i] += t.extraTracingValues[i];
            AtomicTracerStatMap map = extraTracingStatistics.get(i).getTracingStat();
            if (map != null) {
              map.incrementBy(t.type, t.extraTracingValues[i]);
            }
          }
        }

        if (elapsed < silenceThreshold) {
          stat.silent++;
          if (typeToSilentMap != null) {
            typeToSilentMap.incrementBy(t.type, 1);
          }
        }
      }
    }
Esempio n. 2
0
 /**
  * Used for exporting this data via varz. Accesses to this map must be synchronized on the map. If
  * enableTypeMaps has not been called, this will return null.
  */
 @Nullable
 static Map<String, Long> getTypeToTimeMap() {
   return typeToTimeMap != null ? typeToTimeMap.getMap() : null;
 }