Signed-off-by: Lai Jiangshan <laijs(a)cn.fujitsu.com>
---
include/libvirt/libvirt.h.in | 5 ++++
python/generator.py | 1 +
src/driver.h | 7 +++++
src/libvirt.c | 51 ++++++++++++++++++++++++++++++++++++++++++
src/libvirt_public.syms | 5 ++++
5 files changed, 69 insertions(+), 0 deletions(-)
diff --git a/include/libvirt/libvirt.h.in b/include/libvirt/libvirt.h.in
index d01d1bc..2ec6b6b 100644
--- a/include/libvirt/libvirt.h.in
+++ b/include/libvirt/libvirt.h.in
@@ -3487,6 +3487,11 @@ int virConnectSetKeepAlive(virConnectPtr conn,
int interval,
unsigned int count);
+int virDomainGetPcpusUsage(virDomainPtr dom,
+ unsigned long long *usages,
+ int *nr_usages,
+ unsigned int flags);
+
#ifdef __cplusplus
}
#endif
diff --git a/python/generator.py b/python/generator.py
index 88c52b9..a39244f 100755
--- a/python/generator.py
+++ b/python/generator.py
@@ -416,6 +416,7 @@ skip_impl = (
'virDomainBlockStatsFlags',
'virDomainSetBlockIoTune',
'virDomainGetBlockIoTune',
+ 'virDomainGetPcpusUsage', # not implemented yet
)
qemu_skip_impl = (
diff --git a/src/driver.h b/src/driver.h
index 941ff51..3d54370 100644
--- a/src/driver.h
+++ b/src/driver.h
@@ -770,6 +770,12 @@ typedef int
int *nparams,
unsigned int flags);
+typedef int
+ (*virDrvDomainGetPcpusUsage)(virDomainPtr dom,
+ unsigned long long *usages,
+ int *nr_usages,
+ unsigned int flags);
+
/**
* _virDriver:
*
@@ -934,6 +940,7 @@ struct _virDriver {
virDrvNodeSuspendForDuration nodeSuspendForDuration;
virDrvDomainSetBlockIoTune domainSetBlockIoTune;
virDrvDomainGetBlockIoTune domainGetBlockIoTune;
+ virDrvDomainGetPcpusUsage domainGetPcpusUsage;
};
typedef int
diff --git a/src/libvirt.c b/src/libvirt.c
index 68074e7..06a019c 100644
--- a/src/libvirt.c
+++ b/src/libvirt.c
@@ -17599,3 +17599,54 @@ error:
virDispatchError(dom->conn);
return -1;
}
+
+/**
+ * virDomainGetPcpusUsage:
+ * @dom: pointer to domain object
+ * @usages: returned physic cpu usages
+ * @nr_usages: length of @usages
+ * @flags: flags to control the operation
+ *
+ * Get the cpu usages per every physic cpu
+ *
+ * Returns 0 if success, -1 on error
+ */
+int virDomainGetPcpusUsage(virDomainPtr dom,
+ unsigned long long *usages,
+ int *nr_usages,
+ unsigned int flags)
+{
+ virConnectPtr conn;
+
+ VIR_DOMAIN_DEBUG(dom, "usages=%p, nr_usages=%d, flags=%x",
+ usages, (nr_usages) ? *nr_usages : -1, flags);
+
+ virResetLastError();
+
+ if (!VIR_IS_CONNECTED_DOMAIN (dom)) {
+ virLibDomainError(VIR_ERR_INVALID_DOMAIN, __FUNCTION__);
+ virDispatchError(NULL);
+ return -1;
+ }
+
+ if (nr_usages == NULL && *nr_usages != 0) {
+ virLibDomainError(VIR_ERR_INVALID_ARG, __FUNCTION__);
+ goto error;
+ }
+
+ conn = dom->conn;
+
+ if (conn->driver->domainGetPcpusUsage) {
+ int ret;
+ ret = conn->driver->domainGetPcpusUsage(dom, usages, nr_usages, flags);
+ if (ret < 0)
+ goto error;
+ return ret;
+ }
+
+ virLibDomainError(VIR_ERR_NO_SUPPORT, __FUNCTION__);
+
+error:
+ virDispatchError(dom->conn);
+ return -1;
+}
diff --git a/src/libvirt_public.syms b/src/libvirt_public.syms
index 164039a..05f8d9e 100644
--- a/src/libvirt_public.syms
+++ b/src/libvirt_public.syms
@@ -508,4 +508,9 @@ LIBVIRT_0.9.8 {
virNodeSuspendForDuration;
} LIBVIRT_0.9.7;
+LIBVIRT_0.9.9 {
+ global:
+ virDomainGetPcpusUsage;
+} LIBVIRT_0.9.8;
+
# .... define new API here using predicted next version number ....
--
1.7.4.4