Skip to content

Instantly share code, notes, and snippets.

@kkarad
Created January 9, 2015 17:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kkarad/89625808193a5eed3f20 to your computer and use it in GitHub Desktop.
Save kkarad/89625808193a5eed3f20 to your computer and use it in GitHub Desktop.
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