Coverage for scrapy/utils/memory : 60%
Hot-keys on this page
r m x p toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
|
"""Return virtual memory value (in bytes) for the given pid using the /proc filesystem. If pid is not given, it default to the current process pid. Available keys are: VmSize, VmRSS (default), VmStk """ except IOError: raise RuntimeError("/proc filesystem not supported") return _vmvalue_solaris(vmkey, pid) else: # get vmkey line e.g. 'VmRSS: 9999 kB\n ...' return 0 # invalid format? # convert Vm value to bytes
except IOError: return False else:
# Memory layout for struct psinfo. # http://docs.sun.com/app/docs/doc/816-5174/proc-4?l=en&a=view _psinfo_struct_format = ( "10i" # pr_flag [0] through pr_egid [9] "5L" # pr_addr [10] through pr_ttyydev [14] "2H" # pr_pctcpu [15] and pr_pctmem [16] "6l" # pr_start [17-18] through pr_ctime [21-22] "16s" # pr_fname [23] "80s" # pr_psargs [24] "2i" # pr_wstat[25] and pr_argc [26] "2L" # pr_argv [27] and pr_envp [28] "b3x" # pr_dmodel[29] and pr_pad2 "7i" # pr_taskid [30] through pr_filler "20i6l" # pr_lwp ) psinfo_file = os.path.join("/proc", str(pid), "psinfo") with open(psinfo_file) as f: parts = struct.unpack(_psinfo_struct_format, f.read())
vmkey_index = { 'VmSize' : 11, # pr_size 'VmRSS' : 12, # pr_rssize }
vm_in_kB = parts[vmkey_index[vmkey]]
return vm_in_kB * 1024 |