[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [Xen-changelog] [xen master] tools/python: expose xc_getcpuinfo()
commit a9958947e49644c917c2349a567b2005b08e7c1f Author: Zhigang Wang <zhigang.x.wang@xxxxxxxxxx> AuthorDate: Tue May 13 16:32:33 2014 -0400 Commit: Ian Campbell <ian.campbell@xxxxxxxxxx> CommitDate: Thu May 15 16:12:52 2014 +0100 tools/python: expose xc_getcpuinfo() This API can be used to get per physical CPU utilization. Testing: # python >>> import xen.lowlevel.xc >>> xc = xen.lowlevel.xc.xc() >>> xc.getcpuinfo() Traceback (most recent call last): File "<stdin>", line 1, in <module> TypeError: Required argument 'max_cpus' (pos 1) not found >>> xc.getcpuinfo(4) [{'idletime': 109322086128854}, {'idletime': 109336447648802}, {'idletime': 109069270544960}, {'idletime': 109065612611363}] >>> xc.getcpuinfo(100) [{'idletime': 109639015806078}, {'idletime': 109654551195681}, {'idletime': 109382107891193}, {'idletime': 109382057541119}] >>> xc.getcpuinfo(1) [{'idletime': 109682068418798}] >>> xc.getcpuinfo(2) [{'idletime': 109711311201330}, {'idletime': 109728458214729}] >>> xc.getcpuinfo(max_cpus=4) [{'idletime': 109747116214638}, {'idletime': 109764982453261}, {'idletime': 109491373228931}, {'idletime': 109489858724432}] Signed-off-by: Zhigang Wang <zhigang.x.wang@xxxxxxxxxx> Acked-by: Ian Campbell <ian.campbell@xxxxxxxxxx> --- tools/python/xen/lowlevel/xc/xc.c | 41 +++++++++++++++++++++++++++++++++++++ 1 files changed, 41 insertions(+), 0 deletions(-) diff --git a/tools/python/xen/lowlevel/xc/xc.c b/tools/python/xen/lowlevel/xc/xc.c index 737bdac..cb34446 100644 --- a/tools/python/xen/lowlevel/xc/xc.c +++ b/tools/python/xen/lowlevel/xc/xc.c @@ -1183,6 +1183,40 @@ static PyObject *pyxc_physinfo(XcObject *self) "virt_caps", virt_caps); } +static PyObject *pyxc_getcpuinfo(XcObject *self, PyObject *args, PyObject *kwds) +{ + xc_cpuinfo_t *cpuinfo, *cpuinfo_ptr; + PyObject *cpuinfo_list_obj, *cpuinfo_obj; + int max_cpus, nr_cpus, ret, i; + static char *kwd_list[] = { "max_cpus", NULL }; + static char kwd_type[] = "i"; + + if(!PyArg_ParseTupleAndKeywords(args, kwds, kwd_type, kwd_list, &max_cpus)) + return NULL; + + cpuinfo = malloc(sizeof(xc_cpuinfo_t) * max_cpus); + if (!cpuinfo) + return NULL; + + ret = xc_getcpuinfo(self->xc_handle, max_cpus, cpuinfo, &nr_cpus); + if (ret != 0) { + free(cpuinfo); + return pyxc_error_to_exception(self->xc_handle); + } + + cpuinfo_list_obj = PyList_New(0); + cpuinfo_ptr = cpuinfo; + for (i = 0; i < nr_cpus; i++) { + cpuinfo_obj = Py_BuildValue("{s:k}", "idletime", cpuinfo_ptr->idletime); + PyList_Append(cpuinfo_list_obj, cpuinfo_obj); + cpuinfo_ptr++; + } + + free(cpuinfo); + + return cpuinfo_list_obj; +} + static PyObject *pyxc_topologyinfo(XcObject *self) { #define MAX_CPU_INDEX 255 @@ -2611,6 +2645,13 @@ static PyMethodDef pyxc_methods[] = { "Returns [dict]: information about the hardware" " [None]: on failure.\n" }, + { "getcpuinfo", + (PyCFunction)pyxc_getcpuinfo, + METH_VARARGS | METH_KEYWORDS, "\n" + "Get information about physical CPUs\n" + "Returns [list]: information about physical CPUs" + " [None]: on failure.\n" }, + { "topologyinfo", (PyCFunction)pyxc_topologyinfo, METH_NOARGS, "\n" -- generated by git-patchbot for /home/xen/git/xen.git#master _______________________________________________ Xen-changelog mailing list Xen-changelog@xxxxxxxxxxxxx http://lists.xensource.com/xen-changelog
|
Lists.xenproject.org is hosted with RackSpace, monitoring our |