示例#1
0
    def transform_to_fixed_size_buckets(percentages_histogram,
                                        expected_buckets=200):
        """
        Returns for given histogram to a normalized histogram in term of buckets.
        :param percentages_histogram: Histogram as returned per memtier in format
        :param expected_buckets: Number of buckets expected in the histogram
        :return: Histogram which has 100µs buckets between [0, expected_buckets/10 - 0.1] ms
        """
        result = {}

        # Default initialize the result-dictionary to our needs
        for i in range(expected_buckets):
            result[StdLib.get_rounded_double(i / 10)] = 0.0

        sum_below_range = 0
        sum_beyond_range = 0
        current_below = 0
        # Fill in the observed values to the dictionary
        for item in percentages_histogram:
            if item >= expected_buckets / 10:
                # Accumulate anything above X milliseconds
                sum_beyond_range += percentages_histogram.get(item)
                continue
            if item <= 1:
                if int(item * 10) - int(current_below * 10) > 0.99:
                    if not current_below == 0.0:
                        index = StdLib.get_rounded_double(
                            int(current_below * 10) / 10)
                        result[index] = sum_below_range
                    sum_below_range = percentages_histogram.get(item)
                    current_below = item
                    if item == 1:
                        current_below = 0
                        sum_below_range = 0
                        index = StdLib.get_rounded_double(item)
                        result[index] = percentages_histogram.get(item)
                else:
                    sum_below_range += percentages_histogram.get(item)
                continue
            # Try to expand buckets and divide respective percentages evenly -> uniform distribution inside buckets
            bucket_count = int(
                math.pow(10,
                         math.ceil(math.log10(item + 0.1)) - 1))
            bucket_value = StdLib.safe_div(percentages_histogram.get(item),
                                           bucket_count)
            for i in range(bucket_count):
                index = StdLib.get_rounded_double(item + i / 10)
                result[index] = bucket_value

        last_bucket = StdLib.get_rounded_double((expected_buckets - 1) / 10)
        result[last_bucket] += sum_beyond_range

        return result
示例#2
0
    def dictionary_keywise_add(dict1, dict2):
        result = {
            key: dict1.get(key) + dict2.get(key)
            for key in set(dict1) if dict1.get(key) is not None
        }
        for key in set(dict1):
            if dict1.get(key) is None:
                result[key] = None

        if 'Request_Throughput' in set(dict1):
            keys_to_average = ['Response_Time']
            for key in keys_to_average:
                if key in set(dict1):
                    if dict1['Request_Throughput'] is None or dict1[
                            key] is None:
                        result[key] = None
                    else:
                        result[key] = StdLib.safe_div(
                            ((dict1['Request_Throughput'] * dict1[key]) +
                             (dict2['Request_Throughput'] * dict2[key])),
                            result['Request_Throughput'])
        return result