def __init__(self, low, high, sign_figures): super(RespTimesCounter, self).__init__() self.low = low self.high = high self.sign_figures = sign_figures self.histogram = HdrHistogram(low, high, sign_figures) self._cached_perc = None self._cached_stdev = None
def __init__(self, low, high, sign_figures, perc_levels=()): super(RespTimesCounter, self).__init__() self.low = low self.high = high self.sign_figures = sign_figures self.histogram = HdrHistogram(low, high, sign_figures) self._ff_iterator = None self._perc_levels = perc_levels self.known_mean = None
class RespTimesCounter(JSONConvertable): def __init__(self, low, high, sign_figures): super(RespTimesCounter, self).__init__() self.low = low self.high = high self.sign_figures = sign_figures self.histogram = HdrHistogram(low, high, sign_figures) def __bool__(self): return len(self) > 0 def __len__(self): return self.histogram.total_count def add(self, item, count=1): self.histogram.record_value(item, count) def merge(self, other): self.histogram.add(other.histogram) def get_percentiles_dict(self, percentiles): return self.histogram.get_percentile_to_value_dict(percentiles) def get_counts(self): return self.histogram.get_value_counts() def get_stdev(self): return self.histogram.get_stddev() def __json__(self): return { float(rt) / 1000: count for rt, count in iteritems(self.histogram.get_value_counts()) }
class RespTimesCounter(JSONConvertable): def __init__(self, low, high, sign_figures): super(RespTimesCounter, self).__init__() self.low = low self.high = high self.sign_figures = sign_figures self.histogram = HdrHistogram(low, high, sign_figures) self._cached_perc = None self._cached_stdev = None def __deepcopy__(self, memo): new = RespTimesCounter(self.low, self.high, self.sign_figures) new._cached_perc = self._cached_perc new._cached_stdev = self._cached_stdev # TODO: maybe hdrpy can encapsulate this itself new.histogram.counts = copy.deepcopy(self.histogram.counts, memo) new.histogram.total_count = self.histogram.total_count new.histogram.min_value = self.histogram.min_value new.histogram.max_value= self.histogram.max_value return new def __bool__(self): return len(self) > 0 def __len__(self): return self.histogram.total_count def add(self, item, count=1): item = round(item * 1000.0, 3) self._cached_perc = None self._cached_stdev = None self.histogram.record_value(item, count) def merge(self, other): self._cached_perc = None self._cached_stdev = None self.histogram.add(other.histogram) def get_percentiles_dict(self, percentiles): if self._cached_perc is None or set(self._cached_perc.keys()) != set(percentiles): self._cached_perc = self.histogram.get_percentile_to_value_dict(percentiles) return self._cached_perc def get_counts(self): return self.histogram.get_value_counts() def get_stdev(self, mean): if self._cached_stdev is None: self._cached_stdev = self.histogram.get_stddev(mean) / 1000.0 # is this correct to divide? return self._cached_stdev def __json__(self): return { rt / 1000.0: int(count) # because hdrpy returns int64, which is unrecognized by json serializer for rt, count in iteritems(self.get_counts()) }
class RespTimesCounter(JSONConvertable): def __init__(self, low, high, sign_figures): super(RespTimesCounter, self).__init__() self.low = low self.high = high self.sign_figures = sign_figures self.histogram = HdrHistogram(low, high, sign_figures) def __bool__(self): return len(self) > 0 def __len__(self): return self.histogram.total_count def add(self, item, count=1): self.histogram.record_value(item, count) def merge(self, other): self.histogram.add(other.histogram) def get_percentiles_dict(self, percentiles): return self.histogram.get_percentile_to_value_dict(percentiles) def get_counts(self): return self.histogram.get_value_counts() def __json__(self): counts = self.get_counts() return counts
class RespTimesCounter(JSONConvertible): def __init__(self, low, high, sign_figures, perc_levels=()): super(RespTimesCounter, self).__init__() self.low = low self.high = high self.sign_figures = sign_figures self.histogram = HdrHistogram(low, high, sign_figures) self._ff_iterator = None self._perc_levels = perc_levels self.known_mean = None def __deepcopy__(self, memo): new = RespTimesCounter(self.low, self.high, self.sign_figures) new._ff_iterator = self._ff_iterator new._perc_levels = self._perc_levels # TODO: maybe hdrpy can encapsulate this itself new.histogram.counts = copy.deepcopy(self.histogram.counts, memo) new.histogram.total_count = self.histogram.total_count new.histogram.min_value = self.histogram.min_value new.histogram.max_value = self.histogram.max_value return new def __bool__(self): return len(self) > 0 def __len__(self): return self.histogram.total_count def add(self, item, count=1): item = round(item * 1000.0, 3) if item > self.high: self.__grow(math.ceil(item / 1000.0) * 1000.0) self._ff_iterator = None self.histogram.record_value(item, count) def merge(self, other): self._ff_iterator = None if other.high > self.high: self.__grow(other.high) self.histogram.add(other.histogram) def _get_ff(self): if self._ff_iterator is None: self._ff_iterator = SinglePassIterator(self.histogram, self._perc_levels, self.known_mean) for _ in self._ff_iterator: pass # consume it return self._ff_iterator def get_percentiles_dict(self): return self._get_ff().percentiles def get_counts(self): return self._get_ff().hist_values def get_stdev(self): return self._get_ff().stdev / 1000.0 def __json__(self): return { rt / 1000.0: int(count) # because hdrpy returns int64, which is unrecognized by json serializer for rt, count in iteritems(self.get_counts()) } def __grow(self, newsize): log.debug("Growing HDR from %s to %s", self.high, newsize) old = self.histogram self.high = newsize self.histogram = HdrHistogram(self.low, self.high, self.sign_figures) self.histogram.add(old)
def __grow(self, newsize): log.debug("Growing HDR from %s to %s", self.high, newsize) old = self.histogram self.high = newsize self.histogram = HdrHistogram(self.low, self.high, self.sign_figures) self.histogram.add(old)
class RespTimesCounter(JSONConvertible): def __init__(self, low, high, sign_figures): super(RespTimesCounter, self).__init__() self.low = low self.high = high self.sign_figures = sign_figures self.histogram = HdrHistogram(low, high, sign_figures) self._cached_perc = None self._cached_stdev = None def __deepcopy__(self, memo): new = RespTimesCounter(self.low, self.high, self.sign_figures) new._cached_perc = self._cached_perc new._cached_stdev = self._cached_stdev # TODO: maybe hdrpy can encapsulate this itself new.histogram.counts = copy.deepcopy(self.histogram.counts, memo) new.histogram.total_count = self.histogram.total_count new.histogram.min_value = self.histogram.min_value new.histogram.max_value = self.histogram.max_value return new def __bool__(self): return len(self) > 0 def __len__(self): return self.histogram.total_count def add(self, item, count=1): item = round(item * 1000.0, 3) if item > self.high: self.__grow(math.ceil(item / 1000.0) * 1000.0) self._cached_perc = None self._cached_stdev = None self.histogram.record_value(item, count) def merge(self, other): self._cached_perc = None self._cached_stdev = None if other.high > self.high: self.__grow(other.high) self.histogram.add(other.histogram) def get_percentiles_dict(self, percentiles): if self._cached_perc is None or set(self._cached_perc.keys()) != set(percentiles): self._cached_perc = self.histogram.get_percentile_to_value_dict(percentiles) return self._cached_perc def get_counts(self): return self.histogram.get_value_counts() def get_stdev(self, mean): if self._cached_stdev is None: self._cached_stdev = self.histogram.get_stddev(mean) / 1000.0 # is this correct to divide? return self._cached_stdev def __json__(self): return { rt / 1000.0: int(count) # because hdrpy returns int64, which is unrecognized by json serializer for rt, count in iteritems(self.get_counts()) } def __grow(self, newsize): log.debug("Growing HDR from %s to %s", self.high, newsize) old = self.histogram self.high = newsize self.histogram = HdrHistogram(self.low, self.high, self.sign_figures) self.histogram.add(old)