<s> """<STR_LIT>""" <EOL> import re <EOL> import fileinput <EOL> from datetime import datetime <EOL> try : <EOL> from sqlalchemy . ext . declarative import declarative_base <EOL> from sqlalchemy . orm import sessionmaker , relation <EOL> from sqlalchemy import create_engine <EOL> from sqlalchemy import Column , Integer , String , Float , DateTime <EOL> from sqlalchemy import ForeignKey , UniqueConstraint <EOL> except ImportError : <EOL> print "<STR_LIT>" <EOL> Base = declarative_base ( ) <EOL> class GlobalConfig ( Base ) : <EOL> """<STR_LIT>""" <EOL> __tablename__ = '<STR_LIT>' <EOL> id = Column ( Integer , nullable = False , primary_key = True ) <EOL> run_time = Column ( Integer , nullable = False ) <EOL> rampup = Column ( Integer , nullable = False ) <EOL> results_ts_interval = Column ( Integer , nullable = False ) <EOL> user_group_configs = relation ( "<STR_LIT>" , <EOL> primaryjoin = "<STR_LIT>" ) <EOL> results = relation ( "<STR_LIT>" , <EOL> primaryjoin = "<STR_LIT>" ) <EOL> def __init__ ( self , run_time = None , rampup = None , results_ts_interval = None ) : <EOL> self . run_time = str ( run_time ) <EOL> self . rampup = int ( rampup ) <EOL> """<STR_LIT>""" <EOL> self . results_ts_interval = int ( results_ts_interval ) <EOL> def __repr__ ( self ) : <EOL> return "<STR_LIT>" % ( <EOL> self . run_time , self . rampup , self . results_ts_interval ) <EOL> class UserGroupConfig ( Base ) : <EOL> """<STR_LIT>""" <EOL> __tablename__ = '<STR_LIT>' <EOL> id = Column ( Integer , nullable = False , primary_key = True ) <EOL> mechanize_global_configs_id = Column ( Integer , ForeignKey ( '<STR_LIT>' ) , nullable = False ) <EOL> user_group = Column ( String ( <NUM_LIT:50> ) , nullable = False ) <EOL> threads = Column ( Integer , nullable = False ) <EOL> script = Column ( String ( <NUM_LIT:50> ) , nullable = False ) <EOL> def __init__ ( self , user_group = None , threads = None , script = None ) : <EOL> self . user_group = str ( user_group ) <EOL> self . threads = int ( threads ) <EOL> self . script = str ( script ) <EOL> def __repr__ ( self ) : <EOL> return "<STR_LIT>" % ( <EOL> self . user_group , self . threads , self . script ) <EOL> class ResultRow ( Base ) : <EOL> """<STR_LIT>""" <EOL> __tablename__ = '<STR_LIT>' <EOL> __table_args__ = ( <EOL> UniqueConstraint ( '<STR_LIT>' , '<STR_LIT>' , name = '<STR_LIT>' ) , <EOL> ) <EOL> id = Column ( Integer , nullable = False , primary_key = True ) <EOL> mechanize_global_configs_id = Column ( Integer , <EOL> ForeignKey ( '<STR_LIT>' ) , nullable = False ) <EOL> project_name = Column ( String ( <NUM_LIT:50> ) , nullable = False , index = True ) <EOL> run_id = Column ( DateTime , nullable = False , index = True ) <EOL> trans_count = Column ( Integer , nullable = False , index = True ) <EOL> elapsed = Column ( Float , nullable = False , index = True ) <EOL> epoch = Column ( Float , nullable = False , index = True ) <EOL> user_group_name = Column ( String ( <NUM_LIT:50> ) , nullable = False ) <EOL> scriptrun_time = Column ( Float , nullable = False ) <EOL> error = Column ( String ( <NUM_LIT:255> ) ) <EOL> custom_timers = Column ( String ( <NUM_LIT:255> ) ) <EOL> global_config = relation ( "<STR_LIT>" , <EOL> primaryjoin = "<STR_LIT>" ) <EOL> timers = relation ( "<STR_LIT>" , <EOL> primaryjoin = "<STR_LIT>" ) <EOL> def __init__ ( self , project_name = None , run_id = None , trans_count = None , <EOL> elapsed = None , epoch = None , user_group_name = None , <EOL> scriptrun_time = None , error = None , custom_timers = None ) : <EOL> self . project_name = str ( project_name ) <EOL> self . run_id = run_id <EOL> self . trans_count = int ( trans_count ) <EOL> self . elapsed = float ( elapsed ) <EOL> self . epoch = int ( epoch ) <EOL> self . user_group_name = str ( user_group_name ) <EOL> self . scriptrun_time = float ( scriptrun_time ) <EOL> self . error = str ( error ) <EOL> self . custom_timers = str ( custom_timers ) <EOL> def __repr__ ( self ) : <EOL> return "<STR_LIT>" % ( <EOL> self . project_name , self . run_id , self . trans_count , self . elapsed , <EOL> self . epoch , self . user_group_name , self . scriptrun_time , <EOL> self . error , self . custom_timers ) <EOL> class TimerRow ( Base ) : <EOL> """<STR_LIT>""" <EOL> __tablename__ = '<STR_LIT>' <EOL> id = Column ( Integer , nullable = False , primary_key = True ) <EOL> mechanize_results_id = Column ( Integer , <EOL> ForeignKey ( '<STR_LIT>' ) , nullable = False ) <EOL> timer_name = Column ( String ( <NUM_LIT:50> ) , nullable = False , index = True ) <EOL> elapsed = Column ( Float , nullable = False , index = True ) <EOL> def __init__ ( self , timer_name = None , elapsed = None ) : <EOL> self . timer_name = str ( timer_name ) <EOL> self . elapsed = float ( elapsed ) <EOL> def __repr__ ( self ) : <EOL> return "<STR_LIT>" % ( self . timer_name , self . elapsed ) <EOL> result_rows = relation ( "<STR_LIT>" , <EOL> primaryjoin = "<STR_LIT>" ) <EOL> def load_results_database ( project_name , run_localtime , results_dir , <EOL> results_database , run_time , rampup , results_ts_interval , <EOL> user_group_configs ) : <EOL> """<STR_LIT>""" <EOL> logline_re = re . compile ( '<STR_LIT>' ) <EOL> engine = create_engine ( results_database , echo = False ) <EOL> ResultRow . metadata . create_all ( engine ) <EOL> TimerRow . metadata . create_all ( engine ) <EOL> GlobalConfig . metadata . create_all ( engine ) <EOL> UserGroupConfig . metadata . create_all ( engine ) <EOL> sa_session = sessionmaker ( bind = engine ) <EOL> sa_current_session = sa_session ( ) <EOL> run_id = datetime ( run_localtime . tm_year , run_localtime . tm_mon , <EOL> run_localtime . tm_mday , run_localtime . tm_hour , run_localtime . tm_min , <EOL> run_localtime . tm_sec ) <EOL> results_file = results_dir + '<STR_LIT>' <EOL> global_config = GlobalConfig ( run_time , rampup , results_ts_interval ) <EOL> sa_current_session . add ( global_config ) <EOL> for i , ug_config in enumerate ( user_group_configs ) : <EOL> user_group_config = UserGroupConfig ( ug_config . name , <EOL> ug_config . num_threads , ug_config . script_file ) <EOL> global_config . user_group_configs . append ( user_group_config ) <EOL> for line in fileinput . input ( [ results_file ] ) : <EOL> line = line . rstrip ( ) <EOL> match = logline_re . match ( line ) <EOL> if match : <EOL> result_row = ResultRow ( project_name , run_id , match . group ( <NUM_LIT:1> ) , <EOL> match . group ( <NUM_LIT:2> ) , match . group ( <NUM_LIT:3> ) , match . group ( <NUM_LIT:4> ) , <EOL> match . group ( <NUM_LIT:5> ) , match . group ( <NUM_LIT:6> ) , match . group ( <NUM_LIT:7> ) ) <EOL> global_config . results . append ( result_row ) <EOL> timer_data = eval ( match . group ( <NUM_LIT:7> ) ) <EOL> for index in timer_data : <EOL> timer_row = TimerRow ( index , timer_data [ index ] ) <EOL> result_row . timers . append ( timer_row ) <EOL> sa_current_session . add ( result_row ) <EOL> sa_current_session . commit ( ) <EOL> sa_current_session . close ( ) </s>
