<s> import sys , os , time , random <EOL> from smisk . util . benchmark import benchmark <EOL> import smisk . ipc . bsddb <EOL> def main ( ) : <EOL> from optparse import OptionParser <EOL> parser = OptionParser ( ) <EOL> parser . add_option ( "<STR_LIT>" , "<STR_LIT>" , dest = "<STR_LIT>" , <EOL> help = "<STR_LIT>" , <EOL> metavar = "<STR_LIT>" , default = None ) <EOL> parser . add_option ( "<STR_LIT>" , "<STR_LIT>" , dest = "<STR_LIT>" , <EOL> help = "<STR_LIT>" , <EOL> metavar = "<STR_LIT:N>" , default = <NUM_LIT> , type = '<STR_LIT:int>' ) <EOL> parser . add_option ( "<STR_LIT>" , "<STR_LIT>" , dest = "<STR_LIT>" , <EOL> help = "<STR_LIT>" , <EOL> metavar = "<STR_LIT>" , default = <NUM_LIT:0> , type = '<STR_LIT:int>' ) <EOL> parser . add_option ( "<STR_LIT>" , "<STR_LIT>" , <EOL> action = "<STR_LIT:store_true>" , dest = "<STR_LIT>" , default = False , <EOL> help = "<STR_LIT>" ) <EOL> parser . add_option ( "<STR_LIT>" , "<STR_LIT>" , <EOL> action = "<STR_LIT:store_true>" , dest = "<STR_LIT>" , default = False , <EOL> help = "<STR_LIT>" ) <EOL> parser . add_option ( "<STR_LIT:-c>" , "<STR_LIT>" , <EOL> action = "<STR_LIT:store_true>" , dest = "<STR_LIT>" , default = False , <EOL> help = "<STR_LIT>" ) <EOL> ( options , args ) = parser . parse_args ( ) <EOL> if not options . read and not options . write : <EOL> print >> sys . stderr , '<STR_LIT>' '<STR_LIT>' <EOL> options . read = True <EOL> options . write = True <EOL> store = smisk . ipc . bsddb . shared_dict ( ) <EOL> idle_sec = float ( options . idle ) / <NUM_LIT> <EOL> if options . sync_time : <EOL> timestr = time . strftime ( '<STR_LIT>' ) + options . sync_time <EOL> try : <EOL> options . sync_time = time . strptime ( timestr , '<STR_LIT>' ) <EOL> except ValueError : <EOL> try : <EOL> options . sync_time = time . strptime ( timestr , '<STR_LIT>' ) <EOL> except ValueError : <EOL> raise ValueError ( '<STR_LIT>' ) <EOL> sync_t = time . mktime ( options . sync_time ) <EOL> if sync_t > time . time ( ) : <EOL> print '<STR_LIT>' % time . strftime ( '<STR_LIT>' , options . sync_time ) <EOL> last_printed_second = <NUM_LIT:0> <EOL> while <NUM_LIT:1> : <EOL> t = time . time ( ) <EOL> if sync_t <= t : <EOL> break <EOL> ti = int ( sync_t - t ) <EOL> if ti and ti != last_printed_second : <EOL> last_printed_second = ti <EOL> sys . stdout . write ( '<STR_LIT>' % ti ) <EOL> sys . stdout . flush ( ) <EOL> time . sleep ( <NUM_LIT> ) <EOL> sys . stdout . write ( '<STR_LIT:\n>' ) <EOL> sys . stdout . flush ( ) <EOL> rw = '<STR_LIT>' <EOL> if options . read and options . write : <EOL> rw = '<STR_LIT>' <EOL> elif options . read : <EOL> rw = '<STR_LIT>' <EOL> pid = os . getpid ( ) <EOL> time . sleep ( <NUM_LIT:0.1> * random . random ( ) ) <EOL> idle_msg = '<STR_LIT>' <EOL> if idle_sec > <NUM_LIT:0.0> : <EOL> idle_msg = '<STR_LIT>' % ( idle_sec * <NUM_LIT> ) <EOL> print '<STR_LIT>' % ( options . iterations , rw , pid , idle_msg ) <EOL> if options . read and options . write : <EOL> for x in benchmark ( '<STR_LIT>' % ( rw , pid ) , options . iterations , it_subtractor = idle_sec ) : <EOL> store [ '<STR_LIT>' ] = pid <EOL> time . sleep ( idle_sec ) <EOL> pid_found = store [ '<STR_LIT>' ] <EOL> elif options . read : <EOL> for x in benchmark ( '<STR_LIT>' % ( rw , pid ) , options . iterations , it_subtractor = idle_sec ) : <EOL> time . sleep ( idle_sec ) <EOL> pid_found = store [ '<STR_LIT>' ] <EOL> else : <EOL> for x in benchmark ( '<STR_LIT>' % ( rw , pid ) , options . iterations , it_subtractor = idle_sec ) : <EOL> time . sleep ( idle_sec ) <EOL> store [ '<STR_LIT>' ] = pid <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> main ( ) </s>
