def get_resources(): """ <Purpose> Returns the resouce utilization limits as well as the current resource utilization. <Arguments> None. <Returns> A tuple of dictionaries and an array (limits, usage, stoptimes). Limits is the dictionary which maps the resouce name to its maximum limit. Usage is the dictionary which maps the resource name to its current usage. Stoptimes is an array of tuples with the times which the Repy proces was stopped and for how long, due to CPU over-use. Each entry in the array is a tuple (TOS, Sleep Time) where TOS is the time of stop (respective to getruntime()) and Sleep Time is how long the repy process was suspended. The stop times array holds a fixed number of the last stop times. Currently, it holds the last 100 stop times. """ # Acquire the lock get_resources_lock.acquire() # Construct the dictionaries as copies from nanny limits = nanny_resource_limits.resource_restriction_table.copy() usage = nanny_resource_limits.resource_consumption_table.copy() # These are the type we need to copy or flatten check_types = set([list,dict,set]) # Check the limits dictionary for bad keys for resource in limits.keys(): # Remove any resources we should not expose if resource not in exposed_resources: del limits[resource] # Check the type if type(limits[resource]) in check_types: # Copy the data structure limits[resource] = limits[resource].copy() # Check the usage dictionary for resource in usage.keys(): # Remove any resources that are not exposed if resource not in exposed_resources: del usage[resource] # Check the type, copy any data structures # Flatten any structures using len() other than # "connport" and "messport" if type(usage[resource]) in check_types: # Check if they are exempt from flattening, store a shallow copy if resource in flatten_exempt_resources: usage[resource] = usage[resource].copy() # Store the size of the data set else: usage[resource] = len(usage[resource]) # Calculate all the usage's pid = os.getpid() # Get CPU and memory, this is thread specific if ostype in ["Linux", "Darwin"]: # Get CPU first, then memory usage["cpu"] = os_api.get_process_cpu_time(pid) # This uses the cached PID data from the CPU check usage["memory"] = os_api.get_process_rss() # Get the thread specific CPU usage usage["threadcpu"] = os_api.get_current_thread_cpu_time() # Windows Specific versions elif ostype in ["Windows","WindowsCE"]: # Get the CPU time usage["cpu"] = windows_api.get_process_cpu_time(pid) # Get the memory, use the resident set size usage["memory"] = windows_api.process_memory_info(pid)['WorkingSetSize'] # Get thread-level CPU usage["threadcpu"] = windows_api.get_current_thread_cpu_time() # Unknown OS else: raise EnvironmentError("Unsupported Platform!") # Use the cached disk used amount usage["diskused"] = cached_disk_used # Release the lock get_resources_lock.release() # Copy the stop times stoptimes = process_stopped_timeline[:] # Return the dictionaries and the stoptimes return (limits,usage,stoptimes)
def get_resources(): """ <Purpose> Returns the resource utilization limits as well as the current resource utilization. <Arguments> None. <Returns> A tuple of dictionaries and an array (limits, usage, stoptimes). Limits is the dictionary which maps the resource name to its maximum limit. Usage is the dictionary which maps the resource name to its current usage. Stoptimes is an array of tuples with the times which the Repy process was stopped and for how long, due to CPU over-use. Each entry in the array is a tuple (TOS, Sleep Time) where TOS is the time of stop (respective to getruntime()) and Sleep Time is how long the repy process was suspended. The stop times array holds a fixed number of the last stop times. Currently, it holds the last 100 stop times. """ # Acquire the lock... get_resources_lock.acquire() # ...but always release it try: # Construct the dictionaries as copies from nanny (limits,usage) = 0, 0 #nanny.get_resource_information() # Calculate all the usage's pid = os.getpid() # Get CPU and memory, this is thread specific if ostype in ["Linux", "Darwin"]: # Get CPU first, then memory usage["cpu"] = os_api.get_process_cpu_time(pid) # This uses the cached PID data from the CPU check usage["memory"] = os_api.get_process_rss() # Get the thread specific CPU usage usage["threadcpu"] = os_api.get_current_thread_cpu_time() # Windows Specific versions elif ostype in ["Windows"]: # Get the CPU time usage["cpu"] = windows_api.get_process_cpu_time(pid) # Get the memory, use the resident set size usage["memory"] = windows_api.process_memory_info(pid)['WorkingSetSize'] # Get thread-level CPU usage["threadcpu"] = windows_api.get_current_thread_cpu_time() # Unknown OS else: raise EnvironmentError("Unsupported Platform!") # Use the cached disk used amount usage["diskused"] = cached_disk_used finally: # Release the lock get_resources_lock.release() # Copy the stop times stoptimes = process_stopped_timeline[:] # Return the dictionaries and the stoptimes return (limits,usage,stoptimes)
def get_resources(): """ <Purpose> Returns the resource utilization limits as well as the current resource utilization. <Arguments> None. <Returns> A tuple of dictionaries and an array (limits, usage, stoptimes). Limits is the dictionary which maps the resource name to its maximum limit. Usage is the dictionary which maps the resource name to its current usage. Stoptimes is an array of tuples with the times which the Repy process was stopped and for how long, due to CPU over-use. Each entry in the array is a tuple (TOS, Sleep Time) where TOS is the time of stop (respective to getruntime()) and Sleep Time is how long the repy process was suspended. The stop times array holds a fixed number of the last stop times. Currently, it holds the last 100 stop times. """ # Acquire the lock... get_resources_lock.acquire() # ...but always release it try: # Construct the dictionaries as copies from nanny (limits,usage) = nanny.get_resource_information() # Calculate all the usage's pid = os.getpid() # Get CPU and memory, this is thread specific if ostype in ["Linux", "Darwin"]: # Get CPU first, then memory usage["cpu"] = os_api.get_process_cpu_time(pid) # This uses the cached PID data from the CPU check usage["memory"] = os_api.get_process_rss() # Get the thread specific CPU usage usage["threadcpu"] = os_api.get_current_thread_cpu_time() # Windows Specific versions elif ostype in ["Windows","WindowsCE"]: # Get the CPU time usage["cpu"] = windows_api.get_process_cpu_time(pid) # Get the memory, use the resident set size usage["memory"] = windows_api.process_memory_info(pid)['WorkingSetSize'] # Get thread-level CPU usage["threadcpu"] = windows_api.get_current_thread_cpu_time() # Unknown OS else: raise EnvironmentError("Unsupported Platform!") # Use the cached disk used amount usage["diskused"] = cached_disk_used finally: # Release the lock get_resources_lock.release() # Copy the stop times stoptimes = process_stopped_timeline[:] # Return the dictionaries and the stoptimes return (limits,usage,stoptimes)