massage_qps_stats_helpers.py
Go to the documentation of this file.
1 # Copyright 2017 gRPC authors.
2 #
3 # Licensed under the Apache License, Version 2.0 (the "License");
4 # you may not use this file except in compliance with the License.
5 # You may obtain a copy of the License at
6 #
7 # http://www.apache.org/licenses/LICENSE-2.0
8 #
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 # See the License for the specific language governing permissions and
13 # limitations under the License.
14 
15 import collections
16 
17 
18 def _threshold_for_count_below(buckets, boundaries, count_below):
19  count_so_far = 0
20  for lower_idx in range(0, len(buckets)):
21  count_so_far += buckets[lower_idx]
22  if count_so_far >= count_below:
23  break
24  if count_so_far == count_below:
25  # this bucket hits the threshold exactly... we should be midway through
26  # any run of zero values following the bucket
27  for upper_idx in range(lower_idx + 1, len(buckets)):
28  if buckets[upper_idx] != 0:
29  break
30  return (boundaries[lower_idx] + boundaries[upper_idx]) / 2.0
31  else:
32  # treat values as uniform throughout the bucket, and find where this value
33  # should lie
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]))
38 
39 
40 def percentile(buckets, pctl, boundaries):
41  return _threshold_for_count_below(buckets, boundaries,
42  sum(buckets) * pctl / 100.0)
43 
44 
45 def counter(core_stats, name):
46  for stat in core_stats['metrics']:
47  if stat['name'] == name:
48  return int(stat.get('count', 0))
49 
50 
51 Histogram = collections.namedtuple('Histogram', 'buckets boundaries')
52 
53 
54 def histogram(core_stats, name):
55  for stat in core_stats['metrics']:
56  if stat['name'] == name:
57  buckets = []
58  boundaries = []
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)
performance.massage_qps_stats_helpers.histogram
def histogram(core_stats, name)
Definition: massage_qps_stats_helpers.py:54
capstone.range
range
Definition: third_party/bloaty/third_party/capstone/bindings/python/capstone/__init__.py:6
grpc::testing::sum
double sum(const T &container, F functor)
Definition: test/cpp/qps/stats.h:30
performance.massage_qps_stats_helpers.counter
def counter(core_stats, name)
Definition: massage_qps_stats_helpers.py:45
performance.massage_qps_stats_helpers.Histogram
Histogram
Definition: massage_qps_stats_helpers.py:51
xds_interop_client.int
int
Definition: xds_interop_client.py:113
performance.massage_qps_stats_helpers._threshold_for_count_below
def _threshold_for_count_below(buckets, boundaries, count_below)
Definition: massage_qps_stats_helpers.py:18
len
int len
Definition: abseil-cpp/absl/base/internal/low_level_alloc_test.cc:46
performance.massage_qps_stats_helpers.percentile
def percentile(buckets, pctl, boundaries)
Definition: massage_qps_stats_helpers.py:40


grpc
Author(s):
autogenerated on Fri May 16 2025 02:59:22