| Index: third_party/psutil/psutil/_psutil_linux.c
|
| diff --git a/third_party/psutil/psutil/_psutil_linux.c b/third_party/psutil/psutil/_psutil_linux.c
|
| index 6915c0c81e4fac43ec4f9db7b8d48ebe9bd2a36f..47348fd71e77f55fe9c270d67b6fced6dddcea86 100644
|
| --- a/third_party/psutil/psutil/_psutil_linux.c
|
| +++ b/third_party/psutil/psutil/_psutil_linux.c
|
| @@ -1,5 +1,5 @@
|
| /*
|
| - * $Id: _psutil_linux.c 1142 2011-10-05 18:45:49Z g.rodola $
|
| + * $Id: _psutil_linux.c 1166 2011-10-17 22:18:07Z g.rodola $
|
| *
|
| * 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
|
| @@ -13,6 +13,7 @@
|
| #include <stdlib.h>
|
| #include <mntent.h>
|
| #include <sys/syscall.h>
|
| +#include <sys/sysinfo.h>
|
| #include <linux/unistd.h>
|
|
|
| #include "_psutil_linux.h"
|
| @@ -22,22 +23,22 @@
|
|
|
| #if HAS_IOPRIO
|
| enum {
|
| - IOPRIO_WHO_PROCESS = 1,
|
| + IOPRIO_WHO_PROCESS = 1,
|
| };
|
|
|
| static inline int
|
| ioprio_get(int which, int who)
|
| {
|
| - return syscall(__NR_ioprio_get, which, who);
|
| + return syscall(__NR_ioprio_get, which, who);
|
| }
|
|
|
| static inline int
|
| ioprio_set(int which, int who, int ioprio)
|
| {
|
| - return syscall(__NR_ioprio_set, which, who, ioprio);
|
| + return syscall(__NR_ioprio_set, which, who, ioprio);
|
| }
|
|
|
| -#define IOPRIO_CLASS_SHIFT 13
|
| +#define IOPRIO_CLASS_SHIFT 13
|
| #define IOPRIO_PRIO_MASK ((1UL << IOPRIO_CLASS_SHIFT) - 1)
|
|
|
| #define IOPRIO_PRIO_CLASS(mask) ((mask) >> IOPRIO_CLASS_SHIFT)
|
| @@ -52,7 +53,7 @@ static PyObject*
|
| linux_ioprio_get(PyObject* self, PyObject* args)
|
| {
|
| long pid;
|
| - int ioprio, ioclass, iodata;
|
| + int ioprio, ioclass, iodata;
|
| if (! PyArg_ParseTuple(args, "l", &pid)) {
|
| return NULL;
|
| }
|
| @@ -60,8 +61,8 @@ linux_ioprio_get(PyObject* self, PyObject* args)
|
| if (ioprio == -1) {
|
| return PyErr_SetFromErrno(PyExc_OSError);
|
| }
|
| - ioclass = IOPRIO_PRIO_CLASS(ioprio);
|
| - iodata = IOPRIO_PRIO_DATA(ioprio);
|
| + ioclass = IOPRIO_PRIO_CLASS(ioprio);
|
| + iodata = IOPRIO_PRIO_DATA(ioprio);
|
| return Py_BuildValue("ii", ioclass, iodata);
|
| }
|
|
|
| @@ -82,8 +83,8 @@ linux_ioprio_set(PyObject* self, PyObject* args)
|
| return NULL;
|
| }
|
| ioprio = IOPRIO_PRIO_VALUE(ioclass, iodata);
|
| - retval = ioprio_set(IOPRIO_WHO_PROCESS, pid, ioprio);
|
| - if (retval == -1) {
|
| + retval = ioprio_set(IOPRIO_WHO_PROCESS, pid, ioprio);
|
| + if (retval == -1) {
|
| return PyErr_SetFromErrno(PyExc_OSError);
|
| }
|
| Py_INCREF(Py_None);
|
| @@ -109,7 +110,7 @@ get_disk_partitions(PyObject* self, PyObject* args)
|
| file = setmntent(MOUNTED, "r");
|
| Py_END_ALLOW_THREADS
|
| if ((file == 0) || (file == NULL)) {
|
| - return PyErr_SetFromErrno(PyExc_OSError);
|
| + return PyErr_SetFromErrno(PyExc_OSError);
|
| }
|
|
|
| while ((entry = getmntent(file))) {
|
| @@ -130,6 +131,20 @@ get_disk_partitions(PyObject* self, PyObject* args)
|
|
|
|
|
| /*
|
| + * Return physical memory usage as a (total, free, buffer) tuple.
|
| + */
|
| +static PyObject*
|
| +get_physmem(PyObject* self, PyObject* args)
|
| +{
|
| + struct sysinfo info;
|
| + if (sysinfo(&info) != 0) {
|
| + return PyErr_SetFromErrno(PyExc_OSError);
|
| + }
|
| + return Py_BuildValue("(lll)", info.totalram, info.freeram, info.bufferram);
|
| +}
|
| +
|
| +
|
| +/*
|
| * Define the psutil C module methods and initialize the module.
|
| */
|
| static PyMethodDef
|
| @@ -144,6 +159,8 @@ PsutilMethods[] =
|
| {"get_disk_partitions", get_disk_partitions, METH_VARARGS,
|
| "Return disk mounted partitions as a list of tuples including "
|
| "device, mount point and filesystem type"},
|
| + {"get_physmem", get_physmem, METH_VARARGS,
|
| + "The physical memory usage as a (total, free, buffer) tuple."},
|
|
|
| {NULL, NULL, 0, NULL}
|
| };
|
|
|