<s> '''<STR_LIT>''' <EOL> from optparse import OptionParser <EOL> import logging <EOL> import sys <EOL> import os <EOL> import re <EOL> import matplotlib . pyplot as plt <EOL> parent_path = os . path . abspath ( os . path . join ( os . path . dirname ( __file__ ) , '<STR_LIT:..>' ) ) <EOL> sys . path . insert ( <NUM_LIT:0> , parent_path ) <EOL> from certfuzz . campaign . config . bff_config import read_config_options <EOL> logger = logging . getLogger ( __name__ ) <EOL> logger . setLevel ( logging . INFO ) <EOL> hdlr = logging . StreamHandler ( sys . stdout ) <EOL> logger . addHandler ( hdlr ) <EOL> def parse_options ( ) : <EOL> usage = "<STR_LIT>" <EOL> parser = OptionParser ( usage ) <EOL> parser . add_option ( "<STR_LIT>" , "<STR_LIT>" , dest = "<STR_LIT>" , help = "<STR_LIT>" , action = '<STR_LIT:store_true>' , default = False ) <EOL> parser . add_option ( "<STR_LIT>" , "<STR_LIT>" , dest = "<STR_LIT>" , help = "<STR_LIT>" , action = '<STR_LIT:store_true>' , default = False ) <EOL> parser . add_option ( '<STR_LIT>' , '<STR_LIT>' , dest = '<STR_LIT>' , help = '<STR_LIT>' ) <EOL> parser . add_option ( "<STR_LIT>" , "<STR_LIT>" , dest = "<STR_LIT>" , help = "<STR_LIT>" , metavar = '<STR_LIT>' ) <EOL> parser . add_option ( '<STR_LIT>' , '<STR_LIT>' , dest = '<STR_LIT>' , help = "<STR_LIT>" , action = '<STR_LIT:store_true>' , default = False ) <EOL> parser . add_option ( '<STR_LIT>' , '<STR_LIT>' , dest = '<STR_LIT>' , help = "<STR_LIT>" , action = '<STR_LIT:store_true>' , default = False ) <EOL> parser . add_option ( '<STR_LIT>' , '<STR_LIT>' , dest = '<STR_LIT>' , help = '<STR_LIT>' , action = '<STR_LIT>' , default = True ) <EOL> parser . add_option ( '<STR_LIT>' , '<STR_LIT>' , dest = "<STR_LIT>" , help = "<STR_LIT>" , metavar = '<STR_LIT>' ) <EOL> options , args = parser . parse_args ( ) <EOL> if not len ( args ) : <EOL> parser . print_help ( ) <EOL> parser . error ( "<STR_LIT>" ) <EOL> return options , args <EOL> def plot ( options , crash_id , log ) : <EOL> logfile = LogFile ( log ) <EOL> starts = [ ] <EOL> mins = [ ] <EOL> targets = [ ] <EOL> currents = [ ] <EOL> for item in logfile . results : <EOL> [ x . append ( y ) for x , y in zip ( ( starts , mins , targets , currents ) , item ) ] <EOL> logger . debug ( "<STR_LIT>" ) <EOL> [ logger . debug ( '<STR_LIT:%s>' , str ( x ) ) for x in ( starts , mins , targets , currents ) ] <EOL> fig = plt . figure ( figsize = ( <NUM_LIT:8> , <NUM_LIT:8> ) ) <EOL> ax = fig . add_subplot ( <NUM_LIT:1> , <NUM_LIT:1> , <NUM_LIT:1> ) <EOL> if not options . linear_y : <EOL> logger . info ( '<STR_LIT>' ) <EOL> ax . set_yscale ( '<STR_LIT>' ) <EOL> if options . log_x : <EOL> logger . info ( '<STR_LIT>' ) <EOL> ax . set_xscale ( '<STR_LIT>' ) <EOL> logger . info ( '<STR_LIT>' ) <EOL> plt . xlabel ( '<STR_LIT>' ) <EOL> plt . ylabel ( '<STR_LIT>' ) <EOL> title = '<STR_LIT>' <EOL> if options . include_crash_id : <EOL> title = '<STR_LIT:\n>' . join ( ( crash_id , title ) ) <EOL> plt . title ( title ) <EOL> plt . plot ( starts , label = '<STR_LIT>' ) <EOL> plt . plot ( mins , label = '<STR_LIT>' ) <EOL> plt . plot ( targets , label = '<STR_LIT>' ) <EOL> plt . plot ( currents , label = '<STR_LIT>' ) <EOL> logger . debug ( '<STR_LIT>' ) <EOL> plt . legend ( ) <EOL> logger . debug ( '<STR_LIT>' ) <EOL> plt . show ( ) <EOL> class Line ( ) : <EOL> def __init__ ( self , line ) : <EOL> self . line = line . strip ( ) <EOL> self . value = False <EOL> self . _process ( ) <EOL> def _process ( self ) : <EOL> m = re . match ( '<STR_LIT>' , self . line ) <EOL> if not m : <EOL> return <EOL> ( start , minimum , target , current ) = ( int ( x ) for x in ( m . group ( <NUM_LIT:1> ) , m . group ( <NUM_LIT:2> ) , m . group ( <NUM_LIT:3> ) , m . group ( <NUM_LIT:4> ) ) ) <EOL> logger . debug ( '<STR_LIT>' , start ) <EOL> logger . debug ( '<STR_LIT>' , minimum ) <EOL> logger . debug ( '<STR_LIT>' , target ) <EOL> logger . debug ( '<STR_LIT>' , current ) <EOL> self . value = ( start , minimum , target , current ) <EOL> class LogFile ( ) : <EOL> def __init__ ( self , logfile ) : <EOL> self . file = logfile <EOL> self . results = [ ] <EOL> self . uniqresults = [ ] <EOL> self . results_read = False <EOL> self . _process ( ) <EOL> logger . debug ( '<STR_LIT>' , self . file ) <EOL> def _process ( self ) : <EOL> if self . results_read : <EOL> return self . results <EOL> f = open ( self . file , '<STR_LIT:r>' ) <EOL> try : <EOL> for l in f . readlines ( ) : <EOL> result = Line ( l ) . value <EOL> if result : <EOL> self . results . append ( result ) <EOL> self . results_read = True <EOL> finally : <EOL> f . close ( ) <EOL> def unique_results ( self ) : <EOL> if self . uniqresults : <EOL> return self . uniqresults <EOL> self . uniqresults = list ( set ( self . results ) ) <EOL> return self . uniqresults <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> options , args = parse_options ( ) <EOL> if options . debug : <EOL> logger . setLevel ( logging . DEBUG ) <EOL> elif options . verbose : <EOL> logger . setLevel ( logging . INFO ) <EOL> if options . cfgfile : <EOL> cfg_file = options . cfgfile <EOL> else : <EOL> cfg_file = os . path . join ( parent_path , '<STR_LIT>' , '<STR_LIT>' ) <EOL> if options . dir : <EOL> result_dir = options . dir <EOL> else : <EOL> logger . info ( '<STR_LIT>' , cfg_file ) <EOL> cfg = read_config_options ( cfg_file ) <EOL> result_dir = cfg . crashers_dir <EOL> logger . info ( '<STR_LIT>' , result_dir ) <EOL> log = None <EOL> crash_id = None <EOL> if len ( args ) : <EOL> crash_id = args . pop ( <NUM_LIT:0> ) <EOL> logger . debug ( '<STR_LIT>' , crash_id ) <EOL> crashdir = os . path . join ( result_dir , crash_id ) <EOL> if not os . path . isdir ( crashdir ) : <EOL> logger . debug ( '<STR_LIT>' , crashdir ) <EOL> raise <EOL> logger . debug ( '<STR_LIT>' , crashdir ) <EOL> log = os . path . join ( crashdir , '<STR_LIT>' ) <EOL> elif options . infile : <EOL> crash_id = os . path . basename ( options . infile ) <EOL> log = options . infile <EOL> if not os . path . exists ( log ) : <EOL> logger . warning ( '<STR_LIT>' , log ) <EOL> raise <EOL> logger . info ( '<STR_LIT>' , log ) <EOL> plot ( options , crash_id , log ) <EOL> logger . info ( '<STR_LIT>' ) </s>
