Esempio n. 1
0
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())
        }
Esempio n. 2
0
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())
        }
Esempio n. 3
0
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)