Skip to content
Browse files

add cpu list Python bindings

  • Loading branch information...
1 parent fde0017 commit de81b904972ea8305b0c0299b87e3a2a545af0cd @dougm dougm committed Jun 15, 2011
Showing with 48 additions and 0 deletions.
  1. +48 −0 bindings/python/_sigar.c
View
48 bindings/python/_sigar.c
@@ -367,6 +367,52 @@ static PyObject *pysigar_arp_list(PyObject *self, PyObject *args)
return RETVAL;
}
+static PyObject *pysigar_cpu_list(PyObject *self, PyObject *args)
+{
+ int status;
+ sigar_t *sigar = PySIGAR;
+ sigar_cpu_list_t cpus;
+ PyObject *RETVAL;
+
+ status = sigar_cpu_list_get(sigar, &cpus);
+ if (status != SIGAR_OK) {
+ PySigar_Croak();
+ return NULL;
+ }
+
+ RETVAL = pysigar_new_list((char *)&cpus.data[0],
+ cpus.number,
+ sizeof(*cpus.data),
+ &pysigar_PySigarCpuType);
+
+ sigar_cpu_list_destroy(sigar, &cpus);
+
+ return RETVAL;
+}
+
+static PyObject *pysigar_cpu_info_list(PyObject *self, PyObject *args)
+{
+ int status;
+ sigar_t *sigar = PySIGAR;
+ sigar_cpu_info_list_t cpu_infos;
+ PyObject *RETVAL;
+
+ status = sigar_cpu_info_list_get(sigar, &cpu_infos);
+ if (status != SIGAR_OK) {
+ PySigar_Croak();
+ return NULL;
+ }
+
+ RETVAL = pysigar_new_list((char *)&cpu_infos.data[0],
+ cpu_infos.number,
+ sizeof(*cpu_infos.data),
+ &pysigar_PySigarCpuInfoType);
+
+ sigar_cpu_info_list_destroy(sigar, &cpu_infos);
+
+ return RETVAL;
+}
+
static PyObject *pysigar_loadavg(PyObject *self, PyObject *args)
{
int status;
@@ -497,6 +543,8 @@ static PyMethodDef pysigar_methods[] = {
{ "net_route_list", pysigar_net_route_list, METH_NOARGS, NULL },
{ "file_system_list", pysigar_file_system_list, METH_NOARGS, NULL },
{ "arp_list", pysigar_arp_list, METH_NOARGS, NULL },
+ { "cpu_list", pysigar_cpu_list, METH_NOARGS, NULL },
+ { "cpu_info_list", pysigar_cpu_info_list, METH_NOARGS, NULL },
{ "loadavg", pysigar_loadavg, METH_NOARGS, NULL },
{ "who_list", pysigar_who_list, METH_NOARGS, NULL },
{ "proc_list", pysigar_proc_list, METH_VARARGS, NULL },

0 comments on commit de81b90

Please sign in to comment.
Something went wrong with that request. Please try again.