[{
"type": "thumb-down",
"id": "hardToUnderstand",
"label":"Hard to understand"
},{
"type": "thumb-down",
"id": "incorrectInformationOrSampleCode",
"label":"Incorrect information or sample code"
},{
"type": "thumb-down",
"id": "missingTheInformationSamplesINeed",
"label":"Missing the information/samples I need"
},{
"type": "thumb-down",
"id": "otherDown",
"label":"Other"
}]
[{
"type": "thumb-up",
"id": "easyToUnderstand",
"label":"Easy to understand"
},{
"type": "thumb-up",
"id": "solvedMyProblem",
"label":"Solved my problem"
},{
"type": "thumb-up",
"id": "otherUp",
"label":"Other"
}]
Source code for google.appengine.ext.appstats.loader
#!/usr/bin/env python## Copyright 2007 Google Inc.## Licensed under the Apache License, Version 2.0 (the "License");# you may not use this file except in compliance with the License.# You may obtain a copy of the License at## http://www.apache.org/licenses/LICENSE-2.0## Unless required by applicable law or agreed to in writing, software# distributed under the License is distributed on an "AS IS" BASIS,# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.# See the License for the specific language governing permissions and# limitations under the License.#"""Loading appstats data from and to various sources like file, memcache etc.The file currently has modules to read data from memcache, to write appstatsdata to a file in pickled format, and to read records from a file afterunpickling. The script is envisioned to be extensible in the future to allowreading/writing to/from datastore, storing data in alternate file formats suchas SQLLite etc."""importcPickleaspickleimportloggingimporttimefromgoogle.appengine.ext.appstatsimportdatamodel_pbfromgoogle.appengine.ext.appstatsimportrecording
[docs]defFromMemcache(filter_timestamp=0,java_application=False):"""Reads appstats data from memcache. Get all appstats full records from memcache which correspond to requests with a greater timestamp than filter_timestamp Args: filter_timestamp: only retrieve records with timestamp (in milliseconds) higher than this value. If 0, all records are retrieved. java_application: Boolean. If true, this function is being called by the download_appstats tool for a Java application. Returns: List of RequestStatProto protobufs. """records=[]logging.info('Loading appstats summaries...')summaries=recording.load_summary_protos(java_application)logging.info('Loaded %d summaries. Loading full records...',len(summaries))start_time=time.time()missing_full_records=0failed_requests=0forcount,summaryinenumerate(summaries):time_key=summary.start_timestamp_milliseconds()iftime_key<=filter_timestamp:logging.info('Only %d records with newer timestamp.'' Skipping rest.',count)breaktimestamp=int(time_key)*0.001record=recording.load_full_proto(timestamp,java_application)ifnotrecord:missing_full_records+=1continuehttpstatus=int(record.http_status())ifhttpstatus>=400:failed_requests+=1continuerecords.append(record)iflen(records)%10==0:logging.info('Download in progress..completed %d..',len(records))ifnotrecords:logging.info('No full records present in memcache for succesful requests.')else:end_time=time.time()elapsed=max(end_time-start_time,0)time_per_record=elapsed/len(records)logging.info('Done. %d full records downloaded in %.2f secs ''[%.2f secs per full record]',len(records),elapsed,time_per_record)ifmissing_full_records:logging.info('Skipped %d summaries with missing full records',missing_full_records)iffailed_requests:logging.info('Skipped %d summaries corresponding to failed requests',failed_requests)returnrecords
[docs]defPickleToFile(records,outfile):"""Writes appstats data to file. Args: records: list of RequestStatProto protobufs outfile: file object to write appstats data to Returns: None. File format is a pickled list of protobufs encoded as binary strings. """encoded_records=[]forrecordinrecords:encoded=record.Encode()encoded_records.append(encoded)pickle.dump(encoded_records,outfile,protocol=pickle.HIGHEST_PROTOCOL)
[docs]defUnpickleFromFile(datafile):"""Reads appstats data from file. Args: datafile: file object to read appstats data from. File format is a pickled list of protobufs encoded as binary strings. Returns: List of RequestStatProto protobufs. """encoded_records=pickle.load(datafile)records=[]forencoded_recordinencoded_records:record=datamodel_pb.RequestStatProto(encoded_record)records.append(record)datafile.close()returnrecords
[{
"type": "thumb-down",
"id": "hardToUnderstand",
"label":"Hard to understand"
},{
"type": "thumb-down",
"id": "incorrectInformationOrSampleCode",
"label":"Incorrect information or sample code"
},{
"type": "thumb-down",
"id": "missingTheInformationSamplesINeed",
"label":"Missing the information/samples I need"
},{
"type": "thumb-down",
"id": "otherDown",
"label":"Other"
}]
[{
"type": "thumb-up",
"id": "easyToUnderstand",
"label":"Easy to understand"
},{
"type": "thumb-up",
"id": "solvedMyProblem",
"label":"Solved my problem"
},{
"type": "thumb-up",
"id": "otherUp",
"label":"Other"
}]