未验证 提交 971578c6 编写于 作者: Y Yan Chunwei 提交者: GitHub

enhance/add histogram sample (#137)

上级 346b64e1
......@@ -146,7 +146,7 @@ def get_histogram_tags(storage):
return get_tags(storage, 'histogram')
def get_histogram(storage, mode, tag):
def get_histogram(storage, mode, tag, num_samples=200):
with storage.mode(mode) as reader:
histogram = reader.histogram(tag)
res = []
......@@ -171,7 +171,22 @@ def get_histogram(storage, mode, tag):
[instance.left(),
instance.right(),
instance.frequency()])
return res
if len(res) < num_samples:
return res
# sample some steps
span = float(len(res)) / (num_samples - 1)
span_offset = 0
data_idx = 0
sampled_data = []
data_size = len(res)
while data_idx < data_size:
sampled_data.append(res[data_size - data_idx - 1])
span_offset += 1
data_idx = int(span_offset * span)
sampled_data.append(res[0])
return sampled_data[::-1]
def retry(ntimes, function, time2sleep, *args, **kwargs):
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册