1/**
2 * A simple method to log 95th percentile information
3 */
4private static void logPercentileInfo() {
5
6 double total = 0;
7 for (Map.Entry<Long, Long> entry : CassandraTimer.histogram.entrySet()) {
8 long value = entry.getKey() * entry.getValue();
9 total += value;
10 }
11
12 double sum = 0.95*total;
13
14 double totalSum = 0;
15
16 SortedSet<Long> keys = new TreeSet<Long>(CassandraTimer.histogram.keySet());
17 for (long key : keys) {
18
19 totalSum += CassandraTimer.histogram.get(key);
20
21 if(totalSum >= sum) {
22 //this is the 95th percentile I guess
23 System.out.println(key);
24 }
25 }
26
27}
1for (i=0, sum=0; i<n; i++) sum += Number[i];
2tot = sum;
3for (i=0, sum=0; i<n && sum < 0.95*tot; i++) sum += Number[i];
4// i is about it
1 public static long[] percentiles(long[] latencies, double... percentiles) {
2 Arrays.sort(latencies, 0, latencies.length);
3 long[] values = new long[percentiles.length];
4 for (int i = 0; i < percentiles.length; i++) {
5 int index = (int) (percentiles[i] * latencies.length);
6 values[i] = latencies[index];
7 }
8 return values;
9 }