Ejemplo n.º 1
0
def parse(lines):
    lg = logging.getLogger(funcname())
    lg.setLevel(logging.ERROR)
    
    EVENTS = dict()

    i = 0
    skipped = 0
    for line in lines:
        i += 1
        line = line.rstrip()

        lg.info(line)
        ev = None
        for p in event_parsers:
            try:
                ev = p.parse_line(line)
                break
            except ParseError:
                pass

            pass

        if not ev:
            lg.warn('Unable to parse string')
            lg.info(line)
            skipped += 1
        else:
            ev.line = i
            EVENTS[i] = ev
            pass

        lg.info(ev)

        if i >= 376:
            break

        pass
    lg.setLevel(logging.INFO)
    lg.info('skipped lines = %d' % skipped)
    
    return EVENTS
Ejemplo n.º 2
0
    def make_dot(self, fd):
        lg.info(funcname())

        # header        
        fd.write('digraph {\n')
        
        # timeline
        fd.write('{\n')
        fd.write('node [shape=plaintext];\n')
        fd.write(' -> '.join(map(lambda x: x.get_dot_name(), sorted(self.times))))
        fd.write(';\n')
        fd.write('}\n\n')
        
        # threads list
        fd.write('{\n')
        fd.write('rank = same; "past"; ')
        fd.write('; '.join(map(lambda x: x.get_dot_name(), self.threads)))
        fd.write('\n}\n\n')
        
        # time ranking
        fd.write('node [shape=box];\n')
        for tm, elist in self.time_events_th_uniq.iteritems():
            fd.write('{{ rank = same; {0}; '.format(tm.get_dot_name()))
            fd.write('; '.join(map(lambda x: x.get_dot_name(), elist)))
            fd.write('}\n')
        fd.write('\n')
        
        # events
        def node_list(node): 
            while node:
                yield node
                node = node.child
            raise StopIteration
        for th in self.threads:
            for a, b in pair_iter(node_list(th)):
                fd.write('{0} -> {1};\n'.format(a.get_dot_name(), b.get_dot_name()))
                pass
            pass
        
        # invisible nodes
        for ie in self.invis_nodes:
            fd.write(InvisibleLink(ie.parent, ie).get_dot_code()); fd.write('\n')
            fd.write(InvisibleLink(ie, ie.child).get_dot_code()); fd.write('\n')
        fd.write('\n')
        
        # nodes attributes
        def write_attribs(lis):
            for ev in lis:
                fd.write(ev.get_dot_node_name_attrib())
                fd.write('\n')
                pass
            fd.write('\n')
            pass
        write_attribs(self.events)
        write_attribs(self.invis_nodes)
        
        # ipc links
        for il in self.ipc_links:
            fd.write(il.get_dot_code()); fd.write('\n')
        
        
        
        # footer
        fd.write('}')
Ejemplo n.º 3
0
 def make_graph(self):
     lg.info(funcname())
     
     # parse all events and fill base structures
     for _,v in self.raw_events.iteritems():
         tm = TimeNode(v.time)
         if not tm in self.times:
             self.times.add(tm)
             self.time_events[tm] = list()
             pass
         
         th = ThreadNode(v.thread, v.proc)
         if not th in self.threads:
             self.threads.add(th)
             self.thread_events[th] = list()
             pass
         
         ev = EventNode(tm, th, v)
         self.thread_events[th].append(ev)
         self.time_events[tm].append(ev)
         self.events.append(ev)
         
         pass
     
     # build the linked list of event and thread nodes
     for th, elist in self.thread_events.iteritems():
         elist[0].set_parent(th)
         elist[0].first = True
         
         for a,b in pair_iter(elist):
             b.set_parent(a)
             pass
         pass
     
     # build time events list unique by thread
     for tm, elist in self.time_events.iteritems():
         self.time_events_th_uniq[tm] = list(unique_everseen(elist, lambda x: x.thread))
     
     # set invisible nodes to fix time ranking
     for tma, tmb in pair_iter(sorted(self.times)):
         elista = self.time_events_th_uniq[tma]
         elistb = self.time_events_th_uniq[tmb]
         have_threads_a = {e.thread for e in elista}
         have_threads_b = {e.thread for e in elistb}
         lack_threads_b = self.threads - have_threads_b
         
         for th in lack_threads_b:
             if th in have_threads_a:
                 e = (e for e in elista if e.thread == th).next()
                 while e.child and e.child.time == e.time: 
                     e = e.child
                     pass
                 if e.child:
                     ie = InvisibleNode(str(th) + str(tmb) + 'invis')
                     ie.thread = th
                     ie.time = tmb
                     e.set_sec_child(ie)
                     e.child.set_sec_parent(ie)
                     ie.set_parent(e)
                     ie.set_child(e.child)
                     self.time_events_th_uniq[tmb].append(ie)
                     
                     self.invis_nodes.append(ie)
                     pass
                 pass
             pass # for th in lac_th
         pass
     
     self.find_hor_links()
     self.shrink_graph()
     
     pass