20 for lower_idx
in range(0,
len(buckets)):
21 count_so_far += buckets[lower_idx]
22 if count_so_far >= count_below:
24 if count_so_far == count_below:
27 for upper_idx
in range(lower_idx + 1,
len(buckets)):
28 if buckets[upper_idx] != 0:
30 return (boundaries[lower_idx] + boundaries[upper_idx]) / 2.0
34 lower_bound = boundaries[lower_idx]
35 upper_bound = boundaries[lower_idx + 1]
36 return (upper_bound - (upper_bound - lower_bound) *
37 (count_so_far - count_below) / float(buckets[lower_idx]))
42 sum(buckets) * pctl / 100.0)
46 for stat
in core_stats[
'metrics']:
47 if stat[
'name'] == name:
48 return int(stat.get(
'count', 0))
51 Histogram = collections.namedtuple(
'Histogram',
'buckets boundaries')
55 for stat
in core_stats[
'metrics']:
56 if stat[
'name'] == name:
59 for b
in stat[
'histogram'][
'buckets']:
60 buckets.append(
int(b.get(
'count', 0)))
61 boundaries.append(
int(b.get(
'start', 0)))
62 return Histogram(buckets=buckets, boundaries=boundaries)