Created
January 9, 2015 17:34
-
-
Save kkarad/89625808193a5eed3f20 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package org.kkarad.metrics; | |
import org.HdrHistogram.Histogram; | |
import gnu.trove.map.hash.TObjectLongHashMap; | |
public class Metrics { | |
private static final Histogram histogram = new Histogram(3600000000000L, 3); | |
private static TObjectLongHashMap<String> map = new TObjectLongHashMap<String>(1000, 0.5f, -1); | |
private Metrics() { | |
} | |
public static void in(String id) { | |
long now = System.nanoTime(); | |
map.put(id, now); | |
} | |
public static void out(String id) { | |
long now = System.nanoTime(); | |
final long start = map.remove(id); | |
if(start != -1) { | |
histogram.recordValue(now - start); | |
} | |
} | |
public static void printAndReset() { | |
System.out.println("Recoded latencies (in usec) for pricing:"); | |
histogram.outputPercentileDistribution(System.out, 100.0); | |
histogram.reset(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment