Esempio n. 1
0
 def __iter__(self):
     exit_event_queue = []
     root = self._prototype.root()
     picking_list = root.children_list()[:]
     yield Event.start(tme=0,
                       pid=1,
                       ppid=0,
                       name=self._prototype.root().name)
     exit_event_queue.append(
         Event.exit(tme=0, pid=1, ppid=0, start_tme=0, name=root.name))
     picked = 0
     for i in range(self._tree_node_count):
         if random.random() <= self._relative_matching:
             try:
                 node = random.choice(picking_list)
                 picking_list.remove(node)
             except IndexError:
                 node = random.choice(root.children_list())
             node_name = node.name
             pid = node.pid
             picked += 1
         else:
             node_name = id_generator()
             pid = i + 2
         yield Event.start(tme=0, pid=pid, ppid=1, name=node_name)
         exit_event_queue.append(
             Event.exit(tme=0, pid=pid, ppid=1, name=node_name,
                        start_tme=0))
     while exit_event_queue:
         yield exit_event_queue.pop()
Esempio n. 2
0
    def test_creation(self):
        event = Event.start(0, 0, 1)
        self.assertEqual(type(event), ProcessStartEvent)

        event_2 = Event.exit(1, 0, 1, 0)
        self.assertEqual(type(event_2), ProcessExitEvent)
        self.assertEqual(event_2.start_tme, 0)

        event_3 = Event.add(1, 0, 1, .5)
        self.assertEqual(type(event_3), TrafficEvent)
        self.assertEqual(event_3.value, .5)
Esempio n. 3
0
    def test_start_exit(self):
        signature = ParentChildByNameTopologySignature()
        alg = IncrementalDistanceAlgorithm(signature=signature,
                                           distance=StartExitDistance)
        alg.prototypes = [self._simple_prototype]

        alg.start_tree()
        alg.add_event(Event.start(tme=0, pid=2, ppid=1, name="root_node"))
        alg.add_event(Event.start(tme=1, pid=3, ppid=2, name="first_child"))
        alg.add_event(Event.start(tme=1, pid=4, ppid=2, name="second_child"))
        alg.add_event(
            Event.exit(tme=3, start_tme=1, pid=3, ppid=2, name="first_child"))
        alg.add_event(
            Event.exit(tme=4, start_tme=1, pid=4, ppid=2, name="second_child"))
        alg.add_event(Event.start(tme=5, pid=5, ppid=2, name="first_child"))
        alg.add_event(
            Event.exit(tme=7, start_tme=5, pid=5, ppid=2, name="first_child"))
        distance = alg.add_event(
            Event.exit(tme=10, start_tme=0, pid=2, ppid=1, name="root_node"))
        alg.finish_tree()
        self.assertEqual(distance[0][0], [0])
Esempio n. 4
0
    def test_manual_creation(self):
        start = ProcessStartEvent(0, 0, 0)
        start.pid = 2
        start.ppid = 1
        start.tme = 1
        self.assertEqual(start, Event.start(1, 2, 1))

        exit = ProcessExitEvent(0, 0, 0, 0)
        exit.pid = 2
        exit.ppid = 1
        exit.tme = 1
        exit.start_tme = 0
        exit.value = 1
        self.assertEqual(exit, Event.exit(1, 2, 1, 0))

        traffic = TrafficEvent(0, 0, 0, 0)
        traffic.pid = 2
        traffic.ppid = 1
        traffic.tme = 1
        traffic.value = 5
        self.assertEqual(traffic.value, 5)
        self.assertEqual(traffic, Event.add(1, 2, 1, 5))