Example #1
0
 def test_parameter_event_generation(self):
     prototype = Prototype()
     root = prototype.add_node("root", pid=1, ppid=0, test=2, muh=3, tme=3, exit_tme=3)
     events = 0
     matches = 0
     for event in Event.events_from_node(root, supported={ParameterEvent: True}):
         events += 1
         if event.name == "test":
             self.assertEqual(2, event.value)
             matches += 1
         if event.name == "muh":
             self.assertEqual(3, event.value)
             matches += 1
     self.assertEqual(2, events)
     self.assertEqual(2, matches)
Example #2
0
    def event_iter(self, include_marker=True, supported=None):
        exit_event_queue = deque(
        )  # (tme, -#events, event); leftmost popped FIRST
        event_count = 0

        for node in self.node_iter(include_marker=include_marker):
            try:
                now = node.tme
            except AttributeError:
                # EmptyNode Event only needs to be forwarded
                event = EmptyProcessEvent()
                event.node = node
                yield event
                continue

            # yield any exit events that should have happened so far
            while exit_event_queue and exit_event_queue[0][0] < now:
                yield exit_event_queue.popleft()[2]

            existing_parameter_nodes = {}
            for event in Event.events_from_node(node, supported=supported):
                event_count += 1
                if isinstance(event, ProcessStartEvent):
                    event.node = node
                    yield event
                    continue
                elif isinstance(event, ProcessExitEvent):
                    event.node = node
                else:
                    try:
                        current_node = existing_parameter_nodes[event.name]
                    except KeyError:
                        existing_parameter_nodes[event.name] = OrderedTreeNode(
                            1, **event.__dict__)
                        current_node = existing_parameter_nodes[event.name]
                        current_node._parent = node
                    event.node = current_node
                    if event.tme <= now:
                        yield event
                        continue
                try:
                    bisect.insort_right(exit_event_queue,
                                        (event.tme, -event_count, event))
                except AttributeError:
                    pass
        while exit_event_queue:
            yield exit_event_queue.popleft()[2]