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;
  
A struct holding the min, max, avg, 95th, and 99th percentile measurements for the collection of values held in a LatencyStat.
 
 public class Latency implements SerializableCloneable {
     private static final long serialVersionUID = 1L;
 
     private static final DecimalFormat FORMAT = 
         new DecimalFormat("###,###,###,###,###,###,###.##");
 
     private int maxTrackedLatencyMillis;
     private int min;
     private int max;
     private float avg;
     private int totalOps;
     private int percent95;
     private int percent99;
 
     /*
      * This field should be called requestsOverflow, but is left opsOverflow
      * for serialization compatibility with JE 5.0.69 and earlier.
      */
     private int opsOverflow;
 
     /*
      * The totalRequests field was added in JE 5.0.70.  When an object
      * serialized by JE 5.0.69 or earler is deserialized here, this field is
      * initialized here to 0 by Java and then set equal to totalOps by
      * readObject.  Setting totalRequests to totalOps is accurate for
      * single-op-per-request stats.  It is inaccurate for
      * multiple-op-per-request stats, but the best we can do with the
      * information we have available.
      */
     private int totalRequests;

    
Creates a Latency with a maxTrackedLatencyMillis and all fields with zero values.
 
     public Latency(int maxTrackedLatencyMillis) {
         this. = maxTrackedLatencyMillis;
     }
 
     public Latency(int maxTrackedLatencyMillis,
                    int minMillis,
                    int maxMillis,
                    float avg,
                    int totalOps,
                    int totalRequests,
                    int percent95,
                    int percent99,
                    int requestsOverflow) {
         this. = maxTrackedLatencyMillis;
         this. = minMillis;
         this. = maxMillis;
         this. = avg;
         this. = totalOps;
         this. = totalRequests;
         this. = percent95;
         this. = percent99;
         this. = requestsOverflow;
     }
 
     /* See totalRequests field. */
     private void readObject(ObjectInputStream in)
         throws IOExceptionClassNotFoundException {
 
         in.defaultReadObject();
 
         if ( == 0) {
              = ;
         }
     }
 
     @Override
     public Latency clone() {
         try {
             return (Latencysuper.clone();
         } catch (CloneNotSupportedException e) {
             /* Should never happen. */
             throw new IllegalStateException(e);
         }
     }
     
     @Override
    public String toString() {
        if ( == 0) {
            return "No operations";
        }
        
        return "maxTrackedLatencyMillis=" + 
               .format() +
               " totalOps=" + .format() + 
               " totalReq=" + .format() + 
               " reqOverflow=" + .format() +
               " min=" + .format() +
               " max=" + .format() +
               " avg=" + .format() +
               " 95%=" + .format() +
               " 99%=" + .format();
    }

    

Returns:
the number of operations recorded by this stat.
    public int getTotalOps() {
        return ;
    }

    

Returns:
the number of requests recorded by this stat.
    public int getTotalRequests() {
        return ;
    }

    

Returns:
the number of requests which exceed the max expected latency
    public int getRequestsOverflow() {
        return ;
    }

    

Returns:
the max expected latency for this kind of operation
    public int getMaxTrackedLatencyMillis() {
        return ;
    }

    

Returns:
the fastest latency tracked
    public int getMin() {
        return ;
    }

    

Returns:
the slowest latency tracked
    public int getMax() {
        return ;
    }

    

Returns:
the average latency tracked
    public float getAvg() {
        return ;
    }

    

Returns:
the 95th percentile latency tracked by the histogram
    public int get95thPercent() {
        return ;
    }

    

Returns:
the 99th percentile latency tracked by the histogram
    public int get99thPercent() {
        return ;
    }

    
Add the measurements from "other" and recalculate the min, max, and average values. The 95th and 99th percentile are not recalculated, because the histogram from LatencyStatis not available, and those values can't be generated.
    public void rollup(Latency other) {
        if (other == null || other.totalOps == 0 || other.totalRequests == 0) {
            throw new IllegalStateException
                ("Can't rollup a Latency that doesn't have any data");
        }
        if ( != other.maxTrackedLatencyMillis) {
            throw new IllegalStateException
                ("Can't rollup a Latency whose maxTrackedLatencyMillis is " +
                 "different");
        }
        if ( > other.min) {
             = other.min;
        }
        if ( < other.max) {
             = other.max;
        }
         = (( * ) + (other.totalRequests * other.avg)) / 
              ( + other.totalRequests);
        /* Clear out 95th and 99th. They have become invalid. */
         = 0;
         = 0;
         += other.totalOps;
         += other.totalRequests;
         += other.opsOverflow;
    }
New to GrepCode? Check out our FAQ X