<s> """<STR_LIT>""" <EOL> import sys <EOL> import re <EOL> import matplotlib . pyplot as plt <EOL> from telesphorus . helpers import path_utils <EOL> calls = [ ] <EOL> GLOBAL = [ ] <EOL> def main ( argv = sys . argv ) : <EOL> """<STR_LIT>""" <EOL> if len ( argv ) != <NUM_LIT:3> : <EOL> usage ( argv ) <EOL> for i in range ( len ( argv ) ) : <EOL> if argv [ i ] == "<STR_LIT>" : <EOL> trace_dir = argv [ i + <NUM_LIT:1> ] <EOL> path_utils . walktree ( trace_dir , build_from_file ) <EOL> for c in calls : <EOL> print >> fw , c [ <NUM_LIT:0> ] , GLOBAL [ c [ <NUM_LIT:1> ] ] <EOL> fw . close ( ) <EOL> if argv [ i ] == "<STR_LIT>" : <EOL> csv = argv [ i + <NUM_LIT:1> ] <EOL> fw = open ( csv , "<STR_LIT:r>" ) <EOL> build_from_csv ( csv ) <EOL> points = [ ] <EOL> for call in calls : <EOL> name = call [ <NUM_LIT:1> ] <EOL> time = int ( call [ <NUM_LIT:0> ] ) <EOL> points . append ( [ time , name ] ) <EOL> plt . plot ( map ( lambda c : c [ <NUM_LIT:0> ] , points ) , map ( lambda c : c [ <NUM_LIT:1> ] , points ) , '<STR_LIT>' , markersize = <NUM_LIT:1> , label = None ) <EOL> plt . xlabel ( '<STR_LIT>' ) <EOL> plt . xscale ( '<STR_LIT>' ) <EOL> plt . ylabel ( '<STR_LIT>' ) <EOL> plt . title ( '<STR_LIT>' ) <EOL> plt . savefig ( '<STR_LIT>' , format = '<STR_LIT>' ) <EOL> def build_from_csv ( filename ) : <EOL> fr = open ( filename , "<STR_LIT:r>" ) <EOL> for line in fr : <EOL> call = line . split ( '<STR_LIT:U+0020>' ) [ <NUM_LIT:1> ] <EOL> time = line . split ( '<STR_LIT:U+0020>' ) [ <NUM_LIT:0> ] <EOL> if call not in GLOBAL : <EOL> GLOBAL . append ( call ) <EOL> calls . append ( [ time , GLOBAL . index ( call ) ] ) <EOL> fr . close ( ) <EOL> def build_from_file ( filename ) : <EOL> for ( call , time ) in yield_timed_calls ( filename ) : <EOL> if call not in GLOBAL : <EOL> GLOBAL . append ( call ) <EOL> calls . append ( [ int ( time ) , GLOBAL . index ( call ) ] ) <EOL> def yield_timed_calls ( filename ) : <EOL> try : <EOL> f = open ( filename ) <EOL> except IOError , error : <EOL> print >> sys . stderr , "<STR_LIT>" % error <EOL> return <EOL> for line in f : <EOL> try : <EOL> if len ( line . split ( '<STR_LIT::>' ) ) > <NUM_LIT:5> : <EOL> continue <EOL> labels = line . split ( '<STR_LIT::>' ) [ : <NUM_LIT:3> ] <EOL> except Exception , error : <EOL> print >> sys . stderr , "<STR_LIT>" , error , filename <EOL> return <EOL> if labels [ <NUM_LIT:1> : ] in [ [ '<STR_LIT>' , '<STR_LIT:T>' ] ] : <EOL> if len ( line . split ( '<STR_LIT::>' ) ) != <NUM_LIT:5> : <EOL> continue <EOL> try : <EOL> call = line . split ( '<STR_LIT::>' ) [ <NUM_LIT:3> ] + '<STR_LIT>' <EOL> if call [ : <NUM_LIT:11> ] == "<STR_LIT>" : <EOL> call = "<STR_LIT>" <EOL> else : <EOL> call = re . sub ( r'<STR_LIT>' , '<STR_LIT::>' , call ) <EOL> time = line . split ( '<STR_LIT::>' ) [ <NUM_LIT:4> ] <EOL> msec = int ( time . split ( '<STR_LIT:.>' ) [ <NUM_LIT:0> ] ) * <NUM_LIT:10> ** <NUM_LIT:6> + int ( time . split ( '<STR_LIT:.>' ) [ <NUM_LIT:1> ] ) <EOL> except Exception , error : <EOL> print >> sys . stderr , "<STR_LIT>" , error , filename <EOL> continue <EOL> yield ( call , str ( msec ) ) <EOL> f . close ( ) <EOL> def usage ( argv ) : <EOL> print ( "<STR_LIT>" ) % argv [ <NUM_LIT:0> ] <EOL> sys . exit ( - <NUM_LIT:1> ) <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> sys . exit ( main ( ) ) </s>
