Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*-
   * See the file LICENSE for redistribution information.
   *
   * Copyright (c) 2002, 2013 Oracle and/or its affiliates.  All rights reserved.
   *
   */
  
  package com.sleepycat.utilint;
  
 import java.util.Map;
Maintain interval and cumulative stats for a given set of operations, as well as a activityCounter that generates thread dumps if operations take too long. The markStart and markFinish methods can be used to bracket each tracked operation.
 
 public class StatsTracker<T> {
 
     /* Latency stats. */
     private final Map<T, LatencyStatintervalLatencies;
     private final Map<T, LatencyStatcumulativeLatencies;
 
     /*
      * ActivityCounter tracks throughput and dumps thread stacktraces when
      * throughput drops.
      */
     private final ActivityCounter activityCounter;

    
The logger is used for activity stack traces.
 
     public StatsTracker(T[] opTypes,
                         Logger stackTraceLogger,
                         int activeThreadThreshold,
                         long threadDumpIntervalMillis,
                         int threadDumpMax,
                         int maxTrackedLatencyMillis) {
 
         this. = new HashMap<T, LatencyStat>();
         this. = new HashMap<T, LatencyStat>();
 
         for (T opType : opTypes) {
             .put
                 (opTypenew LatencyStat(maxTrackedLatencyMillis));
             .put
                 (opTypenew LatencyStat(maxTrackedLatencyMillis));
         }
 
          = new ActivityCounter(activeThreadThreshold,
                                               threadDumpIntervalMillis,
                                               threadDumpMax
                                               stackTraceLogger);
     }

    
Track the start of a operation.

Returns:
the value of System.nanoTime, for passing to markFinish.
 
     public long markStart() {
         .start();
         return System.nanoTime();
     }

    
Track the end of an operation.

Parameters:
startTime should be the value returned by the corresponding call to markStart
 
     public void markFinish(T opTypelong startTime) {
         markFinish(opTypestartTime, 1);
     }
    
Track the end of an operation.

Parameters:
startTime should be the value returned by the corresponding call to markStart
 
     public void markFinish(T opTypelong startTimeint numOperations) {
         try {
             if (numOperations == 0) {
                 return;
             }
 
             if (opType != null) {
                 long elapsed = System.nanoTime() - startTime;
                 .get(opType).set(numOperationselapsed);
                 .get(opType).set(numOperationselapsed);
             }
         } finally {
             /* Must be invoked to clear the ActivityCounter stats. */
             .finish();
         }
     }

    
Should be called after each interval latency stat collection, to reset for the next period's collection.
    public void clearLatency() {
        for (Map.Entry<T, LatencyState : .entrySet()) {
            e.getValue().clear();
        }
    }
    public Map<T, LatencyStatgetIntervalLatency() {
        return ;
    }
    public Map<T, LatencyStatgetCumulativeLatency() {
        return ;
    }

    
For unit test support.
    public int getNumCompletedDumps() {
        return .getNumCompletedDumps();
    }
New to GrepCode? Check out our FAQ X