summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGiampaolo Rodola <g.rodola@gmail.com>2019-11-21 22:38:27 -0800
committerGiampaolo Rodola <g.rodola@gmail.com>2019-11-21 22:38:27 -0800
commit81796561fc3e485e64f2064043078cdeeab0c780 (patch)
tree92a7defeb496ea3da8a1b2e5fa033c5eb47ea865
parentb2414b83d3d728ec34ea0e35bfb21517ee231401 (diff)
downloadpsutil-81796561fc3e485e64f2064043078cdeeab0c780.tar.gz
add shared and shareable memory metrics on win
-rw-r--r--HISTORY.rst5
-rw-r--r--psutil/_psutil_windows.c24
-rw-r--r--psutil/_pswindows.py9
-rwxr-xr-xpsutil/tests/test_process.py3
4 files changed, 31 insertions, 10 deletions
diff --git a/HISTORY.rst b/HISTORY.rst
index 5cef298c..f4e127eb 100644
--- a/HISTORY.rst
+++ b/HISTORY.rst
@@ -5,6 +5,11 @@
XXXX-XX-XX
+**Enhancements**
+
+- 1452_: [Windows] Process memory_full_info() now reports 'shared' and
+ 'shareable' memory metrics.
+
**Bug fixes**
- 1179_: [Linux] Process cmdline() now takes into account misbehaving processes
diff --git a/psutil/_psutil_windows.c b/psutil/_psutil_windows.c
index 95991934..b8391a7a 100644
--- a/psutil/_psutil_windows.c
+++ b/psutil/_psutil_windows.c
@@ -269,7 +269,7 @@ psutil_proc_kill(PyObject *self, PyObject *args) {
// https://github.com/giampaolo/psutil/issues/1099
if (GetLastError() != ERROR_ACCESS_DENIED) {
PyErr_SetFromOSErrnoWithSyscall("TerminateProcess");
- goto error;
+ return NULL;
}
}
@@ -824,13 +824,13 @@ psutil_GetProcWsetInformation(
/*
- * Returns the USS of the process.
- * Reference:
+ * Returns memory working set info about process.
+ * Reference (USS):
* https://dxr.mozilla.org/mozilla-central/source/xpcom/base/
* nsMemoryReporterManager.cpp
*/
static PyObject *
-psutil_proc_memory_uss(PyObject *self, PyObject *args) {
+psutil_proc_memory_wset(PyObject *self, PyObject *args) {
DWORD pid;
HANDLE hProcess;
PSUTIL_PROCESS_WS_COUNTERS wsCounters;
@@ -867,12 +867,22 @@ psutil_proc_memory_uss(PyObject *self, PyObject *args) {
wsInfo->WorkingSetInfo[i].ShareCount <= 1) {
wsCounters.NumberOfPrivatePages++;
}
+
+ // shared memory info
+ if (wsInfo->WorkingSetInfo[i].ShareCount > 1)
+ wsCounters.NumberOfSharedPages++;
+ if (wsInfo->WorkingSetInfo[i].Shared)
+ wsCounters.NumberOfShareablePages++;
}
HeapFree(GetProcessHeap(), 0, wsInfo);
CloseHandle(hProcess);
- return Py_BuildValue("I", wsCounters.NumberOfPrivatePages);
+ return Py_BuildValue(
+ "III",
+ wsCounters.NumberOfPrivatePages,
+ wsCounters.NumberOfSharedPages,
+ wsCounters.NumberOfShareablePages);
}
@@ -3426,8 +3436,8 @@ PsutilMethods[] = {
"seconds since the epoch"},
{"proc_memory_info", psutil_proc_memory_info, METH_VARARGS,
"Return a tuple of process memory information"},
- {"proc_memory_uss", psutil_proc_memory_uss, METH_VARARGS,
- "Return the USS of the process"},
+ {"proc_memory_wset", psutil_proc_memory_wset, METH_VARARGS,
+ "Return memory working set info about a process"},
{"proc_cwd", psutil_proc_cwd, METH_VARARGS,
"Return process current working directory"},
{"proc_suspend_or_resume", psutil_proc_suspend_or_resume, METH_VARARGS,
diff --git a/psutil/_pswindows.py b/psutil/_pswindows.py
index 636b0af9..c5ef7c3b 100644
--- a/psutil/_pswindows.py
+++ b/psutil/_pswindows.py
@@ -201,7 +201,8 @@ pmem = namedtuple(
'paged_pool', 'peak_nonpaged_pool', 'nonpaged_pool',
'pagefile', 'peak_pagefile', 'private'])
# psutil.Process.memory_full_info()
-pfullmem = namedtuple('pfullmem', pmem._fields + ('uss', ))
+pfullmem = namedtuple('pfullmem',
+ pmem._fields + ('uss', 'shared', 'shareable'))
# psutil.Process.memory_maps(grouped=True)
pmmap_grouped = namedtuple('pmmap_grouped', ['path', 'rss'])
# psutil.Process.memory_maps(grouped=False)
@@ -867,9 +868,11 @@ class Process(object):
@wrap_exceptions
def memory_full_info(self):
basic_mem = self.memory_info()
- uss = cext.proc_memory_uss(self.pid)
+ uss, shared, shareable = cext.proc_memory_wset(self.pid)
uss *= getpagesize()
- return pfullmem(*basic_mem + (uss, ))
+ shared *= getpagesize()
+ shareable *= getpagesize()
+ return pfullmem(*basic_mem + (uss, shared, shareable))
def memory_maps(self):
try:
diff --git a/psutil/tests/test_process.py b/psutil/tests/test_process.py
index 24a29b5a..a92e84ce 100755
--- a/psutil/tests/test_process.py
+++ b/psutil/tests/test_process.py
@@ -612,6 +612,9 @@ class TestProcess(unittest.TestCase):
if LINUX:
self.assertGreaterEqual(mem.pss, 0)
self.assertGreaterEqual(mem.swap, 0)
+ if WINDOWS:
+ self.assertGreaterEqual(mem.shared, 0)
+ self.assertGreaterEqual(mem.shareable, 0)
@unittest.skipIf(not HAS_MEMORY_MAPS, "not supported")
def test_memory_maps(self):