diff options
Diffstat (limited to 'tools/run_tests/performance/massage_qps_stats_helpers.py')
-rw-r--r-- | tools/run_tests/performance/massage_qps_stats_helpers.py | 71 |
1 files changed, 38 insertions, 33 deletions
diff --git a/tools/run_tests/performance/massage_qps_stats_helpers.py b/tools/run_tests/performance/massage_qps_stats_helpers.py index a2fe4ae6c3..108451cd55 100644 --- a/tools/run_tests/performance/massage_qps_stats_helpers.py +++ b/tools/run_tests/performance/massage_qps_stats_helpers.py @@ -14,44 +14,49 @@ import collections + def _threshold_for_count_below(buckets, boundaries, count_below): - count_so_far = 0 - for lower_idx in range(0, len(buckets)): - count_so_far += buckets[lower_idx] - if count_so_far >= count_below: - break - if count_so_far == count_below: - # this bucket hits the threshold exactly... we should be midway through - # any run of zero values following the bucket - for upper_idx in range(lower_idx + 1, len(buckets)): - if buckets[upper_idx] != 0: - break - return (boundaries[lower_idx] + boundaries[upper_idx]) / 2.0 - else: - # treat values as uniform throughout the bucket, and find where this value - # should lie - lower_bound = boundaries[lower_idx] - upper_bound = boundaries[lower_idx + 1] - return (upper_bound - - (upper_bound - lower_bound) * (count_so_far - count_below) / - float(buckets[lower_idx])) + count_so_far = 0 + for lower_idx in range(0, len(buckets)): + count_so_far += buckets[lower_idx] + if count_so_far >= count_below: + break + if count_so_far == count_below: + # this bucket hits the threshold exactly... we should be midway through + # any run of zero values following the bucket + for upper_idx in range(lower_idx + 1, len(buckets)): + if buckets[upper_idx] != 0: + break + return (boundaries[lower_idx] + boundaries[upper_idx]) / 2.0 + else: + # treat values as uniform throughout the bucket, and find where this value + # should lie + lower_bound = boundaries[lower_idx] + upper_bound = boundaries[lower_idx + 1] + return (upper_bound - (upper_bound - lower_bound) * + (count_so_far - count_below) / float(buckets[lower_idx])) + def percentile(buckets, pctl, boundaries): - return _threshold_for_count_below( - buckets, boundaries, sum(buckets) * pctl / 100.0) + return _threshold_for_count_below(buckets, boundaries, + sum(buckets) * pctl / 100.0) + def counter(core_stats, name): - for stat in core_stats['metrics']: - if stat['name'] == name: - return int(stat.get('count', 0)) + for stat in core_stats['metrics']: + if stat['name'] == name: + return int(stat.get('count', 0)) + Histogram = collections.namedtuple('Histogram', 'buckets boundaries') + + def histogram(core_stats, name): - for stat in core_stats['metrics']: - if stat['name'] == name: - buckets = [] - boundaries = [] - for b in stat['histogram']['buckets']: - buckets.append(int(b.get('count', 0))) - boundaries.append(int(b.get('start', 0))) - return Histogram(buckets=buckets, boundaries=boundaries) + for stat in core_stats['metrics']: + if stat['name'] == name: + buckets = [] + boundaries = [] + for b in stat['histogram']['buckets']: + buckets.append(int(b.get('count', 0))) + boundaries.append(int(b.get('start', 0))) + return Histogram(buckets=buckets, boundaries=boundaries) |