<s> """<STR_LIT>""" <EOL> __author__ = "<STR_LIT>" <EOL> __version__ = "<STR_LIT:1.0>" <EOL> import sys <EOL> import math <EOL> import os . path <EOL> import re <EOL> import textwrap <EOL> import optparse <EOL> import xml . parsers . expat <EOL> try : <EOL> import debug <EOL> except ImportError : <EOL> pass <EOL> def percentage ( p ) : <EOL> return "<STR_LIT>" % ( p * <NUM_LIT> , ) <EOL> def add ( a , b ) : <EOL> return a + b <EOL> def equal ( a , b ) : <EOL> if a == b : <EOL> return a <EOL> else : <EOL> return None <EOL> def fail ( a , b ) : <EOL> assert False <EOL> tol = <NUM_LIT:2> ** - <NUM_LIT> <EOL> def ratio ( numerator , denominator ) : <EOL> try : <EOL> ratio = float ( numerator ) / float ( denominator ) <EOL> except ZeroDivisionError : <EOL> return <NUM_LIT:1.0> <EOL> if ratio < <NUM_LIT:0.0> : <EOL> if ratio < - tol : <EOL> sys . stderr . write ( '<STR_LIT>' % ( numerator , denominator ) ) <EOL> return <NUM_LIT:0.0> <EOL> if ratio > <NUM_LIT:1.0> : <EOL> if ratio > <NUM_LIT:1.0> + tol : <EOL> sys . stderr . write ( '<STR_LIT>' % ( numerator , denominator ) ) <EOL> return <NUM_LIT:1.0> <EOL> return ratio <EOL> class UndefinedEvent ( Exception ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , event ) : <EOL> Exception . __init__ ( self ) <EOL> self . event = event <EOL> def __str__ ( self ) : <EOL> return '<STR_LIT>' % self . event . name <EOL> class Event ( object ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , name , null , aggregator , formatter = str ) : <EOL> self . name = name <EOL> self . _null = null <EOL> self . _aggregator = aggregator <EOL> self . _formatter = formatter <EOL> def __eq__ ( self , other ) : <EOL> return self is other <EOL> def __hash__ ( self ) : <EOL> return id ( self ) <EOL> def null ( self ) : <EOL> return self . _null <EOL> def aggregate ( self , val1 , val2 ) : <EOL> """<STR_LIT>""" <EOL> assert val1 is not None <EOL> assert val2 is not None <EOL> return self . _aggregator ( val1 , val2 ) <EOL> def format ( self , val ) : <EOL> """<STR_LIT>""" <EOL> assert val is not None <EOL> return self . _formatter ( val ) <EOL> MODULE = Event ( "<STR_LIT>" , None , equal ) <EOL> PROCESS = Event ( "<STR_LIT>" , None , equal ) <EOL> CALLS = Event ( "<STR_LIT>" , <NUM_LIT:0> , add ) <EOL> SAMPLES = Event ( "<STR_LIT>" , <NUM_LIT:0> , add ) <EOL> SAMPLES2 = Event ( "<STR_LIT>" , <NUM_LIT:0> , add ) <EOL> TIME = Event ( "<STR_LIT>" , <NUM_LIT:0.0> , add , lambda x : '<STR_LIT:(>' + str ( x ) + '<STR_LIT:)>' ) <EOL> TIME_RATIO = Event ( "<STR_LIT>" , <NUM_LIT:0.0> , add , lambda x : '<STR_LIT:(>' + percentage ( x ) + '<STR_LIT:)>' ) <EOL> TOTAL_TIME = Event ( "<STR_LIT>" , <NUM_LIT:0.0> , fail ) <EOL> TOTAL_TIME_RATIO = Event ( "<STR_LIT>" , <NUM_LIT:0.0> , fail , percentage ) <EOL> CALL_RATIO = Event ( "<STR_LIT>" , <NUM_LIT:0.0> , add , percentage ) <EOL> PRUNE_RATIO = Event ( "<STR_LIT>" , <NUM_LIT:0.0> , add , percentage ) <EOL> class Object ( object ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , events = None ) : <EOL> if events is None : <EOL> self . events = { } <EOL> else : <EOL> self . events = events <EOL> def __hash__ ( self ) : <EOL> return id ( self ) <EOL> def __eq__ ( self , other ) : <EOL> return self is other <EOL> def __contains__ ( self , event ) : <EOL> return event in self . events <EOL> def __getitem__ ( self , event ) : <EOL> try : <EOL> return self . events [ event ] <EOL> except KeyError : <EOL> raise UndefinedEvent ( event ) <EOL> def __setitem__ ( self , event , value ) : <EOL> if value is None : <EOL> if event in self . events : <EOL> del self . events [ event ] <EOL> else : <EOL> self . events [ event ] = value <EOL> class Call ( Object ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , callee_id ) : <EOL> Object . __init__ ( self ) <EOL> self . callee_id = callee_id <EOL> class Function ( Object ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , id , name ) : <EOL> Object . __init__ ( self ) <EOL> self . id = id <EOL> self . name = name <EOL> self . calls = { } <EOL> self . cycle = None <EOL> def add_call ( self , call ) : <EOL> if call . callee_id in self . calls : <EOL> sys . stderr . write ( '<STR_LIT>' % ( str ( self . id ) , str ( call . callee_id ) ) ) <EOL> self . calls [ call . callee_id ] = call <EOL> def __repr__ ( self ) : <EOL> return self . name <EOL> class Cycle ( Object ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self ) : <EOL> Object . __init__ ( self ) <EOL> self . functions = set ( ) <EOL> def add_function ( self , function ) : <EOL> assert function not in self . functions <EOL> self . functions . add ( function ) <EOL> if function . cycle is not None : <EOL> for other in function . cycle . functions : <EOL> if function not in self . functions : <EOL> self . add_function ( other ) <EOL> function . cycle = self <EOL> class Profile ( Object ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self ) : <EOL> Object . __init__ ( self ) <EOL> self . functions = { } <EOL> self . cycles = [ ] <EOL> def add_function ( self , function ) : <EOL> if function . id in self . functions : <EOL> sys . stderr . write ( '<STR_LIT>' % ( function . name , str ( function . id ) ) ) <EOL> self . functions [ function . id ] = function <EOL> def add_cycle ( self , cycle ) : <EOL> self . cycles . append ( cycle ) <EOL> def validate ( self ) : <EOL> """<STR_LIT>""" <EOL> for function in self . functions . itervalues ( ) : <EOL> for callee_id in function . calls . keys ( ) : <EOL> assert function . calls [ callee_id ] . callee_id == callee_id <EOL> if callee_id not in self . functions : <EOL> sys . stderr . write ( '<STR_LIT>' % ( str ( callee_id ) , function . name ) ) <EOL> del function . calls [ callee_id ] <EOL> def find_cycles ( self ) : <EOL> """<STR_LIT>""" <EOL> visited = set ( ) <EOL> for function in self . functions . itervalues ( ) : <EOL> if function not in visited : <EOL> self . _tarjan ( function , <NUM_LIT:0> , [ ] , { } , { } , visited ) <EOL> cycles = [ ] <EOL> for function in self . functions . itervalues ( ) : <EOL> if function . cycle is not None and function . cycle not in cycles : <EOL> cycles . append ( function . cycle ) <EOL> self . cycles = cycles <EOL> if <NUM_LIT:0> : <EOL> for cycle in cycles : <EOL> sys . stderr . write ( "<STR_LIT>" ) <EOL> for member in cycle . functions : <EOL> sys . stderr . write ( "<STR_LIT>" % member . name ) <EOL> def _tarjan ( self , function , order , stack , orders , lowlinks , visited ) : <EOL> """<STR_LIT>""" <EOL> visited . add ( function ) <EOL> orders [ function ] = order <EOL> lowlinks [ function ] = order <EOL> order += <NUM_LIT:1> <EOL> pos = len ( stack ) <EOL> stack . append ( function ) <EOL> for call in function . calls . itervalues ( ) : <EOL> callee = self . functions [ call . callee_id ] <EOL> if callee not in orders : <EOL> order = self . _tarjan ( callee , order , stack , orders , lowlinks , visited ) <EOL> lowlinks [ function ] = min ( lowlinks [ function ] , lowlinks [ callee ] ) <EOL> elif callee in stack : <EOL> lowlinks [ function ] = min ( lowlinks [ function ] , orders [ callee ] ) <EOL> if lowlinks [ function ] == orders [ function ] : <EOL> members = stack [ pos : ] <EOL> del stack [ pos : ] <EOL> if len ( members ) > <NUM_LIT:1> : <EOL> cycle = Cycle ( ) <EOL> for member in members : <EOL> cycle . add_function ( member ) <EOL> return order <EOL> def call_ratios ( self , event ) : <EOL> cycle_totals = { } <EOL> for cycle in self . cycles : <EOL> cycle_totals [ cycle ] = <NUM_LIT:0.0> <EOL> function_totals = { } <EOL> for function in self . functions . itervalues ( ) : <EOL> function_totals [ function ] = <NUM_LIT:0.0> <EOL> for function in self . functions . itervalues ( ) : <EOL> for call in function . calls . itervalues ( ) : <EOL> if call . callee_id != function . id : <EOL> callee = self . functions [ call . callee_id ] <EOL> function_totals [ callee ] += call [ event ] <EOL> if callee . cycle is not None and callee . cycle is not function . cycle : <EOL> cycle_totals [ callee . cycle ] += call [ event ] <EOL> for function in self . functions . itervalues ( ) : <EOL> for call in function . calls . itervalues ( ) : <EOL> assert CALL_RATIO not in call <EOL> if call . callee_id != function . id : <EOL> callee = self . functions [ call . callee_id ] <EOL> if callee . cycle is not None and callee . cycle is not function . cycle : <EOL> total = cycle_totals [ callee . cycle ] <EOL> else : <EOL> total = function_totals [ callee ] <EOL> call [ CALL_RATIO ] = ratio ( call [ event ] , total ) <EOL> def integrate ( self , outevent , inevent ) : <EOL> """<STR_LIT>""" <EOL> assert outevent not in self <EOL> for function in self . functions . itervalues ( ) : <EOL> assert outevent not in function <EOL> assert inevent in function <EOL> for call in function . calls . itervalues ( ) : <EOL> assert outevent not in call <EOL> if call . callee_id != function . id : <EOL> assert CALL_RATIO in call <EOL> for cycle in self . cycles : <EOL> total = inevent . null ( ) <EOL> for function in self . functions . itervalues ( ) : <EOL> total = inevent . aggregate ( total , function [ inevent ] ) <EOL> self [ inevent ] = total <EOL> total = inevent . null ( ) <EOL> for function in self . functions . itervalues ( ) : <EOL> total = inevent . aggregate ( total , function [ inevent ] ) <EOL> self . _integrate_function ( function , outevent , inevent ) <EOL> self [ outevent ] = total <EOL> def _integrate_function ( self , function , outevent , inevent ) : <EOL> if function . cycle is not None : <EOL> return self . _integrate_cycle ( function . cycle , outevent , inevent ) <EOL> else : <EOL> if outevent not in function : <EOL> total = function [ inevent ] <EOL> for call in function . calls . itervalues ( ) : <EOL> if call . callee_id != function . id : <EOL> total += self . _integrate_call ( call , outevent , inevent ) <EOL> function [ outevent ] = total <EOL> return function [ outevent ] <EOL> def _integrate_call ( self , call , outevent , inevent ) : <EOL> assert outevent not in call <EOL> assert CALL_RATIO in call <EOL> callee = self . functions [ call . callee_id ] <EOL> subtotal = call [ CALL_RATIO ] * self . _integrate_function ( callee , outevent , inevent ) <EOL> call [ outevent ] = subtotal <EOL> return subtotal <EOL> def _integrate_cycle ( self , cycle , outevent , inevent ) : <EOL> if outevent not in cycle : <EOL> total = inevent . null ( ) <EOL> for member in cycle . functions : <EOL> subtotal = member [ inevent ] <EOL> for call in member . calls . itervalues ( ) : <EOL> callee = self . functions [ call . callee_id ] <EOL> if callee . cycle is not cycle : <EOL> subtotal += self . _integrate_call ( call , outevent , inevent ) <EOL> total += subtotal <EOL> cycle [ outevent ] = total <EOL> callees = { } <EOL> for function in self . functions . itervalues ( ) : <EOL> if function . cycle is not cycle : <EOL> for call in function . calls . itervalues ( ) : <EOL> callee = self . functions [ call . callee_id ] <EOL> if callee . cycle is cycle : <EOL> try : <EOL> callees [ callee ] += call [ CALL_RATIO ] <EOL> except KeyError : <EOL> callees [ callee ] = call [ CALL_RATIO ] <EOL> for callee , call_ratio in callees . iteritems ( ) : <EOL> ranks = { } <EOL> call_ratios = { } <EOL> partials = { } <EOL> self . _rank_cycle_function ( cycle , callee , <NUM_LIT:0> , ranks ) <EOL> self . _call_ratios_cycle ( cycle , callee , ranks , call_ratios , set ( ) ) <EOL> partial = self . _integrate_cycle_function ( cycle , callee , call_ratio , partials , ranks , call_ratios , outevent , inevent ) <EOL> assert partial == max ( partials . values ( ) ) <EOL> assert not total or abs ( <NUM_LIT:1.0> - partial / ( call_ratio * total ) ) <= <NUM_LIT> <EOL> return cycle [ outevent ] <EOL> def _rank_cycle_function ( self , cycle , function , rank , ranks ) : <EOL> if function not in ranks or ranks [ function ] > rank : <EOL> ranks [ function ] = rank <EOL> for call in function . calls . itervalues ( ) : <EOL> if call . callee_id != function . id : <EOL> callee = self . functions [ call . callee_id ] <EOL> if callee . cycle is cycle : <EOL> self . _rank_cycle_function ( cycle , callee , rank + <NUM_LIT:1> , ranks ) <EOL> def _call_ratios_cycle ( self , cycle , function , ranks , call_ratios , visited ) : <EOL> if function not in visited : <EOL> visited . add ( function ) <EOL> for call in function . calls . itervalues ( ) : <EOL> if call . callee_id != function . id : <EOL> callee = self . functions [ call . callee_id ] <EOL> if callee . cycle is cycle : <EOL> if ranks [ callee ] > ranks [ function ] : <EOL> call_ratios [ callee ] = call_ratios . get ( callee , <NUM_LIT:0.0> ) + call [ CALL_RATIO ] <EOL> self . _call_ratios_cycle ( cycle , callee , ranks , call_ratios , visited ) <EOL> def _integrate_cycle_function ( self , cycle , function , partial_ratio , partials , ranks , call_ratios , outevent , inevent ) : <EOL> if function not in partials : <EOL> partial = partial_ratio * function [ inevent ] <EOL> for call in function . calls . itervalues ( ) : <EOL> if call . callee_id != function . id : <EOL> callee = self . functions [ call . callee_id ] <EOL> if callee . cycle is not cycle : <EOL> assert outevent in call <EOL> partial += partial_ratio * call [ outevent ] <EOL> else : <EOL> if ranks [ callee ] > ranks [ function ] : <EOL> callee_partial = self . _integrate_cycle_function ( cycle , callee , partial_ratio , partials , ranks , call_ratios , outevent , inevent ) <EOL> call_ratio = ratio ( call [ CALL_RATIO ] , call_ratios [ callee ] ) <EOL> call_partial = call_ratio * callee_partial <EOL> try : <EOL> call [ outevent ] += call_partial <EOL> except UndefinedEvent : <EOL> call [ outevent ] = call_partial <EOL> partial += call_partial <EOL> partials [ function ] = partial <EOL> try : <EOL> function [ outevent ] += partial <EOL> except UndefinedEvent : <EOL> function [ outevent ] = partial <EOL> return partials [ function ] <EOL> def aggregate ( self , event ) : <EOL> """<STR_LIT>""" <EOL> total = event . null ( ) <EOL> for function in self . functions . itervalues ( ) : <EOL> try : <EOL> total = event . aggregate ( total , function [ event ] ) <EOL> except UndefinedEvent : <EOL> return <EOL> self [ event ] = total <EOL> def ratio ( self , outevent , inevent ) : <EOL> assert outevent not in self <EOL> assert inevent in self <EOL> for function in self . functions . itervalues ( ) : <EOL> assert outevent not in function <EOL> assert inevent in function <EOL> function [ outevent ] = ratio ( function [ inevent ] , self [ inevent ] ) <EOL> for call in function . calls . itervalues ( ) : <EOL> assert outevent not in call <EOL> if inevent in call : <EOL> call [ outevent ] = ratio ( call [ inevent ] , self [ inevent ] ) <EOL> self [ outevent ] = <NUM_LIT:1.0> <EOL> def prune ( self , node_thres , edge_thres ) : <EOL> """<STR_LIT>""" <EOL> for function in self . functions . itervalues ( ) : <EOL> try : <EOL> function [ PRUNE_RATIO ] = function [ TOTAL_TIME_RATIO ] <EOL> except UndefinedEvent : <EOL> pass <EOL> for call in function . calls . itervalues ( ) : <EOL> callee = self . functions [ call . callee_id ] <EOL> if TOTAL_TIME_RATIO in call : <EOL> call [ PRUNE_RATIO ] = call [ TOTAL_TIME_RATIO ] <EOL> else : <EOL> try : <EOL> call [ PRUNE_RATIO ] = min ( function [ TOTAL_TIME_RATIO ] , callee [ TOTAL_TIME_RATIO ] ) <EOL> except UndefinedEvent : <EOL> pass <EOL> for function_id in self . functions . keys ( ) : <EOL> function = self . functions [ function_id ] <EOL> try : <EOL> if function [ PRUNE_RATIO ] < node_thres : <EOL> del self . functions [ function_id ] <EOL> except UndefinedEvent : <EOL> pass <EOL> for function in self . functions . itervalues ( ) : <EOL> for callee_id in function . calls . keys ( ) : <EOL> call = function . calls [ callee_id ] <EOL> try : <EOL> if callee_id not in self . functions or call [ PRUNE_RATIO ] < edge_thres : <EOL> del function . calls [ callee_id ] <EOL> except UndefinedEvent : <EOL> pass <EOL> def dump ( self ) : <EOL> for function in self . functions . itervalues ( ) : <EOL> sys . stderr . write ( '<STR_LIT>' % ( function . name , ) ) <EOL> self . _dump_events ( function . events ) <EOL> for call in function . calls . itervalues ( ) : <EOL> callee = self . functions [ call . callee_id ] <EOL> sys . stderr . write ( '<STR_LIT>' % ( callee . name , ) ) <EOL> self . _dump_events ( call . events ) <EOL> def _dump_events ( self , events ) : <EOL> for event , value in events . iteritems ( ) : <EOL> sys . stderr . write ( '<STR_LIT>' % ( event . name , event . format ( value ) ) ) <EOL> class Struct : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , attrs = None ) : <EOL> if attrs is None : <EOL> attrs = { } <EOL> self . __dict__ [ '<STR_LIT>' ] = attrs <EOL> def __getattr__ ( self , name ) : <EOL> try : <EOL> return self . _attrs [ name ] <EOL> except KeyError : <EOL> raise AttributeError ( name ) <EOL> def __setattr__ ( self , name , value ) : <EOL> self . _attrs [ name ] = value <EOL> def __str__ ( self ) : <EOL> return str ( self . _attrs ) <EOL> def __repr__ ( self ) : <EOL> return repr ( self . _attrs ) <EOL> class ParseError ( Exception ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , msg , line ) : <EOL> self . msg = msg <EOL> self . line = line <EOL> def __str__ ( self ) : <EOL> return '<STR_LIT>' % ( self . msg , self . line ) <EOL> class Parser : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self ) : <EOL> pass <EOL> def parse ( self ) : <EOL> raise NotImplementedError <EOL> class LineParser ( Parser ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , file ) : <EOL> Parser . __init__ ( self ) <EOL> self . _file = file <EOL> self . __line = None <EOL> self . __eof = False <EOL> def readline ( self ) : <EOL> line = self . _file . readline ( ) <EOL> if not line : <EOL> self . __line = '<STR_LIT>' <EOL> self . __eof = True <EOL> self . __line = line . rstrip ( '<STR_LIT:\r\n>' ) <EOL> def lookahead ( self ) : <EOL> assert self . __line is not None <EOL> return self . __line <EOL> def consume ( self ) : <EOL> assert self . __line is not None <EOL> line = self . __line <EOL> self . readline ( ) <EOL> return line <EOL> def eof ( self ) : <EOL> assert self . __line is not None <EOL> return self . __eof <EOL> XML_ELEMENT_START , XML_ELEMENT_END , XML_CHARACTER_DATA , XML_EOF = range ( <NUM_LIT:4> ) <EOL> class XmlToken : <EOL> def __init__ ( self , type , name_or_data , attrs = None , line = None , column = None ) : <EOL> assert type in ( XML_ELEMENT_START , XML_ELEMENT_END , XML_CHARACTER_DATA , XML_EOF ) <EOL> self . type = type <EOL> self . name_or_data = name_or_data <EOL> self . attrs = attrs <EOL> self . line = line <EOL> self . column = column <EOL> def __str__ ( self ) : <EOL> if self . type == XML_ELEMENT_START : <EOL> return '<STR_LIT:<>' + self . name_or_data + '<STR_LIT>' <EOL> if self . type == XML_ELEMENT_END : <EOL> return '<STR_LIT>' + self . name_or_data + '<STR_LIT:>>' <EOL> if self . type == XML_CHARACTER_DATA : <EOL> return self . name_or_data <EOL> if self . type == XML_EOF : <EOL> return '<STR_LIT>' <EOL> assert <NUM_LIT:0> <EOL> class XmlTokenizer : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , fp , skip_ws = True ) : <EOL> self . fp = fp <EOL> self . tokens = [ ] <EOL> self . index = <NUM_LIT:0> <EOL> self . final = False <EOL> self . skip_ws = skip_ws <EOL> self . character_pos = <NUM_LIT:0> , <NUM_LIT:0> <EOL> self . character_data = '<STR_LIT>' <EOL> self . parser = xml . parsers . expat . ParserCreate ( ) <EOL> self . parser . StartElementHandler = self . handle_element_start <EOL> self . parser . EndElementHandler = self . handle_element_end <EOL> self . parser . CharacterDataHandler = self . handle_character_data <EOL> def handle_element_start ( self , name , attributes ) : <EOL> self . finish_character_data ( ) <EOL> line , column = self . pos ( ) <EOL> token = XmlToken ( XML_ELEMENT_START , name , attributes , line , column ) <EOL> self . tokens . append ( token ) <EOL> def handle_element_end ( self , name ) : <EOL> self . finish_character_data ( ) <EOL> line , column = self . pos ( ) <EOL> token = XmlToken ( XML_ELEMENT_END , name , None , line , column ) <EOL> self . tokens . append ( token ) <EOL> def handle_character_data ( self , data ) : <EOL> if not self . character_data : <EOL> self . character_pos = self . pos ( ) <EOL> self . character_data += data <EOL> def finish_character_data ( self ) : <EOL> if self . character_data : <EOL> if not self . skip_ws or not self . character_data . isspace ( ) : <EOL> line , column = self . character_pos <EOL> token = XmlToken ( XML_CHARACTER_DATA , self . character_data , None , line , column ) <EOL> self . tokens . append ( token ) <EOL> self . character_data = '<STR_LIT>' <EOL> def next ( self ) : <EOL> size = <NUM_LIT:16> * <NUM_LIT> <EOL> while self . index >= len ( self . tokens ) and not self . final : <EOL> self . tokens = [ ] <EOL> self . index = <NUM_LIT:0> <EOL> data = self . fp . read ( size ) <EOL> self . final = len ( data ) < size <EOL> try : <EOL> self . parser . Parse ( data , self . final ) <EOL> except xml . parsers . expat . ExpatError , e : <EOL> if e . code == <NUM_LIT:3> : <EOL> pass <EOL> else : <EOL> raise e <EOL> if self . index >= len ( self . tokens ) : <EOL> line , column = self . pos ( ) <EOL> token = XmlToken ( XML_EOF , None , None , line , column ) <EOL> else : <EOL> token = self . tokens [ self . index ] <EOL> self . index += <NUM_LIT:1> <EOL> return token <EOL> def pos ( self ) : <EOL> return self . parser . CurrentLineNumber , self . parser . CurrentColumnNumber <EOL> class XmlTokenMismatch ( Exception ) : <EOL> def __init__ ( self , expected , found ) : <EOL> self . expected = expected <EOL> self . found = found <EOL> def __str__ ( self ) : <EOL> return '<STR_LIT>' % ( self . found . line , self . found . column , str ( self . expected ) , str ( self . found ) ) <EOL> class XmlParser ( Parser ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , fp ) : <EOL> Parser . __init__ ( self ) <EOL> self . tokenizer = XmlTokenizer ( fp ) <EOL> self . consume ( ) <EOL> def consume ( self ) : <EOL> self . token = self . tokenizer . next ( ) <EOL> def match_element_start ( self , name ) : <EOL> return self . token . type == XML_ELEMENT_START and self . token . name_or_data == name <EOL> def match_element_end ( self , name ) : <EOL> return self . token . type == XML_ELEMENT_END and self . token . name_or_data == name <EOL> def element_start ( self , name ) : <EOL> while self . token . type == XML_CHARACTER_DATA : <EOL> self . consume ( ) <EOL> if self . token . type != XML_ELEMENT_START : <EOL> raise XmlTokenMismatch ( XmlToken ( XML_ELEMENT_START , name ) , self . token ) <EOL> if self . token . name_or_data != name : <EOL> raise XmlTokenMismatch ( XmlToken ( XML_ELEMENT_START , name ) , self . token ) <EOL> attrs = self . token . attrs <EOL> self . consume ( ) <EOL> return attrs <EOL> def element_end ( self , name ) : <EOL> while self . token . type == XML_CHARACTER_DATA : <EOL> self . consume ( ) <EOL> if self . token . type != XML_ELEMENT_END : <EOL> raise XmlTokenMismatch ( XmlToken ( XML_ELEMENT_END , name ) , self . token ) <EOL> if self . token . name_or_data != name : <EOL> raise XmlTokenMismatch ( XmlToken ( XML_ELEMENT_END , name ) , self . token ) <EOL> self . consume ( ) <EOL> def character_data ( self , strip = True ) : <EOL> data = '<STR_LIT>' <EOL> while self . token . type == XML_CHARACTER_DATA : <EOL> data += self . token . name_or_data <EOL> self . consume ( ) <EOL> if strip : <EOL> data = data . strip ( ) <EOL> return data <EOL> class GprofParser ( Parser ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , fp ) : <EOL> Parser . __init__ ( self ) <EOL> self . fp = fp <EOL> self . functions = { } <EOL> self . cycles = { } <EOL> def readline ( self ) : <EOL> line = self . fp . readline ( ) <EOL> if not line : <EOL> sys . stderr . write ( '<STR_LIT>' ) <EOL> sys . exit ( <NUM_LIT:1> ) <EOL> line = line . rstrip ( '<STR_LIT:\r\n>' ) <EOL> return line <EOL> _int_re = re . compile ( r'<STR_LIT>' ) <EOL> _float_re = re . compile ( r'<STR_LIT>' ) <EOL> def translate ( self , mo ) : <EOL> """<STR_LIT>""" <EOL> attrs = { } <EOL> groupdict = mo . groupdict ( ) <EOL> for name , value in groupdict . iteritems ( ) : <EOL> if value is None : <EOL> value = None <EOL> elif self . _int_re . match ( value ) : <EOL> value = int ( value ) <EOL> elif self . _float_re . match ( value ) : <EOL> value = float ( value ) <EOL> attrs [ name ] = ( value ) <EOL> return Struct ( attrs ) <EOL> _cg_header_re = re . compile ( <EOL> r'<STR_LIT>' + <EOL> r'<STR_LIT>' + <EOL> r'<STR_LIT>' + <EOL> r'<STR_LIT>' <EOL> ) <EOL> _cg_ignore_re = re . compile ( <EOL> r'<STR_LIT>' <EOL> r'<STR_LIT>' <EOL> ) <EOL> _cg_primary_re = re . compile ( <EOL> r'<STR_LIT>' + <EOL> r'<STR_LIT>' + <EOL> r'<STR_LIT>' + <EOL> r'<STR_LIT>' + <EOL> r'<STR_LIT>' + <EOL> r'<STR_LIT>' + <EOL> r'<STR_LIT>' + <EOL> r'<STR_LIT>' <EOL> ) <EOL> _cg_parent_re = re . compile ( <EOL> r'<STR_LIT>' + <EOL> r'<STR_LIT>' + <EOL> r'<STR_LIT>' + <EOL> r'<STR_LIT>' + <EOL> r'<STR_LIT>' + <EOL> r'<STR_LIT>' <EOL> ) <EOL> _cg_child_re = _cg_parent_re <EOL> _cg_cycle_header_re = re . compile ( <EOL> r'<STR_LIT>' + <EOL> r'<STR_LIT>' + <EOL> r'<STR_LIT>' + <EOL> r'<STR_LIT>' + <EOL> r'<STR_LIT>' + <EOL> r'<STR_LIT>' + <EOL> r'<STR_LIT>' <EOL> ) <EOL> _cg_cycle_member_re = re . compile ( <EOL> r'<STR_LIT>' + <EOL> r'<STR_LIT>' + <EOL> r'<STR_LIT>' + <EOL> r'<STR_LIT>' + <EOL> r'<STR_LIT>' + <EOL> r'<STR_LIT>' <EOL> ) <EOL> _cg_sep_re = re . compile ( r'<STR_LIT>' ) <EOL> def parse_function_entry ( self , lines ) : <EOL> parents = [ ] <EOL> children = [ ] <EOL> while True : <EOL> if not lines : <EOL> sys . stderr . write ( '<STR_LIT>' ) <EOL> line = lines . pop ( <NUM_LIT:0> ) <EOL> if line . startswith ( '<STR_LIT:[>' ) : <EOL> break <EOL> mo = self . _cg_parent_re . match ( line ) <EOL> if not mo : <EOL> if self . _cg_ignore_re . match ( line ) : <EOL> continue <EOL> sys . stderr . write ( '<STR_LIT>' % line ) <EOL> else : <EOL> parent = self . translate ( mo ) <EOL> parents . append ( parent ) <EOL> mo = self . _cg_primary_re . match ( line ) <EOL> if not mo : <EOL> sys . stderr . write ( '<STR_LIT>' % line ) <EOL> return <EOL> else : <EOL> function = self . translate ( mo ) <EOL> while lines : <EOL> line = lines . pop ( <NUM_LIT:0> ) <EOL> mo = self . _cg_child_re . match ( line ) <EOL> if not mo : <EOL> if self . _cg_ignore_re . match ( line ) : <EOL> continue <EOL> sys . stderr . write ( '<STR_LIT>' % line ) <EOL> else : <EOL> child = self . translate ( mo ) <EOL> children . append ( child ) <EOL> function . parents = parents <EOL> function . children = children <EOL> self . functions [ function . index ] = function <EOL> def parse_cycle_entry ( self , lines ) : <EOL> line = lines [ <NUM_LIT:0> ] <EOL> mo = self . _cg_cycle_header_re . match ( line ) <EOL> if not mo : <EOL> sys . stderr . write ( '<STR_LIT>' % line ) <EOL> return <EOL> cycle = self . translate ( mo ) <EOL> cycle . functions = [ ] <EOL> for line in lines [ <NUM_LIT:1> : ] : <EOL> mo = self . _cg_cycle_member_re . match ( line ) <EOL> if not mo : <EOL> sys . stderr . write ( '<STR_LIT>' % line ) <EOL> continue <EOL> call = self . translate ( mo ) <EOL> cycle . functions . append ( call ) <EOL> self . cycles [ cycle . cycle ] = cycle <EOL> def parse_cg_entry ( self , lines ) : <EOL> if lines [ <NUM_LIT:0> ] . startswith ( "<STR_LIT:[>" ) : <EOL> self . parse_cycle_entry ( lines ) <EOL> else : <EOL> self . parse_function_entry ( lines ) <EOL> def parse_cg ( self ) : <EOL> """<STR_LIT>""" <EOL> while not self . _cg_header_re . match ( self . readline ( ) ) : <EOL> pass <EOL> line = self . readline ( ) <EOL> while self . _cg_header_re . match ( line ) : <EOL> line = self . readline ( ) <EOL> entry_lines = [ ] <EOL> while line != '<STR_LIT>' : <EOL> if line and not line . isspace ( ) : <EOL> if self . _cg_sep_re . match ( line ) : <EOL> self . parse_cg_entry ( entry_lines ) <EOL> entry_lines = [ ] <EOL> else : <EOL> entry_lines . append ( line ) <EOL> line = self . readline ( ) <EOL> def parse ( self ) : <EOL> self . parse_cg ( ) <EOL> self . fp . close ( ) <EOL> profile = Profile ( ) <EOL> profile [ TIME ] = <NUM_LIT:0.0> <EOL> cycles = { } <EOL> for index in self . cycles . iterkeys ( ) : <EOL> cycles [ index ] = Cycle ( ) <EOL> for entry in self . functions . itervalues ( ) : <EOL> function = Function ( entry . index , entry . name ) <EOL> function [ TIME ] = entry . self <EOL> if entry . called is not None : <EOL> function [ CALLS ] = entry . called <EOL> if entry . called_self is not None : <EOL> call = Call ( entry . index ) <EOL> call [ CALLS ] = entry . called_self <EOL> function [ CALLS ] += entry . called_self <EOL> for child in entry . children : <EOL> call = Call ( child . index ) <EOL> assert child . called is not None <EOL> call [ CALLS ] = child . called <EOL> if child . index not in self . functions : <EOL> missing = Function ( child . index , child . name ) <EOL> function [ TIME ] = <NUM_LIT:0.0> <EOL> function [ CALLS ] = <NUM_LIT:0> <EOL> profile . add_function ( missing ) <EOL> function . add_call ( call ) <EOL> profile . add_function ( function ) <EOL> if entry . cycle is not None : <EOL> cycles [ entry . cycle ] . add_function ( function ) <EOL> profile [ TIME ] = profile [ TIME ] + function [ TIME ] <EOL> for cycle in cycles . itervalues ( ) : <EOL> profile . add_cycle ( cycle ) <EOL> profile . validate ( ) <EOL> profile . ratio ( TIME_RATIO , TIME ) <EOL> profile . call_ratios ( CALLS ) <EOL> profile . integrate ( TOTAL_TIME , TIME ) <EOL> profile . ratio ( TOTAL_TIME_RATIO , TOTAL_TIME ) <EOL> return profile <EOL> class OprofileParser ( LineParser ) : <EOL> """<STR_LIT>""" <EOL> _fields_re = { <EOL> '<STR_LIT>' : r'<STR_LIT>' , <EOL> '<STR_LIT:%>' : r'<STR_LIT>' , <EOL> '<STR_LIT>' : r'<STR_LIT>' , <EOL> '<STR_LIT>' : r'<STR_LIT>' , <EOL> '<STR_LIT>' : r'<STR_LIT>' , <EOL> '<STR_LIT>' : r'<STR_LIT>' , <EOL> } <EOL> def __init__ ( self , infile ) : <EOL> LineParser . __init__ ( self , infile ) <EOL> self . entries = { } <EOL> self . entry_re = None <EOL> def add_entry ( self , callers , function , callees ) : <EOL> try : <EOL> entry = self . entries [ function . id ] <EOL> except KeyError : <EOL> self . entries [ function . id ] = ( callers , function , callees ) <EOL> else : <EOL> callers_total , function_total , callees_total = entry <EOL> self . update_subentries_dict ( callers_total , callers ) <EOL> function_total . samples += function . samples <EOL> self . update_subentries_dict ( callees_total , callees ) <EOL> def update_subentries_dict ( self , totals , partials ) : <EOL> for partial in partials . itervalues ( ) : <EOL> try : <EOL> total = totals [ partial . id ] <EOL> except KeyError : <EOL> totals [ partial . id ] = partial <EOL> else : <EOL> total . samples += partial . samples <EOL> def parse ( self ) : <EOL> self . readline ( ) <EOL> self . parse_header ( ) <EOL> while self . lookahead ( ) : <EOL> self . parse_entry ( ) <EOL> profile = Profile ( ) <EOL> reverse_call_samples = { } <EOL> profile [ SAMPLES ] = <NUM_LIT:0> <EOL> for _callers , _function , _callees in self . entries . itervalues ( ) : <EOL> function = Function ( _function . id , _function . name ) <EOL> function [ SAMPLES ] = _function . samples <EOL> profile . add_function ( function ) <EOL> profile [ SAMPLES ] += _function . samples <EOL> if _function . application : <EOL> function [ PROCESS ] = os . path . basename ( _function . application ) <EOL> if _function . image : <EOL> function [ MODULE ] = os . path . basename ( _function . image ) <EOL> total_callee_samples = <NUM_LIT:0> <EOL> for _callee in _callees . itervalues ( ) : <EOL> total_callee_samples += _callee . samples <EOL> for _callee in _callees . itervalues ( ) : <EOL> if not _callee . self : <EOL> call = Call ( _callee . id ) <EOL> call [ SAMPLES2 ] = _callee . samples <EOL> function . add_call ( call ) <EOL> profile . validate ( ) <EOL> profile . find_cycles ( ) <EOL> profile . ratio ( TIME_RATIO , SAMPLES ) <EOL> profile . call_ratios ( SAMPLES2 ) <EOL> profile . integrate ( TOTAL_TIME_RATIO , TIME_RATIO ) <EOL> return profile <EOL> def parse_header ( self ) : <EOL> while not self . match_header ( ) : <EOL> self . consume ( ) <EOL> line = self . lookahead ( ) <EOL> fields = re . split ( r'<STR_LIT>' , line ) <EOL> entry_re = r'<STR_LIT>' + r'<STR_LIT>' . join ( [ self . _fields_re [ field ] for field in fields ] ) + r'<STR_LIT>' <EOL> self . entry_re = re . compile ( entry_re ) <EOL> self . skip_separator ( ) <EOL> def parse_entry ( self ) : <EOL> callers = self . parse_subentries ( ) <EOL> if self . match_primary ( ) : <EOL> function = self . parse_subentry ( ) <EOL> if function is not None : <EOL> callees = self . parse_subentries ( ) <EOL> self . add_entry ( callers , function , callees ) <EOL> self . skip_separator ( ) <EOL> def parse_subentries ( self ) : <EOL> subentries = { } <EOL> while self . match_secondary ( ) : <EOL> subentry = self . parse_subentry ( ) <EOL> subentries [ subentry . id ] = subentry <EOL> return subentries <EOL> def parse_subentry ( self ) : <EOL> entry = Struct ( ) <EOL> line = self . consume ( ) <EOL> mo = self . entry_re . match ( line ) <EOL> if not mo : <EOL> raise ParseError ( '<STR_LIT>' , line ) <EOL> fields = mo . groupdict ( ) <EOL> entry . samples = int ( fields . get ( '<STR_LIT>' , <NUM_LIT:0> ) ) <EOL> entry . percentage = float ( fields . get ( '<STR_LIT>' , <NUM_LIT:0.0> ) ) <EOL> if '<STR_LIT:source>' in fields and fields [ '<STR_LIT:source>' ] != '<STR_LIT>' : <EOL> source = fields [ '<STR_LIT:source>' ] <EOL> filename , lineno = source . split ( '<STR_LIT::>' ) <EOL> entry . filename = filename <EOL> entry . lineno = int ( lineno ) <EOL> else : <EOL> source = '<STR_LIT>' <EOL> entry . filename = None <EOL> entry . lineno = None <EOL> entry . image = fields . get ( '<STR_LIT:image>' , '<STR_LIT>' ) <EOL> entry . application = fields . get ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> if '<STR_LIT>' in fields and fields [ '<STR_LIT>' ] != '<STR_LIT>' : <EOL> entry . symbol = fields [ '<STR_LIT>' ] <EOL> else : <EOL> entry . symbol = '<STR_LIT>' <EOL> if entry . symbol . startswith ( '<STR_LIT:">' ) and entry . symbol . endswith ( '<STR_LIT:">' ) : <EOL> entry . symbol = entry . symbol [ <NUM_LIT:1> : - <NUM_LIT:1> ] <EOL> entry . id = '<STR_LIT::>' . join ( ( entry . application , entry . image , source , entry . symbol ) ) <EOL> entry . self = fields . get ( '<STR_LIT>' , None ) != None <EOL> if entry . self : <EOL> entry . id += '<STR_LIT>' <EOL> if entry . symbol : <EOL> entry . name = entry . symbol <EOL> else : <EOL> entry . name = entry . image <EOL> return entry <EOL> def skip_separator ( self ) : <EOL> while not self . match_separator ( ) : <EOL> self . consume ( ) <EOL> self . consume ( ) <EOL> def match_header ( self ) : <EOL> line = self . lookahead ( ) <EOL> return line . startswith ( '<STR_LIT>' ) <EOL> def match_separator ( self ) : <EOL> line = self . lookahead ( ) <EOL> return line == '<STR_LIT:->' * len ( line ) <EOL> def match_primary ( self ) : <EOL> line = self . lookahead ( ) <EOL> return not line [ : <NUM_LIT:1> ] . isspace ( ) <EOL> def match_secondary ( self ) : <EOL> line = self . lookahead ( ) <EOL> return line [ : <NUM_LIT:1> ] . isspace ( ) <EOL> class SharkParser ( LineParser ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , infile ) : <EOL> LineParser . __init__ ( self , infile ) <EOL> self . stack = [ ] <EOL> self . entries = { } <EOL> def add_entry ( self , function ) : <EOL> try : <EOL> entry = self . entries [ function . id ] <EOL> except KeyError : <EOL> self . entries [ function . id ] = ( function , { } ) <EOL> else : <EOL> function_total , callees_total = entry <EOL> function_total . samples += function . samples <EOL> def add_callee ( self , function , callee ) : <EOL> func , callees = self . entries [ function . id ] <EOL> try : <EOL> entry = callees [ callee . id ] <EOL> except KeyError : <EOL> callees [ callee . id ] = callee <EOL> else : <EOL> entry . samples += callee . samples <EOL> def parse ( self ) : <EOL> self . readline ( ) <EOL> self . readline ( ) <EOL> self . readline ( ) <EOL> self . readline ( ) <EOL> match = re . compile ( r'<STR_LIT>' ) <EOL> while self . lookahead ( ) : <EOL> line = self . consume ( ) <EOL> mo = match . match ( line ) <EOL> if not mo : <EOL> raise ParseError ( '<STR_LIT>' , line ) <EOL> fields = mo . groupdict ( ) <EOL> prefix = len ( fields . get ( '<STR_LIT>' , <NUM_LIT:0> ) ) / <NUM_LIT:2> - <NUM_LIT:1> <EOL> symbol = str ( fields . get ( '<STR_LIT>' , <NUM_LIT:0> ) ) <EOL> image = str ( fields . get ( '<STR_LIT:image>' , <NUM_LIT:0> ) ) <EOL> entry = Struct ( ) <EOL> entry . id = '<STR_LIT::>' . join ( [ symbol , image ] ) <EOL> entry . samples = int ( fields . get ( '<STR_LIT>' , <NUM_LIT:0> ) ) <EOL> entry . name = symbol <EOL> entry . image = image <EOL> if prefix < len ( self . stack ) : <EOL> del self . stack [ prefix : ] <EOL> if prefix == len ( self . stack ) : <EOL> self . stack . append ( entry ) <EOL> if prefix > <NUM_LIT:0> : <EOL> self . add_callee ( self . stack [ prefix - <NUM_LIT:1> ] , entry ) <EOL> self . add_entry ( entry ) <EOL> profile = Profile ( ) <EOL> profile [ SAMPLES ] = <NUM_LIT:0> <EOL> for _function , _callees in self . entries . itervalues ( ) : <EOL> function = Function ( _function . id , _function . name ) <EOL> function [ SAMPLES ] = _function . samples <EOL> profile . add_function ( function ) <EOL> profile [ SAMPLES ] += _function . samples <EOL> if _function . image : <EOL> function [ MODULE ] = os . path . basename ( _function . image ) <EOL> for _callee in _callees . itervalues ( ) : <EOL> call = Call ( _callee . id ) <EOL> call [ SAMPLES ] = _callee . samples <EOL> function . add_call ( call ) <EOL> profile . validate ( ) <EOL> profile . find_cycles ( ) <EOL> profile . ratio ( TIME_RATIO , SAMPLES ) <EOL> profile . call_ratios ( SAMPLES ) <EOL> profile . integrate ( TOTAL_TIME_RATIO , TIME_RATIO ) <EOL> return profile <EOL> class AQtimeTable : <EOL> def __init__ ( self , name , fields ) : <EOL> self . name = name <EOL> self . fields = fields <EOL> self . field_column = { } <EOL> for column in range ( len ( fields ) ) : <EOL> self . field_column [ fields [ column ] ] = column <EOL> self . rows = [ ] <EOL> def __len__ ( self ) : <EOL> return len ( self . rows ) <EOL> def __iter__ ( self ) : <EOL> for values , children in self . rows : <EOL> fields = { } <EOL> for name , value in zip ( self . fields , values ) : <EOL> fields [ name ] = value <EOL> children = dict ( [ ( child . name , child ) for child in children ] ) <EOL> yield fields , children <EOL> raise StopIteration <EOL> def add_row ( self , values , children = ( ) ) : <EOL> self . rows . append ( ( values , children ) ) <EOL> class AQtimeParser ( XmlParser ) : <EOL> def __init__ ( self , stream ) : <EOL> XmlParser . __init__ ( self , stream ) <EOL> self . tables = { } <EOL> def parse ( self ) : <EOL> self . element_start ( '<STR_LIT>' ) <EOL> self . parse_headers ( ) <EOL> results = self . parse_results ( ) <EOL> self . element_end ( '<STR_LIT>' ) <EOL> return self . build_profile ( results ) <EOL> def parse_headers ( self ) : <EOL> self . element_start ( '<STR_LIT>' ) <EOL> while self . token . type == XML_ELEMENT_START : <EOL> self . parse_table_header ( ) <EOL> self . element_end ( '<STR_LIT>' ) <EOL> def parse_table_header ( self ) : <EOL> attrs = self . element_start ( '<STR_LIT>' ) <EOL> name = attrs [ '<STR_LIT>' ] <EOL> id = int ( attrs [ '<STR_LIT>' ] ) <EOL> field_types = [ ] <EOL> field_names = [ ] <EOL> while self . token . type == XML_ELEMENT_START : <EOL> field_type , field_name = self . parse_table_field ( ) <EOL> field_types . append ( field_type ) <EOL> field_names . append ( field_name ) <EOL> self . element_end ( '<STR_LIT>' ) <EOL> self . tables [ id ] = name , field_types , field_names <EOL> def parse_table_field ( self ) : <EOL> attrs = self . element_start ( '<STR_LIT>' ) <EOL> type = attrs [ '<STR_LIT>' ] <EOL> name = self . character_data ( ) <EOL> self . element_end ( '<STR_LIT>' ) <EOL> return type , name <EOL> def parse_results ( self ) : <EOL> self . element_start ( '<STR_LIT>' ) <EOL> table = self . parse_data ( ) <EOL> self . element_end ( '<STR_LIT>' ) <EOL> return table <EOL> def parse_data ( self ) : <EOL> rows = [ ] <EOL> attrs = self . element_start ( '<STR_LIT>' ) <EOL> table_id = int ( attrs [ '<STR_LIT>' ] ) <EOL> table_name , field_types , field_names = self . tables [ table_id ] <EOL> table = AQtimeTable ( table_name , field_names ) <EOL> while self . token . type == XML_ELEMENT_START : <EOL> row , children = self . parse_row ( field_types ) <EOL> table . add_row ( row , children ) <EOL> self . element_end ( '<STR_LIT>' ) <EOL> return table <EOL> def parse_row ( self , field_types ) : <EOL> row = [ None ] * len ( field_types ) <EOL> children = [ ] <EOL> self . element_start ( '<STR_LIT>' ) <EOL> while self . token . type == XML_ELEMENT_START : <EOL> if self . token . name_or_data == '<STR_LIT>' : <EOL> field_id , field_value = self . parse_field ( field_types ) <EOL> row [ field_id ] = field_value <EOL> elif self . token . name_or_data == '<STR_LIT>' : <EOL> children = self . parse_children ( ) <EOL> else : <EOL> raise XmlTokenMismatch ( "<STR_LIT>" , self . token ) <EOL> self . element_end ( '<STR_LIT>' ) <EOL> return row , children <EOL> def parse_field ( self , field_types ) : <EOL> attrs = self . element_start ( '<STR_LIT>' ) <EOL> id = int ( attrs [ '<STR_LIT>' ] ) <EOL> type = field_types [ id ] <EOL> value = self . character_data ( ) <EOL> if type == '<STR_LIT>' : <EOL> value = int ( value ) <EOL> elif type == '<STR_LIT>' : <EOL> value = float ( value ) <EOL> elif type == '<STR_LIT>' : <EOL> value = int ( value ) <EOL> elif type == '<STR_LIT>' : <EOL> pass <EOL> else : <EOL> assert False <EOL> self . element_end ( '<STR_LIT>' ) <EOL> return id , value <EOL> def parse_children ( self ) : <EOL> children = [ ] <EOL> self . element_start ( '<STR_LIT>' ) <EOL> while self . token . type == XML_ELEMENT_START : <EOL> table = self . parse_data ( ) <EOL> assert table . name not in children <EOL> children . append ( table ) <EOL> self . element_end ( '<STR_LIT>' ) <EOL> return children <EOL> def build_profile ( self , results ) : <EOL> assert results . name == '<STR_LIT>' <EOL> profile = Profile ( ) <EOL> profile [ TIME ] = <NUM_LIT:0.0> <EOL> for fields , tables in results : <EOL> function = self . build_function ( fields ) <EOL> children = tables [ '<STR_LIT>' ] <EOL> for fields , _ in children : <EOL> call = self . build_call ( fields ) <EOL> function . add_call ( call ) <EOL> profile . add_function ( function ) <EOL> profile [ TIME ] = profile [ TIME ] + function [ TIME ] <EOL> profile [ TOTAL_TIME ] = profile [ TIME ] <EOL> profile . ratio ( TOTAL_TIME_RATIO , TOTAL_TIME ) <EOL> return profile <EOL> def build_function ( self , fields ) : <EOL> function = Function ( self . build_id ( fields ) , self . build_name ( fields ) ) <EOL> function [ TIME ] = fields [ '<STR_LIT>' ] <EOL> function [ TOTAL_TIME ] = fields [ '<STR_LIT>' ] <EOL> return function <EOL> def build_call ( self , fields ) : <EOL> call = Call ( self . build_id ( fields ) ) <EOL> call [ TIME ] = fields [ '<STR_LIT>' ] <EOL> call [ TOTAL_TIME ] = fields [ '<STR_LIT>' ] <EOL> return call <EOL> def build_id ( self , fields ) : <EOL> return '<STR_LIT::>' . join ( [ fields [ '<STR_LIT>' ] , fields [ '<STR_LIT>' ] , fields [ '<STR_LIT>' ] ] ) <EOL> def build_name ( self , fields ) : <EOL> return fields [ '<STR_LIT>' ] <EOL> class PstatsParser : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , * filename ) : <EOL> import pstats <EOL> try : <EOL> self . stats = pstats . Stats ( * filename ) <EOL> except ValueError : <EOL> import hotshot . stats <EOL> self . stats = hotshot . stats . load ( filename [ <NUM_LIT:0> ] ) <EOL> self . profile = Profile ( ) <EOL> self . function_ids = { } <EOL> def get_function_name ( self , ( filename , line , name ) ) : <EOL> module = os . path . splitext ( filename ) [ <NUM_LIT:0> ] <EOL> module = os . path . basename ( module ) <EOL> return "<STR_LIT>" % ( module , line , name ) <EOL> def get_function ( self , key ) : <EOL> try : <EOL> id = self . function_ids [ key ] <EOL> except KeyError : <EOL> id = len ( self . function_ids ) <EOL> name = self . get_function_name ( key ) <EOL> function = Function ( id , name ) <EOL> self . profile . functions [ id ] = function <EOL> self . function_ids [ key ] = id <EOL> else : <EOL> function = self . profile . functions [ id ] <EOL> return function <EOL> def parse ( self ) : <EOL> self . profile [ TIME ] = <NUM_LIT:0.0> <EOL> self . profile [ TOTAL_TIME ] = self . stats . total_tt <EOL> for fn , ( cc , nc , tt , ct , callers ) in self . stats . stats . iteritems ( ) : <EOL> callee = self . get_function ( fn ) <EOL> callee [ CALLS ] = nc <EOL> callee [ TOTAL_TIME ] = ct <EOL> callee [ TIME ] = tt <EOL> self . profile [ TIME ] += tt <EOL> self . profile [ TOTAL_TIME ] = max ( self . profile [ TOTAL_TIME ] , ct ) <EOL> for fn , value in callers . iteritems ( ) : <EOL> caller = self . get_function ( fn ) <EOL> call = Call ( callee . id ) <EOL> if isinstance ( value , tuple ) : <EOL> for i in xrange ( <NUM_LIT:0> , len ( value ) , <NUM_LIT:4> ) : <EOL> nc , cc , tt , ct = value [ i : i + <NUM_LIT:4> ] <EOL> if CALLS in call : <EOL> call [ CALLS ] += cc <EOL> else : <EOL> call [ CALLS ] = cc <EOL> if TOTAL_TIME in call : <EOL> call [ TOTAL_TIME ] += ct <EOL> else : <EOL> call [ TOTAL_TIME ] = ct <EOL> else : <EOL> call [ CALLS ] = value <EOL> call [ TOTAL_TIME ] = ratio ( value , nc ) * ct <EOL> caller . add_call ( call ) <EOL> self . profile . validate ( ) <EOL> self . profile . ratio ( TIME_RATIO , TIME ) <EOL> self . profile . ratio ( TOTAL_TIME_RATIO , TOTAL_TIME ) <EOL> return self . profile <EOL> class Theme : <EOL> def __init__ ( self , <EOL> bgcolor = ( <NUM_LIT:0.0> , <NUM_LIT:0.0> , <NUM_LIT:1.0> ) , <EOL> mincolor = ( <NUM_LIT:0.0> , <NUM_LIT:0.0> , <NUM_LIT:0.0> ) , <EOL> maxcolor = ( <NUM_LIT:0.0> , <NUM_LIT:0.0> , <NUM_LIT:1.0> ) , <EOL> fontname = "<STR_LIT>" , <EOL> minfontsize = <NUM_LIT> , <EOL> maxfontsize = <NUM_LIT> , <EOL> minpenwidth = <NUM_LIT:0.5> , <EOL> maxpenwidth = <NUM_LIT> , <EOL> gamma = <NUM_LIT> ) : <EOL> self . bgcolor = bgcolor <EOL> self . mincolor = mincolor <EOL> self . maxcolor = maxcolor <EOL> self . fontname = fontname <EOL> self . minfontsize = minfontsize <EOL> self . maxfontsize = maxfontsize <EOL> self . minpenwidth = minpenwidth <EOL> self . maxpenwidth = maxpenwidth <EOL> self . gamma = gamma <EOL> def graph_bgcolor ( self ) : <EOL> return self . hsl_to_rgb ( * self . bgcolor ) <EOL> def graph_fontname ( self ) : <EOL> return self . fontname <EOL> def graph_fontsize ( self ) : <EOL> return self . minfontsize <EOL> def node_bgcolor ( self , weight ) : <EOL> return self . color ( weight ) <EOL> def node_fgcolor ( self , weight ) : <EOL> return self . graph_bgcolor ( ) <EOL> def node_fontsize ( self , weight ) : <EOL> return self . fontsize ( weight ) <EOL> def edge_color ( self , weight ) : <EOL> return self . color ( weight ) <EOL> def edge_fontsize ( self , weight ) : <EOL> return self . fontsize ( weight ) <EOL> def edge_penwidth ( self , weight ) : <EOL> return max ( weight * self . maxpenwidth , self . minpenwidth ) <EOL> def edge_arrowsize ( self , weight ) : <EOL> return <NUM_LIT:0.5> * math . sqrt ( self . edge_penwidth ( weight ) ) <EOL> def fontsize ( self , weight ) : <EOL> return max ( weight ** <NUM_LIT:2> * self . maxfontsize , self . minfontsize ) <EOL> def color ( self , weight ) : <EOL> weight = min ( max ( weight , <NUM_LIT:0.0> ) , <NUM_LIT:1.0> ) <EOL> hmin , smin , lmin = self . mincolor <EOL> hmax , smax , lmax = self . maxcolor <EOL> h = hmin + weight * ( hmax - hmin ) <EOL> s = smin + weight * ( smax - smin ) <EOL> l = lmin + weight * ( lmax - lmin ) <EOL> return self . hsl_to_rgb ( h , s , l ) <EOL> def hsl_to_rgb ( self , h , s , l ) : <EOL> """<STR_LIT>""" <EOL> h = h % <NUM_LIT:1.0> <EOL> s = min ( max ( s , <NUM_LIT:0.0> ) , <NUM_LIT:1.0> ) <EOL> l = min ( max ( l , <NUM_LIT:0.0> ) , <NUM_LIT:1.0> ) <EOL> if l <= <NUM_LIT:0.5> : <EOL> m2 = l * ( s + <NUM_LIT:1.0> ) <EOL> else : <EOL> m2 = l + s - l * s <EOL> m1 = l * <NUM_LIT> - m2 <EOL> r = self . _hue_to_rgb ( m1 , m2 , h + <NUM_LIT:1.0> / <NUM_LIT> ) <EOL> g = self . _hue_to_rgb ( m1 , m2 , h ) <EOL> b = self . _hue_to_rgb ( m1 , m2 , h - <NUM_LIT:1.0> / <NUM_LIT> ) <EOL> r **= self . gamma <EOL> g **= self . gamma <EOL> b **= self . gamma <EOL> return ( r , g , b ) <EOL> def _hue_to_rgb ( self , m1 , m2 , h ) : <EOL> if h < <NUM_LIT:0.0> : <EOL> h += <NUM_LIT:1.0> <EOL> elif h > <NUM_LIT:1.0> : <EOL> h -= <NUM_LIT:1.0> <EOL> if h * <NUM_LIT:6> < <NUM_LIT:1.0> : <EOL> return m1 + ( m2 - m1 ) * h * <NUM_LIT> <EOL> elif h * <NUM_LIT:2> < <NUM_LIT:1.0> : <EOL> return m2 <EOL> elif h * <NUM_LIT:3> < <NUM_LIT> : <EOL> return m1 + ( m2 - m1 ) * ( <NUM_LIT> / <NUM_LIT> - h ) * <NUM_LIT> <EOL> else : <EOL> return m1 <EOL> TEMPERATURE_COLORMAP = Theme ( <EOL> mincolor = ( <NUM_LIT> / <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ) , <EOL> maxcolor = ( <NUM_LIT:0.0> , <NUM_LIT:1.0> , <NUM_LIT:0.5> ) , <EOL> gamma = <NUM_LIT:1.0> <EOL> ) <EOL> PINK_COLORMAP = Theme ( <EOL> mincolor = ( <NUM_LIT:0.0> , <NUM_LIT:1.0> , <NUM_LIT> ) , <EOL> maxcolor = ( <NUM_LIT:0.0> , <NUM_LIT:1.0> , <NUM_LIT:0.5> ) , <EOL> ) <EOL> GRAY_COLORMAP = Theme ( <EOL> mincolor = ( <NUM_LIT:0.0> , <NUM_LIT:0.0> , <NUM_LIT> ) , <EOL> maxcolor = ( <NUM_LIT:0.0> , <NUM_LIT:0.0> , <NUM_LIT:0.0> ) , <EOL> ) <EOL> BW_COLORMAP = Theme ( <EOL> minfontsize = <NUM_LIT> , <EOL> maxfontsize = <NUM_LIT> , <EOL> mincolor = ( <NUM_LIT:0.0> , <NUM_LIT:0.0> , <NUM_LIT:0.0> ) , <EOL> maxcolor = ( <NUM_LIT:0.0> , <NUM_LIT:0.0> , <NUM_LIT:0.0> ) , <EOL> minpenwidth = <NUM_LIT:0.1> , <EOL> maxpenwidth = <NUM_LIT> , <EOL> ) <EOL> class DotWriter : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , fp ) : <EOL> self . fp = fp <EOL> def graph ( self , profile , theme ) : <EOL> self . begin_graph ( ) <EOL> fontname = theme . graph_fontname ( ) <EOL> self . attr ( '<STR_LIT>' , fontname = fontname , ranksep = <NUM_LIT> , nodesep = <NUM_LIT> ) <EOL> self . attr ( '<STR_LIT>' , fontname = fontname , shape = "<STR_LIT>" , style = "<STR_LIT>" , fontcolor = "<STR_LIT>" , width = <NUM_LIT:0> , height = <NUM_LIT:0> ) <EOL> self . attr ( '<STR_LIT>' , fontname = fontname ) <EOL> for function in profile . functions . itervalues ( ) : <EOL> labels = [ ] <EOL> for event in PROCESS , MODULE : <EOL> if event in function . events : <EOL> label = event . format ( function [ event ] ) <EOL> labels . append ( label ) <EOL> labels . append ( function . name ) <EOL> for event in TOTAL_TIME_RATIO , TIME_RATIO , CALLS : <EOL> if event in function . events : <EOL> label = event . format ( function [ event ] ) <EOL> labels . append ( label ) <EOL> try : <EOL> weight = function [ PRUNE_RATIO ] <EOL> except UndefinedEvent : <EOL> weight = <NUM_LIT:0.0> <EOL> label = '<STR_LIT:\n>' . join ( labels ) <EOL> self . node ( function . id , <EOL> label = label , <EOL> color = self . color ( theme . node_bgcolor ( weight ) ) , <EOL> fontcolor = self . color ( theme . node_fgcolor ( weight ) ) , <EOL> fontsize = "<STR_LIT>" % theme . node_fontsize ( weight ) , <EOL> ) <EOL> for call in function . calls . itervalues ( ) : <EOL> callee = profile . functions [ call . callee_id ] <EOL> labels = [ ] <EOL> for event in TOTAL_TIME_RATIO , CALLS : <EOL> if event in call . events : <EOL> label = event . format ( call [ event ] ) <EOL> labels . append ( label ) <EOL> try : <EOL> weight = call [ PRUNE_RATIO ] <EOL> except UndefinedEvent : <EOL> try : <EOL> weight = callee [ PRUNE_RATIO ] <EOL> except UndefinedEvent : <EOL> weight = <NUM_LIT:0.0> <EOL> label = '<STR_LIT:\n>' . join ( labels ) <EOL> self . edge ( function . id , call . callee_id , <EOL> label = label , <EOL> color = self . color ( theme . edge_color ( weight ) ) , <EOL> fontcolor = self . color ( theme . edge_color ( weight ) ) , <EOL> fontsize = "<STR_LIT>" % theme . edge_fontsize ( weight ) , <EOL> penwidth = "<STR_LIT>" % theme . edge_penwidth ( weight ) , <EOL> labeldistance = "<STR_LIT>" % theme . edge_penwidth ( weight ) , <EOL> arrowsize = "<STR_LIT>" % theme . edge_arrowsize ( weight ) , <EOL> ) <EOL> self . end_graph ( ) <EOL> def begin_graph ( self ) : <EOL> self . write ( '<STR_LIT>' ) <EOL> def end_graph ( self ) : <EOL> self . write ( '<STR_LIT>' ) <EOL> def attr ( self , what , ** attrs ) : <EOL> self . write ( "<STR_LIT:\t>" ) <EOL> self . write ( what ) <EOL> self . attr_list ( attrs ) <EOL> self . write ( "<STR_LIT>" ) <EOL> def node ( self , node , ** attrs ) : <EOL> self . write ( "<STR_LIT:\t>" ) <EOL> self . id ( node ) <EOL> self . attr_list ( attrs ) <EOL> self . write ( "<STR_LIT>" ) <EOL> def edge ( self , src , dst , ** attrs ) : <EOL> self . write ( "<STR_LIT:\t>" ) <EOL> self . id ( src ) <EOL> self . write ( "<STR_LIT>" ) <EOL> self . id ( dst ) <EOL> self . attr_list ( attrs ) <EOL> self . write ( "<STR_LIT>" ) <EOL> def attr_list ( self , attrs ) : <EOL> if not attrs : <EOL> return <EOL> self . write ( '<STR_LIT>' ) <EOL> first = True <EOL> for name , value in attrs . iteritems ( ) : <EOL> if first : <EOL> first = False <EOL> else : <EOL> self . write ( "<STR_LIT:U+002CU+0020>" ) <EOL> self . id ( name ) <EOL> self . write ( '<STR_LIT:=>' ) <EOL> self . id ( value ) <EOL> self . write ( '<STR_LIT:]>' ) <EOL> def id ( self , id ) : <EOL> if isinstance ( id , ( int , float ) ) : <EOL> s = str ( id ) <EOL> elif isinstance ( id , basestring ) : <EOL> if id . isalnum ( ) : <EOL> s = id <EOL> else : <EOL> s = self . escape ( id ) <EOL> else : <EOL> raise TypeError <EOL> self . write ( s ) <EOL> def color ( self , ( r , g , b ) ) : <EOL> def float2int ( f ) : <EOL> if f <= <NUM_LIT:0.0> : <EOL> return <NUM_LIT:0> <EOL> if f >= <NUM_LIT:1.0> : <EOL> return <NUM_LIT:255> <EOL> return int ( <NUM_LIT> * f + <NUM_LIT:0.5> ) <EOL> return "<STR_LIT:#>" + "<STR_LIT>" . join ( [ "<STR_LIT>" % float2int ( c ) for c in ( r , g , b ) ] ) <EOL> def escape ( self , s ) : <EOL> s = s . encode ( '<STR_LIT:utf-8>' ) <EOL> s = s . replace ( '<STR_LIT:\\>' , r'<STR_LIT:\\>' ) <EOL> s = s . replace ( '<STR_LIT:\n>' , r'<STR_LIT:\n>' ) <EOL> s = s . replace ( '<STR_LIT:\t>' , r'<STR_LIT:\t>' ) <EOL> s = s . replace ( '<STR_LIT:">' , r'<STR_LIT>' ) <EOL> return '<STR_LIT:">' + s + '<STR_LIT:">' <EOL> def write ( self , s ) : <EOL> self . fp . write ( s ) <EOL> class Main : <EOL> """<STR_LIT>""" <EOL> themes = { <EOL> "<STR_LIT>" : TEMPERATURE_COLORMAP , <EOL> "<STR_LIT>" : PINK_COLORMAP , <EOL> "<STR_LIT>" : GRAY_COLORMAP , <EOL> "<STR_LIT>" : BW_COLORMAP , <EOL> } <EOL> def main ( self ) : <EOL> """<STR_LIT>""" <EOL> parser = optparse . OptionParser ( <EOL> usage = "<STR_LIT>" , <EOL> version = "<STR_LIT>" % __version__ ) <EOL> parser . add_option ( <EOL> '<STR_LIT>' , '<STR_LIT>' , metavar = '<STR_LIT>' , <EOL> type = "<STR_LIT:string>" , dest = "<STR_LIT>" , <EOL> help = "<STR_LIT>" ) <EOL> parser . add_option ( <EOL> '<STR_LIT>' , '<STR_LIT>' , metavar = '<STR_LIT>' , <EOL> type = "<STR_LIT:float>" , dest = "<STR_LIT>" , default = <NUM_LIT:0.5> , <EOL> help = "<STR_LIT>" ) <EOL> parser . add_option ( <EOL> '<STR_LIT>' , '<STR_LIT>' , metavar = '<STR_LIT>' , <EOL> type = "<STR_LIT:float>" , dest = "<STR_LIT>" , default = <NUM_LIT:0.1> , <EOL> help = "<STR_LIT>" ) <EOL> parser . add_option ( <EOL> '<STR_LIT>' , '<STR_LIT>' , <EOL> type = "<STR_LIT>" , choices = ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) , <EOL> dest = "<STR_LIT>" , default = "<STR_LIT>" , <EOL> help = "<STR_LIT>" ) <EOL> parser . add_option ( <EOL> '<STR_LIT:-c>' , '<STR_LIT>' , <EOL> type = "<STR_LIT>" , choices = ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) , <EOL> dest = "<STR_LIT>" , default = "<STR_LIT>" , <EOL> help = "<STR_LIT>" ) <EOL> parser . add_option ( <EOL> '<STR_LIT>' , '<STR_LIT>' , <EOL> action = "<STR_LIT:store_true>" , <EOL> dest = "<STR_LIT>" , default = False , <EOL> help = "<STR_LIT>" ) <EOL> parser . add_option ( <EOL> '<STR_LIT>' , '<STR_LIT>' , <EOL> action = "<STR_LIT:store_true>" , <EOL> dest = "<STR_LIT>" , default = False , <EOL> help = "<STR_LIT>" ) <EOL> ( self . options , self . args ) = parser . parse_args ( sys . argv [ <NUM_LIT:1> : ] ) <EOL> if len ( self . args ) > <NUM_LIT:1> and self . options . format != '<STR_LIT>' : <EOL> parser . error ( '<STR_LIT>' ) <EOL> try : <EOL> self . theme = self . themes [ self . options . theme ] <EOL> except KeyError : <EOL> parser . error ( '<STR_LIT>' % self . options . theme ) <EOL> if self . options . format == '<STR_LIT>' : <EOL> if not self . args : <EOL> fp = sys . stdin <EOL> else : <EOL> fp = open ( self . args [ <NUM_LIT:0> ] , '<STR_LIT>' ) <EOL> parser = GprofParser ( fp ) <EOL> elif self . options . format == '<STR_LIT>' : <EOL> if not self . args : <EOL> fp = sys . stdin <EOL> else : <EOL> fp = open ( self . args [ <NUM_LIT:0> ] , '<STR_LIT>' ) <EOL> parser = OprofileParser ( fp ) <EOL> elif self . options . format == '<STR_LIT>' : <EOL> if not self . args : <EOL> parser . error ( '<STR_LIT>' ) <EOL> parser = PstatsParser ( * self . args ) <EOL> elif self . options . format == '<STR_LIT>' : <EOL> if not self . args : <EOL> fp = sys . stdin <EOL> else : <EOL> fp = open ( self . args [ <NUM_LIT:0> ] , '<STR_LIT>' ) <EOL> parser = SharkParser ( fp ) <EOL> elif self . options . format == '<STR_LIT>' : <EOL> if not self . args : <EOL> fp = sys . stdin <EOL> else : <EOL> fp = open ( self . args [ <NUM_LIT:0> ] , '<STR_LIT>' ) <EOL> parser = AQtimeParser ( fp ) <EOL> else : <EOL> parser . error ( '<STR_LIT>' % self . options . format ) <EOL> self . profile = parser . parse ( ) <EOL> if self . options . output is None : <EOL> self . output = sys . stdout <EOL> else : <EOL> self . output = open ( self . options . output , '<STR_LIT>' ) <EOL> self . write_graph ( ) <EOL> _parenthesis_re = re . compile ( r'<STR_LIT>' ) <EOL> _angles_re = re . compile ( r'<STR_LIT>' ) <EOL> _const_re = re . compile ( r'<STR_LIT>' ) <EOL> def strip_function_name ( self , name ) : <EOL> """<STR_LIT>""" <EOL> while True : <EOL> name , n = self . _parenthesis_re . subn ( '<STR_LIT>' , name ) <EOL> if not n : <EOL> break <EOL> name = self . _const_re . sub ( '<STR_LIT>' , name ) <EOL> while True : <EOL> name , n = self . _angles_re . subn ( '<STR_LIT>' , name ) <EOL> if not n : <EOL> break <EOL> return name <EOL> def wrap_function_name ( self , name ) : <EOL> """<STR_LIT>""" <EOL> if len ( name ) > <NUM_LIT:32> : <EOL> ratio = <NUM_LIT> / <NUM_LIT> <EOL> height = max ( int ( len ( name ) / ( <NUM_LIT:1.0> - ratio ) + <NUM_LIT:0.5> ) , <NUM_LIT:1> ) <EOL> width = max ( len ( name ) / height , <NUM_LIT:32> ) <EOL> name = textwrap . fill ( name , width , break_long_words = False ) <EOL> name = name . replace ( "<STR_LIT:U+002CU+0020>" , "<STR_LIT:U+002C>" ) <EOL> name = name . replace ( "<STR_LIT>" , "<STR_LIT>" ) <EOL> name = name . replace ( "<STR_LIT>" , "<STR_LIT>" ) <EOL> return name <EOL> def compress_function_name ( self , name ) : <EOL> """<STR_LIT>""" <EOL> if self . options . strip : <EOL> name = self . strip_function_name ( name ) <EOL> if self . options . wrap : <EOL> name = self . wrap_function_name ( name ) <EOL> return name <EOL> def write_graph ( self ) : <EOL> dot = DotWriter ( self . output ) <EOL> profile = self . profile <EOL> profile . prune ( self . options . node_thres / <NUM_LIT> , self . options . edge_thres / <NUM_LIT> ) <EOL> for function in profile . functions . itervalues ( ) : <EOL> function . name = self . compress_function_name ( function . name ) <EOL> dot . graph ( profile , self . theme ) <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> Main ( ) . main ( ) </s>
