summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGiampaolo Rodola <g.rodola@gmail.com>2015-11-12 12:51:12 +0100
committerGiampaolo Rodola <g.rodola@gmail.com>2015-11-12 12:51:12 +0100
commit19817a146d0ebfa56a46a1cca41d5bf493d007c7 (patch)
tree5d0990db09dee7ab26360c5c4e4e0a9289c42603
parent7ae8a7ab88a9ea53434ac8dbfd8aa13180383743 (diff)
downloadpsutil-19817a146d0ebfa56a46a1cca41d5bf493d007c7.tar.gz
move stuff around
-rw-r--r--psutil/_psutil_bsd.c71
-rw-r--r--psutil/_psutil_bsd.h3
-rw-r--r--psutil/arch/bsd/freebsd.c68
-rw-r--r--psutil/arch/bsd/freebsd.h1
4 files changed, 69 insertions, 74 deletions
diff --git a/psutil/_psutil_bsd.c b/psutil/_psutil_bsd.c
index c73efd32..0042b052 100644
--- a/psutil/_psutil_bsd.c
+++ b/psutil/_psutil_bsd.c
@@ -1177,77 +1177,6 @@ error:
}
-#ifdef __FreeBSD__
-/*
- * Return a Python dict of tuples for disk I/O information
- */
-static PyObject *
-psutil_disk_io_counters(PyObject *self, PyObject *args) {
- int i;
- struct statinfo stats;
-
- PyObject *py_retdict = PyDict_New();
- PyObject *py_disk_info = NULL;
-
- if (py_retdict == NULL)
- return NULL;
- if (devstat_checkversion(NULL) < 0) {
- PyErr_Format(PyExc_RuntimeError, "devstat_checkversion() failed");
- goto error;
- }
-
- stats.dinfo = (struct devinfo *)malloc(sizeof(struct devinfo));
- if (stats.dinfo == NULL) {
- PyErr_NoMemory();
- goto error;
- }
- bzero(stats.dinfo, sizeof(struct devinfo));
-
- if (devstat_getdevs(NULL, &stats) == -1) {
- PyErr_Format(PyExc_RuntimeError, "devstat_getdevs() failed");
- goto error;
- }
-
- for (i = 0; i < stats.dinfo->numdevs; i++) {
- py_disk_info = NULL;
- struct devstat current;
- char disk_name[128];
- current = stats.dinfo->devices[i];
- snprintf(disk_name, sizeof(disk_name), "%s%d",
- current.device_name,
- current.unit_number);
-
- py_disk_info = Py_BuildValue(
- "(KKKKLL)",
- current.operations[DEVSTAT_READ], // no reads
- current.operations[DEVSTAT_WRITE], // no writes
- current.bytes[DEVSTAT_READ], // bytes read
- current.bytes[DEVSTAT_WRITE], // bytes written
- (long long) BT2MSEC(current.duration[DEVSTAT_READ]), // r time
- (long long) BT2MSEC(current.duration[DEVSTAT_WRITE]) // w time
- ); // finished transactions
- if (!py_disk_info)
- goto error;
- if (PyDict_SetItemString(py_retdict, disk_name, py_disk_info))
- goto error;
- Py_DECREF(py_disk_info);
- }
-
- if (stats.dinfo->mem_ptr)
- free(stats.dinfo->mem_ptr);
- free(stats.dinfo);
- return py_retdict;
-
-error:
- Py_XDECREF(py_disk_info);
- Py_DECREF(py_retdict);
- if (stats.dinfo != NULL)
- free(stats.dinfo);
- return NULL;
-}
-#endif
-
-
/*
* Return currently connected users as a list of tuples.
*/
diff --git a/psutil/_psutil_bsd.h b/psutil/_psutil_bsd.h
index f846c084..aec0ada7 100644
--- a/psutil/_psutil_bsd.h
+++ b/psutil/_psutil_bsd.h
@@ -40,6 +40,3 @@ static PyObject* psutil_disk_partitions(PyObject* self, PyObject* args);
static PyObject* psutil_net_io_counters(PyObject* self, PyObject* args);
static PyObject* psutil_pids(PyObject* self, PyObject* args);
static PyObject* psutil_users(PyObject* self, PyObject* args);
-#ifdef __FreeBSD__
-static PyObject* psutil_disk_io_counters(PyObject* self, PyObject* args);
-#endif
diff --git a/psutil/arch/bsd/freebsd.c b/psutil/arch/bsd/freebsd.c
index 461d6ac8..5c911fb5 100644
--- a/psutil/arch/bsd/freebsd.c
+++ b/psutil/arch/bsd/freebsd.c
@@ -28,6 +28,8 @@
#define TV2DOUBLE(t) ((t).tv_sec + (t).tv_usec / 1000000.0)
+#define BT2MSEC(bt) (bt.sec * 1000 + (((uint64_t) 1000000000 * (uint32_t) \
+ (bt.frac >> 32) ) >> 32 ) / 1000000)
#ifndef _PATH_DEVNULL
#define _PATH_DEVNULL "/dev/null"
#endif
@@ -692,3 +694,69 @@ error:
Py_DECREF(py_retlist);
return NULL;
}
+
+
+PyObject *
+psutil_disk_io_counters(PyObject *self, PyObject *args) {
+ int i;
+ struct statinfo stats;
+
+ PyObject *py_retdict = PyDict_New();
+ PyObject *py_disk_info = NULL;
+
+ if (py_retdict == NULL)
+ return NULL;
+ if (devstat_checkversion(NULL) < 0) {
+ PyErr_Format(PyExc_RuntimeError, "devstat_checkversion() failed");
+ goto error;
+ }
+
+ stats.dinfo = (struct devinfo *)malloc(sizeof(struct devinfo));
+ if (stats.dinfo == NULL) {
+ PyErr_NoMemory();
+ goto error;
+ }
+ bzero(stats.dinfo, sizeof(struct devinfo));
+
+ if (devstat_getdevs(NULL, &stats) == -1) {
+ PyErr_Format(PyExc_RuntimeError, "devstat_getdevs() failed");
+ goto error;
+ }
+
+ for (i = 0; i < stats.dinfo->numdevs; i++) {
+ py_disk_info = NULL;
+ struct devstat current;
+ char disk_name[128];
+ current = stats.dinfo->devices[i];
+ snprintf(disk_name, sizeof(disk_name), "%s%d",
+ current.device_name,
+ current.unit_number);
+
+ py_disk_info = Py_BuildValue(
+ "(KKKKLL)",
+ current.operations[DEVSTAT_READ], // no reads
+ current.operations[DEVSTAT_WRITE], // no writes
+ current.bytes[DEVSTAT_READ], // bytes read
+ current.bytes[DEVSTAT_WRITE], // bytes written
+ (long long) BT2MSEC(current.duration[DEVSTAT_READ]), // r time
+ (long long) BT2MSEC(current.duration[DEVSTAT_WRITE]) // w time
+ ); // finished transactions
+ if (!py_disk_info)
+ goto error;
+ if (PyDict_SetItemString(py_retdict, disk_name, py_disk_info))
+ goto error;
+ Py_DECREF(py_disk_info);
+ }
+
+ if (stats.dinfo->mem_ptr)
+ free(stats.dinfo->mem_ptr);
+ free(stats.dinfo);
+ return py_retdict;
+
+error:
+ Py_XDECREF(py_disk_info);
+ Py_DECREF(py_retdict);
+ if (stats.dinfo != NULL)
+ free(stats.dinfo);
+ return NULL;
+}
diff --git a/psutil/arch/bsd/freebsd.h b/psutil/arch/bsd/freebsd.h
index c40951e2..1c5705f2 100644
--- a/psutil/arch/bsd/freebsd.h
+++ b/psutil/arch/bsd/freebsd.h
@@ -24,3 +24,4 @@ PyObject* psutil_virtual_mem(PyObject* self, PyObject* args);
PyObject* psutil_swap_mem(PyObject* self, PyObject* args);
PyObject* psutil_proc_num_fds(PyObject* self, PyObject* args);
PyObject* psutil_per_cpu_times(PyObject* self, PyObject* args);
+PyObject* psutil_disk_io_counters(PyObject* self, PyObject* args);