Skip to content

Commit

Permalink
#799 / windows / cpu_times: add ionice() support
Browse files Browse the repository at this point in the history
  • Loading branch information
giampaolo committed Aug 6, 2016
1 parent c8c8dfb commit 614ecab
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 9 deletions.
10 changes: 3 additions & 7 deletions psutil/_psutil_windows.c
Expand Up @@ -1944,27 +1944,23 @@ psutil_proc_priority_set(PyObject *self, PyObject *args) {
static PyObject *
psutil_proc_io_priority_get(PyObject *self, PyObject *args) {
long pid;
HANDLE hProcess;
unsigned long handle;
PULONG IoPriority;

_NtQueryInformationProcess NtQueryInformationProcess =
(_NtQueryInformationProcess)GetProcAddress(
GetModuleHandleA("ntdll.dll"), "NtQueryInformationProcess");

if (! PyArg_ParseTuple(args, "l", &pid))
return NULL;
hProcess = psutil_handle_from_pid(pid);
if (hProcess == NULL)
if (! PyArg_ParseTuple(args, "lk", &pid, &handle))
return NULL;

NtQueryInformationProcess(
hProcess,
(HANDLE)handle,
ProcessIoPriority,
&IoPriority,
sizeof(ULONG),
NULL
);
CloseHandle(hProcess);
return Py_BuildValue("i", IoPriority);
}

Expand Down
3 changes: 2 additions & 1 deletion psutil/_pswindows.py
Expand Up @@ -803,7 +803,8 @@ def nice_set(self, value):
if hasattr(cext, "proc_io_priority_get"):
@wrap_exceptions
def ionice_get(self):
return cext.proc_io_priority_get(self.pid)
with self.handle_ctx() as handle:
return cext.proc_io_priority_get(self.pid, handle)

@wrap_exceptions
def ionice_set(self, value, _):
Expand Down
3 changes: 2 additions & 1 deletion scripts/internal/bench_oneshot.py
Expand Up @@ -77,10 +77,11 @@
names = (
'cpu_percent',
'cpu_times',
'num_handles',
'ionice',
'memory_info',
'memory_percent',
'nice',
'num_handles',
)
else:
raise RuntimeError("platform %r not supported" % sys.platform)
Expand Down

0 comments on commit 614ecab

Please sign in to comment.