Пример #1
0
    def test_time_packets(self):
        """
        :return:
        """
        time_node = TimePacketsNode(3, 2)
        packets = TimePackets()
        packets.merge_time_metric(time_node)
        self.assertEqual(packets[0], 1, "call times count error.")
        self.assertEqual(packets[1], 3, "total cost times count error.")
        self.assertEqual(packets[2], 2, "total exclusive times count error.")
        self.assertEqual(packets[3], 3, "max cost time count error.")
        self.assertEqual(packets[4], 3, "min cost time count error.")
        self.assertEqual(packets[5], 9, "time square count error.")

        time_node = TimePacketsNode(5, 3)
        packets.merge_time_metric(time_node)
        self.assertEqual(packets[0], 2, "call times count error.")
        self.assertEqual(packets[1], 8, "total cost times count error.")
        self.assertEqual(packets[2], 5, "total exclusive times count error.")
        self.assertEqual(packets[3], 5, "max cost time count error.")
        self.assertEqual(packets[4], 3, "min cost time count error.")
        self.assertEqual(packets[5], 34, "time square count error.")

        packets_other = TimePackets()
        time_node = TimePacketsNode(4, 3)
        packets_other.merge_time_metric(time_node)
        self.assertEqual(packets_other[0], 1, "call times count error.")
        self.assertEqual(packets_other[1], 4, "total cost times count error.")
        self.assertEqual(packets_other[2], 3, "total exclusive times count error.")
        self.assertEqual(packets_other[3], 4, "max cost time count error.")
        self.assertEqual(packets_other[4], 4, "min cost time count error.")
        self.assertEqual(packets_other[5], 16, "time square count error.")

        time_node = TimePacketsNode(8, 2)
        packets_other.merge_time_metric(time_node)
        self.assertEqual(packets_other[0], 2, "call times count error.")
        self.assertEqual(packets_other[1], 12, "total cost times count error.")
        self.assertEqual(packets_other[2], 5, "total exclusive times count error.")
        self.assertEqual(packets_other[3], 8, "max cost time count error.")
        self.assertEqual(packets_other[4], 4, "min cost time count error.")
        self.assertEqual(packets_other[5], 80, "time square count error.")

        packets.merge_packets(packets_other)
        self.assertEqual(packets[0], 4, "call times count error.")
        self.assertEqual(packets[1], 20, "total cost times count error.")
        self.assertEqual(packets[2], 10, "total exclusive times count error.")
        self.assertEqual(packets[3], 8, "max cost time count error.")
        self.assertEqual(packets[4], 3, "min cost time count error.")
        self.assertEqual(packets[5], 114, "time square count error.")
Пример #2
0
    def record_action_metric(self, metric):
        """
        :param metric:
        :return:
        """
        key = (metric.name, metric.scope or '')  # metric key for protocol
        packets = self.__action_packets.get(key)
        if packets is None:
            packets = TimePackets()

        packets.merge_time_metric(metric)
        self.__action_packets[key] = packets

        return key
Пример #3
0
    def record_general_metric(self, metric):
        """
        :param metric:
        :return:
        """
        key = (metric.name.split("/", 1)[1], '')

        packets = self.__general_packets.get(key)
        if packets is None:
            packets = TimePackets()

        packets.merge_time_metric(metric)
        self.__general_packets[key] = packets

        return key
Пример #4
0
    def record_time_metric(self, metric):
        """
        :param metric:
        :return:
        """
        # filter the general data from the metric, the metric node should be distinguish general and basic metric
        if metric.name.startswith("GENERAL"):
            self.record_general_metric(metric)
            return

        key = (metric.name, metric.scope or '')  # metric key for protocol
        packets = self.__time_packets.get(key)
        if packets is None:
            packets = TimePackets()

        packets.merge_time_metric(metric)
        self.__time_packets[key] = packets

        return key