From: Nikolay Shirokovskiy <nshirokovskiy@xxxxxxxxxxxxx> Implemented counters: VIR_DOMAIN_MEMORY_STAT_SWAP_IN VIR_DOMAIN_MEMORY_STAT_SWAP_OUT VIR_DOMAIN_MEMORY_STAT_MINOR_FAULT VIR_DOMAIN_MEMORY_STAT_MAJOR_FAULT VIR_DOMAIN_MEMORY_STAT_AVAILABLE VIR_DOMAIN_MEMORY_STAT_ACTUAL_BALLOON VIR_DOMAIN_MEMORY_STAT_UNUSED Comments. 1. Use vzDomObjFromDomainRef/virDomainObjEndAPI pair to get domain object as we use prlsdkGetStatsParam. See previous statistics comments. 2. Balloon statistics is not applicable to containers. Fault statistics for containers not provided in PCS6 yet. Signed-off-by: Nikolay Shirokovskiy <nshirokovskiy@xxxxxxxxxxxxx> --- src/vz/vz_driver.c | 20 +++++++++++++++++ src/vz/vz_sdk.c | 61 ++++++++++++++++++++++++++++++++++++++++++++++++++++ src/vz/vz_sdk.h | 2 + 3 files changed, 83 insertions(+), 0 deletions(-) diff --git a/src/vz/vz_driver.c b/src/vz/vz_driver.c index d11ce18..488df83 100644 --- a/src/vz/vz_driver.c +++ b/src/vz/vz_driver.c @@ -1356,6 +1356,25 @@ vzDomainInterfaceStats(virDomainPtr domain, return ret; } +static int +vzDomainMemoryStats(virDomainPtr domain, + virDomainMemoryStatPtr stats, + unsigned int nr_stats, + unsigned int flags) +{ + virDomainObjPtr dom = NULL; + int ret = -1; + + virCheckFlags(0, -1); + if (!(dom = vzDomObjFromDomainRef(domain))) + return -1; + + ret = prlsdkGetMemoryStats(dom, stats, nr_stats); + virDomainObjEndAPI(&dom); + + return ret; +} + static virHypervisorDriver vzDriver = { .name = "vz", .connectOpen = vzConnectOpen, /* 0.10.0 */ @@ -1408,6 +1427,7 @@ static virHypervisorDriver vzDriver = { .domainBlockStats = vzDomainBlockStats, /* 1.3.0 */ .domainBlockStatsFlags = vzDomainBlockStatsFlags, /* 1.3.0 */ .domainInterfaceStats = vzDomainInterfaceStats, /* 1.3.0 */ + .domainMemoryStats = vzDomainMemoryStats, /* 1.3.0 */ }; static virConnectDriver vzConnectDriver = { diff --git a/src/vz/vz_sdk.c b/src/vz/vz_sdk.c index aeeada3..fff9608 100644 --- a/src/vz/vz_sdk.c +++ b/src/vz/vz_sdk.c @@ -3882,3 +3882,64 @@ prlsdkGetVcpuStats(virDomainObjPtr dom, int idx, unsigned long long *vtime) VIR_FREE(name); return ret; } + +int +prlsdkGetMemoryStats(virDomainObjPtr dom, + virDomainMemoryStatPtr stats, + unsigned int nr_stats) +{ + int ret = -1; + long long v = 0, t = 0, u = 0; + size_t i = 0; + +#define PRLSDK_GET_COUNTER(NAME, VALUE) \ + if (prlsdkGetStatsParam(dom, NAME, &VALUE) < 0) \ + goto cleanup; \ + +#define PRLSDK_MEMORY_STAT_SET(TAG, VALUE) \ + if (i < nr_stats) { \ + stats[i].tag = (TAG); \ + stats[i].val = (VALUE); \ + i++; \ + } + + i = 0; + + // count to kb + PRLSDK_GET_COUNTER("guest.ram.swap_in", v) + if (v != -1) + PRLSDK_MEMORY_STAT_SET(VIR_DOMAIN_MEMORY_STAT_SWAP_IN, v << 12) + + PRLSDK_GET_COUNTER("guest.ram.swap_out", v) + if (v != -1) + PRLSDK_MEMORY_STAT_SET(VIR_DOMAIN_MEMORY_STAT_SWAP_OUT, v << 12) + + PRLSDK_GET_COUNTER("guest.ram.minor_fault", v) + if (v != -1) + PRLSDK_MEMORY_STAT_SET(VIR_DOMAIN_MEMORY_STAT_MINOR_FAULT, v) + + PRLSDK_GET_COUNTER("guest.ram.major_fault", v) + if (v != -1) + PRLSDK_MEMORY_STAT_SET(VIR_DOMAIN_MEMORY_STAT_MAJOR_FAULT, v) + + PRLSDK_GET_COUNTER("guest.ram.total", v) + if (v != -1) + PRLSDK_MEMORY_STAT_SET(VIR_DOMAIN_MEMORY_STAT_AVAILABLE, v << 10) + + PRLSDK_GET_COUNTER("guest.ram.balloon_actual", v) + if (v != -1) + PRLSDK_MEMORY_STAT_SET(VIR_DOMAIN_MEMORY_STAT_ACTUAL_BALLOON, v << 10) + + PRLSDK_GET_COUNTER("guest.ram.usage", u) + PRLSDK_GET_COUNTER("guest.ram.total", t) + if (u != -1 && t != -1) + PRLSDK_MEMORY_STAT_SET(VIR_DOMAIN_MEMORY_STAT_UNUSED, (t - u) << 10) + +#undef PRLSDK_GET_COUNTER +#undef PRLSDK_MEMORY_STAT_SET + + ret = i; + cleanup: + + return ret; +} diff --git a/src/vz/vz_sdk.h b/src/vz/vz_sdk.h index ca38c59..ebe4591 100644 --- a/src/vz/vz_sdk.h +++ b/src/vz/vz_sdk.h @@ -74,3 +74,5 @@ int prlsdkGetNetStats(virDomainObjPtr dom, const char *path, virDomainInterfaceStatsPtr stats); int prlsdkGetVcpuStats(virDomainObjPtr dom, int idx, unsigned long long *time); +int +prlsdkGetMemoryStats(virDomainObjPtr dom, virDomainMemoryStatPtr stats, unsigned int nr_stats); -- 1.7.1 -- libvir-list mailing list libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list