]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
src: add constants for domain stats 'balloon.' parameters
authorDaniel P. Berrangé <berrange@redhat.com>
Thu, 27 Feb 2025 13:42:08 +0000 (13:42 +0000)
committerDaniel P. Berrangé <berrange@redhat.com>
Wed, 12 Mar 2025 09:59:48 +0000 (09:59 +0000)
Contrary to most APIs returning typed parameters, there are no constants
defined for the domain stats data keys. This is was because many of the
keys needs to be dynamically constructed using one or more array index
values.

It is possible to define constants while still supporting dynamic
array indexes by simply defining the prefixes and suffixes as constants.
The consuming code can then combine the constants with array index
value.

With this approach, it is practical to add constants for the domain stats
API keys.

Reviewed-by: Peter Krempa <pkrempa@redhat.com>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
include/libvirt/libvirt-domain.h
src/libvirt-domain.c
src/qemu/qemu_driver.c

index b3605717effb6f0024a7acade01bbfd3c24a2faa..e2a3bbe08ac8a8734df24c0905e34815fde6d393 100644 (file)
@@ -2943,6 +2943,142 @@ struct _virDomainStatsRecord {
  */
 # define VIR_DOMAIN_STATS_CPU_CACHE_MONITOR_SUFFIX_BANK_SUFFIX_BYTES ".bytes"
 
+
+/**
+ * VIR_DOMAIN_STATS_BALLOON_CURRENT:
+ *
+ * The memory in kiB currently used as unsigned long long.
+ *
+ * Since: 11.2.0
+ */
+# define VIR_DOMAIN_STATS_BALLOON_CURRENT "balloon.current"
+
+/**
+ * VIR_DOMAIN_STATS_BALLOON_MAXIMUM:
+ *
+ * The maximum memory in kiB allowed as unsigned long long.
+ *
+ * Since: 11.2.0
+ */
+# define VIR_DOMAIN_STATS_BALLOON_MAXIMUM "balloon.maximum"
+
+/**
+ * VIR_DOMAIN_STATS_BALLOON_SWAP_IN:
+ *
+ * The amount of data read from swap space (in KiB) as unsigned long long.
+ *
+ * Since: 11.2.0
+ */
+# define VIR_DOMAIN_STATS_BALLOON_SWAP_IN "balloon.swap_in"
+
+/**
+ * VIR_DOMAIN_STATS_BALLOON_SWAP_OUT:
+ *
+ * The amount of memory written out to swap space (in KiB) as unsigned long
+ * long.
+ *
+ * Since: 11.2.0
+ */
+# define VIR_DOMAIN_STATS_BALLOON_SWAP_OUT "balloon.swap_out"
+
+/**
+ * VIR_DOMAIN_STATS_BALLOON_MAJOR_FAULT:
+ *
+ * The number of page faults when disk IO was required as unsigned long long.
+ *
+ * Since: 11.2.0
+ */
+# define VIR_DOMAIN_STATS_BALLOON_MAJOR_FAULT "balloon.major_fault"
+
+/**
+ * VIR_DOMAIN_STATS_BALLOON_MINOR_FAULT:
+ *
+ * The number of other page faults as unsigned long long.
+ *
+ * Since: 11.2.0
+ */
+# define VIR_DOMAIN_STATS_BALLOON_MINOR_FAULT "balloon.minor_fault"
+
+/**
+ * VIR_DOMAIN_STATS_BALLOON_UNUSED:
+ *
+ * The amount of memory left unused by the system (in KiB) as unsigned long
+ * long.
+ *
+ * Since: 11.2.0
+ */
+# define VIR_DOMAIN_STATS_BALLOON_UNUSED "balloon.unused"
+
+/**
+ * VIR_DOMAIN_STATS_BALLOON_AVAILABLE:
+ *
+ * The amount of usable memory as seen by the domain (in KiB) as unsigned long
+ * long.
+ *
+ * Since: 11.2.0
+ */
+# define VIR_DOMAIN_STATS_BALLOON_AVAILABLE "balloon.available"
+
+/**
+ * VIR_DOMAIN_STATS_BALLOON_RSS:
+ *
+ * Resident Set Size of running domain's process (in KiB) as unsigned long
+ * long.
+ *
+ * Since: 11.2.0
+ */
+# define VIR_DOMAIN_STATS_BALLOON_RSS "balloon.rss"
+
+/**
+ * VIR_DOMAIN_STATS_BALLOON_USABLE:
+ *
+ * The amount of memory which can be reclaimed by balloon without causing host
+ * swapping (in KiB) as unsigned long long.
+ *
+ * Since: 11.2.0
+ */
+# define VIR_DOMAIN_STATS_BALLOON_USABLE "balloon.usable"
+
+/**
+ * VIR_DOMAIN_STATS_BALLOON_LAST_UPDATE:
+ *
+ * Timestamp of the last update of statistics (in seconds) as unsigned long
+ * long.
+ *
+ * Since: 11.2.0
+ */
+# define VIR_DOMAIN_STATS_BALLOON_LAST_UPDATE "balloon.last-update"
+
+/**
+ * VIR_DOMAIN_STATS_BALLOON_DISK_CACHES:
+ *
+ * The amount of memory that can be reclaimed without additional I/O,
+ * typically disk (in KiB) as unsigned long long.
+ *
+ * Since: 11.2.0
+ */
+# define VIR_DOMAIN_STATS_BALLOON_DISK_CACHES "balloon.disk_caches"
+
+/**
+ * VIR_DOMAIN_STATS_BALLOON_HUGETLB_PGALLOC:
+ *
+ * The number of successful huge page allocations from inside the domain via
+ * virtio balloon as unsigned long long.
+ *
+ * Since: 11.2.0
+ */
+# define VIR_DOMAIN_STATS_BALLOON_HUGETLB_PGALLOC "balloon.hugetlb_pgalloc"
+
+/**
+ * VIR_DOMAIN_STATS_BALLOON_HUGETLB_PGFAIL:
+ *
+ * The number of failed huge page allocations from inside the domain via
+ * virtio balloon as unsigned long long.
+ *
+ * Since: 11.2.0
+ */
+# define VIR_DOMAIN_STATS_BALLOON_HUGETLB_PGFAIL "balloon.hugetlb_pgfail"
+
 /**
  * virDomainStatsTypes:
  *
index 3d22fa112bf4dba6733c54cdfd5a30a9a9460db4..a8c4b8cfc15147167ebbd23bb6caba7e58737699 100644 (file)
@@ -12251,40 +12251,8 @@ virConnectGetDomainCapabilities(virConnectPtr conn,
  *
  * VIR_DOMAIN_STATS_BALLOON:
  *     Return memory balloon device information.
- *     The typed parameter keys are in this format:
- *
- *     "balloon.current" - the memory in kiB currently used
- *                         as unsigned long long.
- *     "balloon.maximum" - the maximum memory in kiB allowed
- *                         as unsigned long long.
- *     "balloon.swap_in" - the amount of data read from swap space (in KiB)
- *                         as unsigned long long
- *     "balloon.swap_out" - the amount of memory written out to swap space
- *                          (in KiB) as unsigned long long
- *     "balloon.major_fault" - the number of page faults when disk IO was
- *                             required as unsigned long long
- *     "balloon.minor_fault" - the number of other page faults
- *                             as unsigned long long
- *     "balloon.unused" - the amount of memory left unused by the system
- *                        (in KiB) as unsigned long long
- *     "balloon.available" - the amount of usable memory as seen by the domain
- *                           (in KiB) as unsigned long long
- *     "balloon.rss" - Resident Set Size of running domain's process
- *                     (in KiB) as unsigned long long
- *     "balloon.usable" - the amount of memory which can be reclaimed by balloon
- *                        without causing host swapping (in KiB)
- *                        as unsigned long long
- *     "balloon.last-update" - timestamp of the last update of statistics
- *                             (in seconds) as unsigned long long
- *     "balloon.disk_caches" - the amount of memory that can be reclaimed
- *                             without additional I/O, typically disk (in KiB)
- *                             as unsigned long long
- *     "balloon.hugetlb_pgalloc" - the number of successful huge page allocations
- *                                 from inside the domain via virtio balloon
- *                                 as unsigned long long
- *     "balloon.hugetlb_pgfail" - the number of failed huge page allocations
- *                                from inside the domain via virtio balloon
- *                                as unsigned long long
+ *     The VIR_DOMAIN_STATS_BALLOON_* constants define the known typed
+ *     parameter keys.
  *
  * VIR_DOMAIN_STATS_VCPU:
  *     Return virtual CPU statistics.
index 1684af384ecb126d73ea668f68a386fcb13122ca..27b89972263a49fcca0d11a1c7ed77b76f01ebbc 100644 (file)
@@ -16990,8 +16990,10 @@ qemuDomainGetStatsBalloon(virQEMUDriver *driver G_GNUC_UNUSED,
         cur_balloon = dom->def->mem.cur_balloon;
     }
 
-    virTypedParamListAddULLong(params, cur_balloon, "balloon.current");
-    virTypedParamListAddULLong(params, virDomainDefGetMemoryTotal(dom->def), "balloon.maximum");
+    virTypedParamListAddULLong(params, cur_balloon,
+                               VIR_DOMAIN_STATS_BALLOON_CURRENT);
+    virTypedParamListAddULLong(params, virDomainDefGetMemoryTotal(dom->def),
+                               VIR_DOMAIN_STATS_BALLOON_MAXIMUM);
 
     if (!HAVE_JOB(privflags) || !virDomainObjIsActive(dom))
         return;
@@ -17001,23 +17003,23 @@ qemuDomainGetStatsBalloon(virQEMUDriver *driver G_GNUC_UNUSED,
     if (nr_stats < 0)
         return;
 
-#define STORE_MEM_RECORD(TAG, NAME) \
+#define STORE_MEM_RECORD(TAG) \
     if (stats[i].tag == VIR_DOMAIN_MEMORY_STAT_ ##TAG) \
-        virTypedParamListAddULLong(params, stats[i].val, "balloon." NAME);
+        virTypedParamListAddULLong(params, stats[i].val,  VIR_DOMAIN_STATS_BALLOON_ ##TAG)
 
     for (i = 0; i < nr_stats; i++) {
-        STORE_MEM_RECORD(SWAP_IN, "swap_in")
-        STORE_MEM_RECORD(SWAP_OUT, "swap_out")
-        STORE_MEM_RECORD(MAJOR_FAULT, "major_fault")
-        STORE_MEM_RECORD(MINOR_FAULT, "minor_fault")
-        STORE_MEM_RECORD(UNUSED, "unused")
-        STORE_MEM_RECORD(AVAILABLE, "available")
-        STORE_MEM_RECORD(RSS, "rss")
-        STORE_MEM_RECORD(LAST_UPDATE, "last-update")
-        STORE_MEM_RECORD(USABLE, "usable")
-        STORE_MEM_RECORD(DISK_CACHES, "disk_caches")
-        STORE_MEM_RECORD(HUGETLB_PGALLOC, "hugetlb_pgalloc")
-        STORE_MEM_RECORD(HUGETLB_PGFAIL, "hugetlb_pgfail")
+        STORE_MEM_RECORD(SWAP_IN);
+        STORE_MEM_RECORD(SWAP_OUT);
+        STORE_MEM_RECORD(MAJOR_FAULT);
+        STORE_MEM_RECORD(MINOR_FAULT);
+        STORE_MEM_RECORD(UNUSED);
+        STORE_MEM_RECORD(AVAILABLE);
+        STORE_MEM_RECORD(RSS);
+        STORE_MEM_RECORD(LAST_UPDATE);
+        STORE_MEM_RECORD(USABLE);
+        STORE_MEM_RECORD(DISK_CACHES);
+        STORE_MEM_RECORD(HUGETLB_PGALLOC);
+        STORE_MEM_RECORD(HUGETLB_PGFAIL);
     }
 
 #undef STORE_MEM_RECORD