#NEWLINE# def _PercentilesFromHistogram( ycsb_histogram , percentiles = _DEFAULT_PERCENTILES ) : #NEWLINE# #INDENT# 'Calculate percentiles for from a YCSB histogram.\n\n  Args:\n    ycsb_histogram: List of (time_ms, frequency) tuples.\n    percentiles: iterable of floats, in the interval [0, 100].\n\n  Returns:\n    dict, mapping from percentile to value.\n  ' #NEWLINE# result = collections . OrderedDict ( ) #NEWLINE# histogram = sorted ( ycsb_histogram ) #NEWLINE# for percentile in percentiles : #NEWLINE# #INDENT# if ( ( percentile < 0 ) or ( percentile > 100 ) ) : #NEWLINE# #INDENT# raise ValueError ( 'Invalid percentile: {0}' . format ( percentile ) ) #NEWLINE# #UNINDENT# if ( math . modf ( percentile ) [ 0 ] < 1e-07 ) : #NEWLINE# #INDENT# percentile = int ( percentile ) #NEWLINE# #UNINDENT# label = 'p{0}' . format ( percentile ) #NEWLINE# ( latencies , freqs ) = zip ( * histogram ) #NEWLINE# time_ms = _WeightedQuantile ( latencies , freqs , ( percentile * 0.01 ) ) #NEWLINE# result [ label ] = time_ms #NEWLINE# #UNINDENT# return result