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/arch | |
parent | 52fe5517f716dedf9c9918e56325e49a49146130 (diff) | |
download | psutil-e6bf2bcafc41319a22945e98f50906149527ff51.tar.gz |
move psutil_virtual_mem() in a new mem.c file
Diffstat (limited to 'psutil/arch')
-rw-r--r-- | psutil/arch/windows/mem.c | 35 | ||||
-rw-r--r-- | psutil/arch/windows/mem.h | 9 |
2 files changed, 44 insertions, 0 deletions
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); |