3 __author__ =
'Ali GOREN <goren.ali@yandex.com>'
4 __repo__ =
'https://github.com/aligoren/syspy'
5 __license__ =
'Apache v2.0 License'
26 symbols = (
'K',
'M',
'G',
'T',
'P',
'E',
'Z',
'Y')
28 for i, s
in enumerate(symbols):
29 prefix[s] = 1 << (i + 1) * 10
30 for s
in reversed(symbols):
32 value = float(n) / prefix[s]
33 return '%.1f%s' % (value, s)
41 >>> mem = psutil.virtual_memory()
43 svmem(total=2142027776, available=1013366784, percent=52.7, used=1128660992, free=1013366784)
46 [2142027776, 1013366784, 52.7, 1128660992, 1013366784]
53 mem = psutil.virtual_memory()
58 ret_percent =
"{0}".format(lmem[2])
62 return ret_total, ret_ava, ret_percent, ret_used, ret_free
69 >>> psutil.swap_memory()
70 sswap(total=4284055552, used=1793249280, free=2490806272, percent=41.9, sin=0, s
72 >>> smem = psutil.swap_memory()
73 >>> lsmem = list(smem)
75 [4284055552, 1794441216, 2489614336, 41.9, 0, 0]
80 smem = psutil.swap_memory()
83 ret_swap_total =
"{0}".format(self.
bytes2human(lsmem[0]))
84 ret_swap_used =
"{0}".format(self.
bytes2human(lsmem[1]))
85 ret_swap_free =
"{0}".format(self.
bytes2human(lsmem[2]))
86 ret_swap_percent =
"{0}".format(lsmem[3])
87 ret_swap_sin =
"{0}".format(self.
bytes2human(lsmem[4]))
88 ret_swap_sout =
"{0}".format(self.
bytes2human(lsmem[5]))
90 return ret_swap_total, ret_swap_used, ret_swap_free, ret_swap_percent, ret_swap_sin, ret_swap_sout
96 >>> p = psutil.Process()
98 pmem(rss=8536064, vms=5599232)
99 >>> minfo = list(p.memory_info())
107 ret_rss = RSS(Resident Set Size)
108 ret_vms = VMS(Virtual Memory Size)
114 minfo = list(p.memory_info())
119 return ret_rss, ret_vms
125 >>> p = psutil.Process()
126 >>> p.memory_info_ex()
127 pextmem(num_page_faults=2277, peak_wset=8552448, wset=8552448, peak_paged_pool=1
128 00980, paged_pool=100980, peak_nonpaged_pool=4484, nonpaged_pool=4484, pagefile=
129 5607424, peak_pagefile=5607424, private=5607424)
130 >>> minfo = list(p.memory_info_ex())
132 [2297, 8634368, 8634368, 100980, 100980, 4844, 4844, 5681152, 5681152, 5681152]
143 f = peak_nonpaged_pool
149 http://pythonhosted.org/psutil/#psutil.Process.memory_info_ex
155 minfo_ex = list(p.memory_info_ex())
157 ret_faults =
"{0}".format(self.
bytes2human(minfo_ex[0]))
158 ret_peak_wset =
"{0}".format(self.
bytes2human(minfo_ex[1]))
159 ret_wset =
"{0}".format(self.
bytes2human(minfo_ex[2]))
160 ret_peak_ptool =
"{0}".format(self.
bytes2human(minfo_ex[3]))
161 ret_paged_tool =
"{0}".format(self.
bytes2human(minfo_ex[4]))
162 ret_peak_nptool =
"{0}".format(self.
bytes2human(minfo_ex[5]))
163 ret_nonpaged_tool =
"{0}".format(self.
bytes2human(minfo_ex[6]))
164 ret_pagefile =
"{0}".format(self.
bytes2human(minfo_ex[7]))
165 ret_peak_pfile =
"{0}".format(self.
bytes2human(minfo_ex[8]))
166 ret_private =
"{0}".format(self.
bytes2human(minfo_ex[9]))
168 return ret_faults, ret_peak_wset, ret_wset, ret_peak_ptool, ret_paged_tool, \
169 ret_peak_nptool, ret_nonpaged_tool, ret_pagefile, ret_peak_pfile, ret_private
176 >>> p = psutil.Process()
177 >>> p.memory_percent()
179 >>> list(p.memory_percent())
180 Traceback (most recent call last):
181 File "<stdin>", line 1, in <module>
182 TypeError: 'float' object is not iterable
189 mpercent = p.memory_percent()
191 ret_mpercent =
"{0}".format(mpercent)
202 Path: C:\Windows\System32\apisetschema.dll
210 RSS: Resident Set Size
211 Permission: Process Permission
212 Path: Process Api Path
213 Total RSS: Total Resident Set Size
217 p = psutil.Process(int(poid))
218 ret_pid =
"{0}".format(p.pid)
219 ret_name =
"{0}".format(p.name())
221 for m
in p.memory_maps(grouped=
False):
224 ret_perm =
"{0}".format(m.perms)
225 ret_path =
"{0}".format(m.path)
226 ret_total =
"{0}".format(self.
bytes2human(total_rss))
228 return ret_pid, ret_name, ret_rss, ret_perm, ret_path, ret_total
def getVirtualMemory(self)
def getMemoryInfoEx(self)
def getMemoryMap(self, poid)
def getMemoryPercent(self)