summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGiampaolo Rodola <g.rodola@gmail.com>2019-02-19 15:39:18 -0800
committerGiampaolo Rodola <g.rodola@gmail.com>2019-02-19 15:39:18 -0800
commit53f5ef447a95fbda1ca514be576a5ba40134fd66 (patch)
treeb38133e8e62a361927a287b7dfd1cb684205dfd2
parentc2ec8157f4dca7b6d8fdba9f690f17acd9d6d095 (diff)
downloadpsutil-53f5ef447a95fbda1ca514be576a5ba40134fd66.tar.gz
port NtQuerySystemInformation
-rw-r--r--psutil/_psutil_windows.c22
-rw-r--r--psutil/arch/windows/global.c5
-rw-r--r--psutil/arch/windows/global.h5
3 files changed, 14 insertions, 18 deletions
diff --git a/psutil/_psutil_windows.c b/psutil/_psutil_windows.c
index ee044954..a3b08ad7 100644
--- a/psutil/_psutil_windows.c
+++ b/psutil/_psutil_windows.c
@@ -1045,10 +1045,6 @@ psutil_cpu_times(PyObject *self, PyObject *args) {
*/
static PyObject *
psutil_per_cpu_times(PyObject *self, PyObject *args) {
- // NtQuerySystemInformation stuff
- typedef DWORD (_stdcall * NTQSI_PROC) (int, PVOID, ULONG, PULONG);
- NTQSI_PROC NtQuerySystemInformation;
-
double idle, kernel, systemt, user, interrupt, dpc;
NTSTATUS status;
_SYSTEM_PROCESSOR_PERFORMANCE_INFORMATION *sppi = NULL;
@@ -1059,10 +1055,6 @@ psutil_per_cpu_times(PyObject *self, PyObject *args) {
if (py_retlist == NULL)
return NULL;
- NtQuerySystemInformation = \
- psutil_GetProcAddressFromLib("ntdll.dll", "NtQuerySystemInformation");
- if (NtQuerySystemInformation == NULL)
- goto error;
// retrieves number of processors
ncpus = psutil_get_num_cpus(1);
@@ -1079,7 +1071,7 @@ psutil_per_cpu_times(PyObject *self, PyObject *args) {
}
// gets cpu time informations
- status = NtQuerySystemInformation(
+ status = psutil_NtQuerySystemInformation(
SystemProcessorPerformanceInformation,
sppi,
ncpus * sizeof(_SYSTEM_PROCESSOR_PERFORMANCE_INFORMATION),
@@ -3457,7 +3449,6 @@ error:
static PyObject *
psutil_cpu_stats(PyObject *self, PyObject *args) {
typedef DWORD (_stdcall * NTQSI_PROC) (int, PVOID, ULONG, PULONG);
- NTQSI_PROC NtQuerySystemInformation;
NTSTATUS status;
_SYSTEM_PERFORMANCE_INFORMATION *spi = NULL;
_SYSTEM_PROCESSOR_PERFORMANCE_INFORMATION *sppi = NULL;
@@ -3467,11 +3458,6 @@ psutil_cpu_stats(PyObject *self, PyObject *args) {
ULONG64 dpcs = 0;
ULONG interrupts = 0;
- NtQuerySystemInformation = \
- psutil_GetProcAddressFromLib("ntdll.dll", "NtQuerySystemInformation");
- if (NtQuerySystemInformation == NULL)
- return NULL;
-
// retrieves number of processors
ncpus = psutil_get_num_cpus(1);
if (ncpus == 0)
@@ -3484,7 +3470,7 @@ psutil_cpu_stats(PyObject *self, PyObject *args) {
PyErr_NoMemory();
goto error;
}
- status = NtQuerySystemInformation(
+ status = psutil_NtQuerySystemInformation(
SystemPerformanceInformation,
spi,
ncpus * sizeof(_SYSTEM_PERFORMANCE_INFORMATION),
@@ -3502,7 +3488,7 @@ psutil_cpu_stats(PyObject *self, PyObject *args) {
goto error;
}
- status = NtQuerySystemInformation(
+ status = psutil_NtQuerySystemInformation(
SystemInterruptInformation,
InterruptInformation,
ncpus * sizeof(SYSTEM_INTERRUPT_INFORMATION),
@@ -3523,7 +3509,7 @@ psutil_cpu_stats(PyObject *self, PyObject *args) {
goto error;
}
- status = NtQuerySystemInformation(
+ status = psutil_NtQuerySystemInformation(
SystemProcessorPerformanceInformation,
sppi,
ncpus * sizeof(_SYSTEM_PROCESSOR_PERFORMANCE_INFORMATION),
diff --git a/psutil/arch/windows/global.c b/psutil/arch/windows/global.c
index 515ca31b..6a50176b 100644
--- a/psutil/arch/windows/global.c
+++ b/psutil/arch/windows/global.c
@@ -51,6 +51,11 @@ ps_GetProcAddressFromLib(LPCSTR libname, LPCSTR procname) {
int
psutil_load_globals() {
+ psutil_NtQuerySystemInformation = ps_GetProcAddressFromLib(
+ "ntdll.dll", "NtQuerySystemInformation");
+ if (psutil_NtQuerySystemInformation == NULL)
+ return 1;
+
psutil_NtQueryInformationProcess = ps_GetProcAddress(
"ntdll.dll", "NtQueryInformationProcess");
if (! psutil_NtQueryInformationProcess)
diff --git a/psutil/arch/windows/global.h b/psutil/arch/windows/global.h
index 777dd3db..9fa48e42 100644
--- a/psutil/arch/windows/global.h
+++ b/psutil/arch/windows/global.h
@@ -9,6 +9,7 @@
typedef PSTR (NTAPI * _RtlIpv4AddressToStringA)(struct in_addr *, PSTR);
typedef PSTR (NTAPI * _RtlIpv6AddressToStringA)(struct in6_addr *, PSTR);
+typedef DWORD (_stdcall * NTQSI_PROC) (int, PVOID, ULONG, PULONG);
_RtlIpv4AddressToStringA \
psutil_rtlIpv4AddressToStringA;
@@ -22,4 +23,8 @@ _RtlIpv6AddressToStringA \
_NtSetInformationProcess
psutil_NtSetInformationProcess;
+NTQSI_PROC \
+ psutil_NtQuerySystemInformation;
+
+
int psutil_load_globals();