Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add memory usage support for Windows
Using wmi wrapper for pywin32. Testing py2exe sucks. If anyone else has a problem with a missing zope module add an __init__.py to the site-packages\zope directory under the interface directory and magic will happen.
- Loading branch information
1 parent
3a4a301
commit 65ef44d
Showing
3 changed files
with
24 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,19 @@ | ||
import gc | ||
import os | ||
import platform | ||
|
||
_scale = {'kB': 1024, 'mB': 1024*1024, | ||
'KB': 1024, 'MB': 1024*1024} | ||
|
||
def resident(): | ||
with open('/proc/%d/status' % os.getpid()) as f: | ||
v = f.read() | ||
i = v.index('VmRSS:') | ||
v = v[i:].split(None, 3) | ||
#assert len(v) == 3, v | ||
return float(v[1]) * _scale[v[2]] | ||
if platform.system() == 'Windows': | ||
from wmi import WMI | ||
w = WMI('.') | ||
result = w.query("SELECT WorkingSet FROM Win32_PerfRawData_PerfProc_Process WHERE IDProcess=%d" % os.getpid()) | ||
return int(result[0].WorkingSet) | ||
else: | ||
with open('/proc/%d/status' % os.getpid()) as f: | ||
v = f.read() | ||
i = v.index('VmRSS:') | ||
v = v[i:].split(None, 3) | ||
#assert len(v) == 3, v | ||
return float(v[1]) * _scale[v[2]] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters