提交 7b760783 编写于 作者: W wenkai

optimize visual range calc

上级 d640bf5a
...@@ -157,10 +157,22 @@ class HistogramReservoir(Reservoir): ...@@ -157,10 +157,22 @@ class HistogramReservoir(Reservoir):
Args: Args:
size (int): Container Size. If the size is 0, the container is not limited. size (int): Container Size. If the size is 0, the container is not limited.
""" """
def __init__(self, size):
super().__init__(size)
# Marker to avoid redundant calc for unchanged histograms.
self._visual_range_up_to_date = False
def add_sample(self, sample):
"""Adds sample, see parent class for details."""
super().add_sample(sample)
self._visual_range_up_to_date = False
def samples(self): def samples(self):
"""Return all stored samples.""" """Return all stored samples."""
with self._mutex: with self._mutex:
if self._visual_range_up_to_date:
return list(self._samples)
# calc visual range # calc visual range
visual_range = _VisualRange() visual_range = _VisualRange()
max_count = 0 max_count = 0
...@@ -179,7 +191,8 @@ class HistogramReservoir(Reservoir): ...@@ -179,7 +191,8 @@ class HistogramReservoir(Reservoir):
bins = calc_histogram_bins(max_count) bins = calc_histogram_bins(max_count)
# update visual range # update visual range
logger.info("Visual histogram: min %s, max %s, bins %s, max_count %s.", logger.debug(
"Visual histogram: min %s, max %s, bins %s, max_count %s.",
visual_range.min, visual_range.min,
visual_range.max, visual_range.max,
bins, bins,
...@@ -188,6 +201,7 @@ class HistogramReservoir(Reservoir): ...@@ -188,6 +201,7 @@ class HistogramReservoir(Reservoir):
histogram = sample.value histogram = sample.value
histogram.set_visual_range(visual_range.max, visual_range.min, bins) histogram.set_visual_range(visual_range.max, visual_range.min, bins)
self._visual_range_up_to_date = True
return list(self._samples) return list(self._samples)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册