Skip to content
Snippets Groups Projects
Commit 2d1cb531 authored by Connor McCoy's avatar Connor McCoy
Browse files

Merge pull request #442 from kruthar/kruthar/configurable-percentiles

[core] added configurable percentile values
parents ec08fdd6 39357c4d
No related branches found
No related tags found
No related merge requests found
......@@ -23,8 +23,7 @@ import java.io.FileOutputStream;
import java.io.IOException;
import java.io.PrintStream;
import java.text.DecimalFormat;
import java.util.Map;
import java.util.Properties;
import java.util.*;
import java.util.concurrent.atomic.AtomicInteger;
import org.HdrHistogram.Histogram;
......@@ -49,8 +48,21 @@ public class OneMeasurementHdrHistogram extends OneMeasurement {
final Recorder histogram;
Histogram totalHistogram;
/**
* The name of the property for deciding what percentile values to output.
*/
public static final String PERCENTILES_PROPERTY = "hdrhistogram.percentiles";
/**
* The default value for the hdrhistogram.percentiles property.
*/
public static final String PERCENTILES_PROPERTY_DEFAULT = "95,99";
List<Integer> percentiles;
public OneMeasurementHdrHistogram(String name, Properties props) {
super(name);
percentiles = getPercentileValues(props.getProperty(PERCENTILES_PROPERTY, PERCENTILES_PROPERTY_DEFAULT));
boolean shouldLog = Boolean.parseBoolean(props.getProperty("hdrhistogram.fileoutput", "false"));
if (!shouldLog) {
log = null;
......@@ -101,8 +113,10 @@ public class OneMeasurementHdrHistogram extends OneMeasurement {
exporter.write(getName(), "AverageLatency(us)", totalHistogram.getMean());
exporter.write(getName(), "MinLatency(us)", totalHistogram.getMinValue());
exporter.write(getName(), "MaxLatency(us)", totalHistogram.getMaxValue());
exporter.write(getName(), "95thPercentileLatency(us)", totalHistogram.getValueAtPercentile(95));
exporter.write(getName(), "99thPercentileLatency(us)", totalHistogram.getValueAtPercentile(99));
for (Integer percentile: percentiles) {
exporter.write(getName(), ordinal(percentile) + "PercentileLatency(us)", totalHistogram.getValueAtPercentile(percentile));
}
exportReturnCodes(exporter);
}
......@@ -142,4 +156,45 @@ public class OneMeasurementHdrHistogram extends OneMeasurement {
return intervalHistogram;
}
/**
* Helper method to parse the given percentile value string
*
* @param percentileString - comma delimited string of Integer values
* @return An Integer List of percentile values
*/
private List<Integer> getPercentileValues(String percentileString) {
List<Integer> percentileValues = new ArrayList<Integer>();
try {
for (String rawPercentile: percentileString.split(",")) {
percentileValues.add(Integer.parseInt(rawPercentile));
}
} catch(Exception e) {
// If the given hdrhistogram.percentiles value is unreadable for whatever reason,
// then calculate and return the default set.
System.err.println("[WARN] Couldn't read " + PERCENTILES_PROPERTY + " value: '" + percentileString +
"', the default of '" + PERCENTILES_PROPERTY_DEFAULT + "' will be used.");
e.printStackTrace();
return getPercentileValues(PERCENTILES_PROPERTY_DEFAULT);
}
return percentileValues;
}
/**
* Helper method to find the ordinal of any number. eg 1 -> 1st
* @param i
* @return ordinal string
*/
private String ordinal(int i) {
String[] suffixes = new String[] { "th", "st", "nd", "rd", "th", "th", "th", "th", "th", "th" };
switch (i % 100) {
case 11:
case 12:
case 13:
return i + "th";
default:
return i + suffixes[i % 10];
}
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment