<s> """<STR_LIT>""" <EOL> import cPickle as pickle <EOL> import logging <EOL> import time <EOL> from google . appengine . ext . appstats import datamodel_pb <EOL> from google . appengine . ext . appstats import recording <EOL> def FromMemcache ( filter_timestamp = <NUM_LIT:0> , java_application = False ) : <EOL> """<STR_LIT>""" <EOL> records = [ ] <EOL> logging . info ( '<STR_LIT>' ) <EOL> summaries = recording . load_summary_protos ( java_application ) <EOL> logging . info ( '<STR_LIT>' , <EOL> len ( summaries ) ) <EOL> start_time = time . time ( ) <EOL> missing_full_records = <NUM_LIT:0> <EOL> failed_requests = <NUM_LIT:0> <EOL> for count , summary in enumerate ( summaries ) : <EOL> time_key = summary . start_timestamp_milliseconds ( ) <EOL> if time_key <= filter_timestamp : <EOL> logging . info ( '<STR_LIT>' <EOL> '<STR_LIT>' , count ) <EOL> break <EOL> timestamp = int ( time_key ) * <NUM_LIT> <EOL> record = recording . load_full_proto ( timestamp , java_application ) <EOL> if not record : <EOL> missing_full_records += <NUM_LIT:1> <EOL> continue <EOL> httpstatus = int ( record . http_status ( ) ) <EOL> if httpstatus >= <NUM_LIT> : <EOL> failed_requests += <NUM_LIT:1> <EOL> continue <EOL> records . append ( record ) <EOL> if len ( records ) % <NUM_LIT:10> == <NUM_LIT:0> : <EOL> logging . info ( '<STR_LIT>' , len ( records ) ) <EOL> if not records : <EOL> logging . info ( '<STR_LIT>' ) <EOL> else : <EOL> end_time = time . time ( ) <EOL> elapsed = max ( end_time - start_time , <NUM_LIT:0> ) <EOL> time_per_record = elapsed / len ( records ) <EOL> logging . info ( '<STR_LIT>' <EOL> '<STR_LIT>' , <EOL> len ( records ) , elapsed , time_per_record ) <EOL> if missing_full_records : <EOL> logging . info ( '<STR_LIT>' , <EOL> missing_full_records ) <EOL> if failed_requests : <EOL> logging . info ( '<STR_LIT>' , <EOL> failed_requests ) <EOL> return records <EOL> def PickleToFile ( records , outfile ) : <EOL> """<STR_LIT>""" <EOL> encoded_records = [ ] <EOL> for record in records : <EOL> encoded = record . Encode ( ) <EOL> encoded_records . append ( encoded ) <EOL> pickle . dump ( encoded_records , outfile , protocol = pickle . HIGHEST_PROTOCOL ) <EOL> def UnpickleFromFile ( datafile ) : <EOL> """<STR_LIT>""" <EOL> encoded_records = pickle . load ( datafile ) <EOL> records = [ ] <EOL> for encoded_record in encoded_records : <EOL> record = datamodel_pb . RequestStatProto ( encoded_record ) <EOL> records . append ( record ) <EOL> datafile . close ( ) <EOL> return records </s>
