summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGiampaolo Rodola <g.rodola@gmail.com>2020-01-03 17:21:56 -0800
committerGiampaolo Rodola <g.rodola@gmail.com>2020-01-03 17:21:56 -0800
commit161accb06f7d0eae089d2844ac43720f889a4e8d (patch)
treed16f19296064410b86557813795c833cb2aba363
parentf07973461f89987aa827a81d2644498e6abbe0a9 (diff)
downloadpsutil-161accb06f7d0eae089d2844ac43720f889a4e8d.tar.gz
rm duplicated C code
-rw-r--r--psutil/_psutil_windows.c120
-rw-r--r--psutil/arch/windows/security.c1
-rw-r--r--psutil/arch/windows/services.c7
3 files changed, 0 insertions, 128 deletions
diff --git a/psutil/_psutil_windows.c b/psutil/_psutil_windows.c
index a98e1c4d..69e129eb 100644
--- a/psutil/_psutil_windows.c
+++ b/psutil/_psutil_windows.c
@@ -712,124 +712,6 @@ psutil_virtual_mem(PyObject *self, PyObject *args) {
memInfo.ullAvailVirtual); // avail virtual
}
-/*
- * Retrieves system CPU timing information as a (user, system, idle)
- * tuple. On a multiprocessor system, the values returned are the
- * sum of the designated times across all processors.
- */
-static PyObject *
-psutil_cpu_times(PyObject *self, PyObject *args) {
- double idle, kernel, user, system;
- FILETIME idle_time, kernel_time, user_time;
-
- if (!GetSystemTimes(&idle_time, &kernel_time, &user_time))
- return PyErr_SetFromWindowsErr(0);
-
- idle = (double)((HI_T * idle_time.dwHighDateTime) + \
- (LO_T * idle_time.dwLowDateTime));
- user = (double)((HI_T * user_time.dwHighDateTime) + \
- (LO_T * user_time.dwLowDateTime));
- kernel = (double)((HI_T * kernel_time.dwHighDateTime) + \
- (LO_T * kernel_time.dwLowDateTime));
-
- // Kernel time includes idle time.
- // We return only busy kernel time subtracting idle time from
- // kernel time.
- system = (kernel - idle);
- return Py_BuildValue("(ddd)", user, system, idle);
-}
-
-
-/*
- * Same as above but for all system CPUs.
- */
-static PyObject *
-psutil_per_cpu_times(PyObject *self, PyObject *args) {
- double idle, kernel, systemt, user, interrupt, dpc;
- NTSTATUS status;
- _SYSTEM_PROCESSOR_PERFORMANCE_INFORMATION *sppi = NULL;
- UINT i;
- unsigned int ncpus;
- PyObject *py_tuple = NULL;
- PyObject *py_retlist = PyList_New(0);
-
- if (py_retlist == NULL)
- return NULL;
-
- // retrieves number of processors
- ncpus = psutil_get_num_cpus(1);
- if (ncpus == 0)
- goto error;
-
- // allocates an array of _SYSTEM_PROCESSOR_PERFORMANCE_INFORMATION
- // structures, one per processor
- sppi = (_SYSTEM_PROCESSOR_PERFORMANCE_INFORMATION *) \
- malloc(ncpus * sizeof(_SYSTEM_PROCESSOR_PERFORMANCE_INFORMATION));
- if (sppi == NULL) {
- PyErr_NoMemory();
- goto error;
- }
-
- // gets cpu time informations
- status = psutil_NtQuerySystemInformation(
- SystemProcessorPerformanceInformation,
- sppi,
- ncpus * sizeof(_SYSTEM_PROCESSOR_PERFORMANCE_INFORMATION),
- NULL);
- if (! NT_SUCCESS(status)) {
- psutil_SetFromNTStatusErr(
- status,
- "NtQuerySystemInformation(SystemProcessorPerformanceInformation)"
- );
- goto error;
- }
-
- // computes system global times summing each
- // processor value
- idle = user = kernel = interrupt = dpc = 0;
- for (i = 0; i < ncpus; i++) {
- py_tuple = NULL;
- user = (double)((HI_T * sppi[i].UserTime.HighPart) +
- (LO_T * sppi[i].UserTime.LowPart));
- idle = (double)((HI_T * sppi[i].IdleTime.HighPart) +
- (LO_T * sppi[i].IdleTime.LowPart));
- kernel = (double)((HI_T * sppi[i].KernelTime.HighPart) +
- (LO_T * sppi[i].KernelTime.LowPart));
- interrupt = (double)((HI_T * sppi[i].InterruptTime.HighPart) +
- (LO_T * sppi[i].InterruptTime.LowPart));
- dpc = (double)((HI_T * sppi[i].DpcTime.HighPart) +
- (LO_T * sppi[i].DpcTime.LowPart));
-
- // kernel time includes idle time on windows
- // we return only busy kernel time subtracting
- // idle time from kernel time
- systemt = kernel - idle;
- py_tuple = Py_BuildValue(
- "(ddddd)",
- user,
- systemt,
- idle,
- interrupt,
- dpc
- );
- if (!py_tuple)
- goto error;
- if (PyList_Append(py_retlist, py_tuple))
- goto error;
- Py_CLEAR(py_tuple);
- }
-
- free(sppi);
- return py_retlist;
-
-error:
- Py_XDECREF(py_tuple);
- Py_DECREF(py_retlist);
- if (sppi)
- free(sppi);
- return NULL;
-}
-
/*
* Return process current working directory as a Python string.
@@ -1575,7 +1457,6 @@ psutil_proc_memory_maps(PyObject *self, PyObject *args) {
DWORD pid;
HANDLE hProcess = NULL;
PVOID baseAddress;
- ULONGLONG previousAllocationBase;
WCHAR mappedFileName[MAX_PATH];
LPVOID maxAddr;
// required by GetMappedFileNameW
@@ -1628,7 +1509,6 @@ psutil_proc_memory_maps(PyObject *self, PyObject *args) {
Py_CLEAR(py_tuple);
Py_CLEAR(py_str);
}
- previousAllocationBase = (ULONGLONG)basicInfo.AllocationBase;
baseAddress = (PCHAR)baseAddress + basicInfo.RegionSize;
}
diff --git a/psutil/arch/windows/security.c b/psutil/arch/windows/security.c
index 4e2c7435..fa838004 100644
--- a/psutil/arch/windows/security.c
+++ b/psutil/arch/windows/security.c
@@ -119,7 +119,6 @@ psutil_print_err() {
int
psutil_set_se_debug() {
HANDLE hToken;
- int err = 1;
if ((hToken = psutil_get_thisproc_token()) == NULL) {
// "return 1;" to get an exception
diff --git a/psutil/arch/windows/services.c b/psutil/arch/windows/services.c
index 92458494..839cf79e 100644
--- a/psutil/arch/windows/services.c
+++ b/psutil/arch/windows/services.c
@@ -18,7 +18,6 @@
SC_HANDLE
psutil_get_service_handler(char *service_name, DWORD scm_access, DWORD access)
{
- ENUM_SERVICE_STATUS_PROCESSW *lpService = NULL;
SC_HANDLE sc = NULL;
SC_HANDLE hService = NULL;
@@ -193,8 +192,6 @@ psutil_winservice_query_config(PyObject *self, PyObject *args) {
SC_HANDLE hService = NULL;
BOOL ok;
DWORD bytesNeeded = 0;
- DWORD resumeHandle = 0;
- DWORD dwBytes = 0;
QUERY_SERVICE_CONFIGW *qsc = NULL;
PyObject *py_tuple = NULL;
PyObject *py_unicode_display_name = NULL;
@@ -284,8 +281,6 @@ psutil_winservice_query_status(PyObject *self, PyObject *args) {
SC_HANDLE hService = NULL;
BOOL ok;
DWORD bytesNeeded = 0;
- DWORD resumeHandle = 0;
- DWORD dwBytes = 0;
SERVICE_STATUS_PROCESS *ssp = NULL;
PyObject *py_tuple = NULL;
@@ -355,8 +350,6 @@ psutil_winservice_query_descr(PyObject *self, PyObject *args) {
ENUM_SERVICE_STATUS_PROCESSW *lpService = NULL;
BOOL ok;
DWORD bytesNeeded = 0;
- DWORD resumeHandle = 0;
- DWORD dwBytes = 0;
SC_HANDLE hService = NULL;
SERVICE_DESCRIPTIONW *scd = NULL;
char *service_name;