diff options
author | Giampaolo Rodola <g.rodola@gmail.com> | 2023-04-10 13:17:26 -0700 |
---|---|---|
committer | Giampaolo Rodola <g.rodola@gmail.com> | 2023-04-10 13:17:26 -0700 |
commit | e6bf2bcafc41319a22945e98f50906149527ff51 (patch) | |
tree | ea8a422f6a63ad3743882eff39170a8830b7ea8e /psutil | |
parent | 52fe5517f716dedf9c9918e56325e49a49146130 (diff) | |
download | psutil-e6bf2bcafc41319a22945e98f50906149527ff51.tar.gz |
move psutil_virtual_mem() in a new mem.c file
Diffstat (limited to 'psutil')
-rw-r--r-- | psutil/_psutil_windows.c | 30 | ||||
-rw-r--r-- | psutil/arch/windows/mem.c | 35 | ||||
-rw-r--r-- | psutil/arch/windows/mem.h | 9 |
3 files changed, 45 insertions, 29 deletions
diff --git a/psutil/_psutil_windows.c b/psutil/_psutil_windows.c index 6e51c449..969c5713 100644 --- a/psutil/_psutil_windows.c +++ b/psutil/_psutil_windows.c @@ -33,6 +33,7 @@ #include "arch/windows/process_handles.h" #include "arch/windows/disk.h" #include "arch/windows/cpu.h" +#include "arch/windows/mem.h" #include "arch/windows/net.h" #include "arch/windows/services.h" #include "arch/windows/socks.h" @@ -603,35 +604,6 @@ psutil_proc_memory_uss(PyObject *self, PyObject *args) { return Py_BuildValue("I", wsCounters.NumberOfPrivatePages); } - -/* - * Return a Python integer indicating the total amount of physical memory - * in bytes. - */ -static PyObject * -psutil_virtual_mem(PyObject *self, PyObject *args) { - unsigned long long totalPhys, availPhys, totalSys, availSys, pageSize; - PERFORMANCE_INFORMATION perfInfo; - - if (! GetPerformanceInfo(&perfInfo, sizeof(PERFORMANCE_INFORMATION))) { - PyErr_SetFromWindowsErr(0); - return NULL; - } - // values are size_t, widen (if needed) to long long - pageSize = perfInfo.PageSize; - totalPhys = perfInfo.PhysicalTotal * pageSize; - availPhys = perfInfo.PhysicalAvailable * pageSize; - totalSys = perfInfo.CommitLimit * pageSize; - availSys = totalSys - perfInfo.CommitTotal * pageSize; - return Py_BuildValue( - "(LLLL)", - totalPhys, - availPhys, - totalSys, - availSys); -} - - /* * Return process current working directory as a Python string. */ diff --git a/psutil/arch/windows/mem.c b/psutil/arch/windows/mem.c new file mode 100644 index 00000000..8b678254 --- /dev/null +++ b/psutil/arch/windows/mem.c @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2009, Jay Loden, Giampaolo Rodola'. All rights reserved. + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + */ + +#include <Python.h> +#include <windows.h> +#include <Psapi.h> + +#include "../../_psutil_common.h" + + +PyObject * +psutil_virtual_mem(PyObject *self, PyObject *args) { + unsigned long long totalPhys, availPhys, totalSys, availSys, pageSize; + PERFORMANCE_INFORMATION perfInfo; + + if (! GetPerformanceInfo(&perfInfo, sizeof(PERFORMANCE_INFORMATION))) { + PyErr_SetFromWindowsErr(0); + return NULL; + } + // values are size_t, widen (if needed) to long long + pageSize = perfInfo.PageSize; + totalPhys = perfInfo.PhysicalTotal * pageSize; + availPhys = perfInfo.PhysicalAvailable * pageSize; + totalSys = perfInfo.CommitLimit * pageSize; + availSys = totalSys - perfInfo.CommitTotal * pageSize; + return Py_BuildValue( + "(LLLL)", + totalPhys, + availPhys, + totalSys, + availSys); +} diff --git a/psutil/arch/windows/mem.h b/psutil/arch/windows/mem.h new file mode 100644 index 00000000..871cd64e --- /dev/null +++ b/psutil/arch/windows/mem.h @@ -0,0 +1,9 @@ +/* + * Copyright (c) 2009, Jay Loden, Giampaolo Rodola'. All rights reserved. + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + */ + +#include <Python.h> + +PyObject *psutil_virtual_mem(PyObject* self, PyObject* args); |