Add a new function 'virDomainMemoryStats' to the libvirt API. Export it via libvirt_public.syms Signed-off-by: Adam Litke <agl@xxxxxxxxxx> To: libvirt list <libvir-list@xxxxxxxxxx> --- src/libvirt.c | 64 +++++++++++++++++++++++++++++++++++++++++++++++ src/libvirt_public.syms | 2 + 2 files changed, 66 insertions(+), 0 deletions(-) diff --git a/src/libvirt.c b/src/libvirt.c index b14942d..0af1ee3 100644 --- a/src/libvirt.c +++ b/src/libvirt.c @@ -4045,6 +4045,70 @@ error: } /** + * virDomainMemStats: + * @dom: pointer to the domain object + * @stats: nr_stats-sized array of stat structures (returned) + * @nr_stats: number of memory statistics requested + * + * This function provides memory statistics for the domain. + * + * Up to 'nr_stats' elements of 'stats' will be populated with memory statistics + * from the domain. Only statistics supported by the domain, the driver, and + * this version of libvirt will be returned. + * + * Memory Statistics: + * + * VIR_MEMSTAT_SWAP_IN: + * The total amount of data read from swap space (in bytes). + * VIR_MEMSTAT_SWAP_OUT: + * The total amount of memory written out to swap space (in bytes). + * VIR_MEMSTAT_MAJOR_FAULT: + * The number of page faults that required disk IO to service. + * VIR_MEMSTAT_MINOR_FAULT: + * The number of page faults serviced without disk IO. + * VIR_MEMSTAT_MEM_FREE: + * The amount of memory which is not being used for any purpose (in bytes). + * VIR_MEMSTAT_MEM_TOTAL: + * The total amount of memory recognized by the domain's OS (in bytes). + * + * Returns: The number of stats provided or -1 in case of failure. + */ +int virDomainMemoryStats (virDomainPtr dom, virDomainMemoryStatPtr stats, + unsigned int nr_stats) +{ + virConnectPtr conn; + unsigned long nr_stats_ret = 0; + DEBUG("domain=%p, stats=%p, nr_stats=%u", dom, stats, nr_stats); + + virResetLastError(); + + if (!VIR_IS_CONNECTED_DOMAIN (dom)) { + virLibDomainError (NULL, VIR_ERR_INVALID_DOMAIN, __FUNCTION__); + return -1; + } + if (!stats || nr_stats == 0) + return 0; + + if (nr_stats > VIR_MEMSTAT_NR_TAGS) + nr_stats = VIR_MEMSTAT_NR_TAGS; + + conn = dom->conn; + if (conn->driver->domainMemoryStats) { + nr_stats_ret = conn->driver->domainMemoryStats (dom, stats, nr_stats); + if (nr_stats_ret == -1) + goto error; + return nr_stats_ret; + } + + virLibDomainError (dom, VIR_ERR_NO_SUPPORT, __FUNCTION__); + +error: + /* Copy to connection error object for back compatability */ + virSetConnError(dom->conn); + return -1; +} + +/** * virDomainBlockPeek: * @dom: pointer to the domain object * @path: path to the block device diff --git a/src/libvirt_public.syms b/src/libvirt_public.syms index 8921c1a..5761a7e 100644 --- a/src/libvirt_public.syms +++ b/src/libvirt_public.syms @@ -327,6 +327,8 @@ LIBVIRT_0.7.2 { virStreamAbort; virStreamFree; virDomainMigrateToURI; + # XXX: For testing only -- Move to 0.7.3 section + virDomainMemoryStats; } LIBVIRT_0.7.1; # .... define new API here using predicted next version number .... -- 1.6.5 -- Libvir-list mailing list Libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list