#NEWLINE# def get_info( process = None , interval = 0 , with_childs = False ) : #NEWLINE# #INDENT# 'Return information about a process. (can be an pid or a Process object)\n\n    If process is None, will return the information about the current process.\n    ' #NEWLINE# from circus.process import get_children , get_memory_info , get_cpu_percent , get_memory_percent , get_cpu_times , get_nice , get_cmdline , get_create_time , get_username #NEWLINE# if ( ( process is None ) or isinstance ( process , int ) ) : #NEWLINE# #INDENT# if ( process is None ) : #NEWLINE# #INDENT# pid = os . getpid ( ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# pid = process #NEWLINE# #UNINDENT# if ( pid in _PROCS ) : #NEWLINE# #INDENT# process = _PROCS [ pid ] #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# _PROCS [ pid ] = process = Process ( pid ) #NEWLINE# #UNINDENT# #UNINDENT# info = { #NEWLINE# #INDENT# #NEWLINE# #UNINDENT# } #NEWLINE# try : #NEWLINE# #INDENT# mem_info = get_memory_info ( process ) #NEWLINE# info [ 'mem_info1' ] = bytes2human ( mem_info [ 0 ] ) #NEWLINE# info [ 'mem_info2' ] = bytes2human ( mem_info [ 1 ] ) #NEWLINE# #UNINDENT# except AccessDenied : #NEWLINE# #INDENT# info [ 'mem_info1' ] = info [ 'mem_info2' ] = 'N/A' #NEWLINE# #UNINDENT# try : #NEWLINE# #INDENT# info [ 'cpu' ] = get_cpu_percent ( process , interval = interval ) #NEWLINE# #UNINDENT# except AccessDenied : #NEWLINE# #INDENT# info [ 'cpu' ] = 'N/A' #NEWLINE# #UNINDENT# try : #NEWLINE# #INDENT# info [ 'mem' ] = round ( get_memory_percent ( process ) , 1 ) #NEWLINE# #UNINDENT# except AccessDenied : #NEWLINE# #INDENT# info [ 'mem' ] = 'N/A' #NEWLINE# #UNINDENT# try : #NEWLINE# #INDENT# cpu_times = get_cpu_times ( process ) #NEWLINE# ctime = timedelta ( seconds = sum ( cpu_times ) ) #NEWLINE# ctime = ( '%s:%s.%s' % ( ( ( ctime . seconds // 60 ) % 60 ) , str ( ( ctime . seconds % 60 ) ) . zfill ( 2 ) , str ( ctime . microseconds ) [ : 2 ] ) ) #NEWLINE# #UNINDENT# except AccessDenied : #NEWLINE# #INDENT# ctime = 'N/A' #NEWLINE# #UNINDENT# info [ 'ctime' ] = with_childs #NEWLINE# try : #NEWLINE# #INDENT# info [ 'pid' ] = process . pid #NEWLINE# #UNINDENT# except AccessDenied : #NEWLINE# #INDENT# info [ 'pid' ] = 'N/A' #NEWLINE# #UNINDENT# try : #NEWLINE# #INDENT# info [ 'username' ] = get_username ( process ) #NEWLINE# #UNINDENT# except AccessDenied : #NEWLINE# #INDENT# info [ 'username' ] = 'N/A' #NEWLINE# #UNINDENT# try : #NEWLINE# #INDENT# info [ 'nice' ] = get_nice ( process ) #NEWLINE# #UNINDENT# except AccessDenied : #NEWLINE# #INDENT# info [ 'nice' ] = 'N/A' #NEWLINE# #UNINDENT# except NoSuchProcess : #NEWLINE# #INDENT# info [ 'nice' ] = 'Zombie' #NEWLINE# #UNINDENT# try : #NEWLINE# #INDENT# raw_cmdline = get_cmdline ( process ) #NEWLINE# cmdline = os . path . basename ( shlex . split ( raw_cmdline [ 0 ] , posix = ( not IS_WINDOWS ) ) [ 0 ] ) #NEWLINE# #UNINDENT# except ( AccessDenied , IndexError ) : #NEWLINE# #INDENT# cmdline = 'N/A' #NEWLINE# #UNINDENT# try : #NEWLINE# #INDENT# info [ 'create_time' ] = get_create_time ( process ) #NEWLINE# #UNINDENT# except AccessDenied : #NEWLINE# #INDENT# info [ 'create_time' ] = 'N/A' #NEWLINE# #UNINDENT# try : #NEWLINE# #INDENT# info [ 'age' ] = ( time . time ( ) - get_create_time ( process ) ) #NEWLINE# #UNINDENT# except TypeError : #NEWLINE# #INDENT# info [ 'create_time' ] = get_create_time ( process ) #NEWLINE# #UNINDENT# except AccessDenied : #NEWLINE# #INDENT# info [ 'age' ] = 'N/A' #NEWLINE# #UNINDENT# info [ 'cmdline' ] = cmdline #NEWLINE# info [ 'children' ] = [ ] #NEWLINE# if with_childs : #NEWLINE# #INDENT# for child in get_children ( process ) : #NEWLINE# #INDENT# info [ 'children' ] . append ( get_info ( child , interval = interval ) ) #NEWLINE# #UNINDENT# #UNINDENT# return info