thirdparty/google_appengine/google/appengine/api/quota.py
changeset 2878 cf4b80992451
parent 2864 2e0b0af889be
equal deleted inserted replaced
2871:e440e94a874b 2878:cf4b80992451
    35   """
    35   """
    36 
    36 
    37   if _apphosting_runtime___python__apiproxy:
    37   if _apphosting_runtime___python__apiproxy:
    38     return _apphosting_runtime___python__apiproxy.get_request_cpu_usage()
    38     return _apphosting_runtime___python__apiproxy.get_request_cpu_usage()
    39   return 0
    39   return 0
       
    40 
       
    41 def get_request_api_cpu_usage():
       
    42   """Get the amount of CPU used so far by API calls during the current request.
       
    43 
       
    44   Returns the number of megacycles used so far by API calls for the current
       
    45   request. Does not include CPU used by code in the request itself.
       
    46 
       
    47   Does nothing when used in the dev_appserver.
       
    48   """
       
    49 
       
    50   if _apphosting_runtime___python__apiproxy:
       
    51     return _apphosting_runtime___python__apiproxy.get_request_api_cpu_usage()
       
    52   return 0
       
    53 
       
    54 MCYCLES_PER_SECOND = 1200.0
       
    55 """Megacycles to CPU seconds.  Convert by using a 1.2 GHz 64-bit x86 CPU."""
       
    56 
       
    57 def megacycles_to_cpu_seconds(mcycles):
       
    58   """Convert an input value in megacycles to CPU-seconds.
       
    59 
       
    60   Returns a double representing the CPU-seconds the input megacycle value
       
    61   converts to.
       
    62   """
       
    63   return mcycles / MCYCLES_PER_SECOND
       
    64 
       
    65 def cpu_seconds_to_megacycles(cpu_secs):
       
    66   """Convert an input value in CPU-seconds to megacycles.
       
    67 
       
    68   Returns an integer representing the megacycles the input CPU-seconds value
       
    69   converts to.
       
    70   """
       
    71   return int(cpu_secs * MCYCLES_PER_SECOND)