On Tue, Mar 04, 2025 at 14:04:11 +0000, Daniel P. Berrangé wrote:
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.
Signed-off-by: Daniel P. Berrangé <berrange(a)redhat.com>
---
include/libvirt/libvirt-domain.h | 92 ++++++++++++++++++++++++++++++++
src/libvirt-domain.c | 19 +------
src/qemu/qemu_driver.c | 37 +++++++++----
3 files changed, 120 insertions(+), 28 deletions(-)
[...]
diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index 76e121144d..d48e79d5c6 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -16722,32 +16722,47 @@ qemuDomainGetStatsMemoryBandwidth(virQEMUDriver *driver,
[...]
for (j = 0; j < resdata[i]->nstats; j++) {
- virTypedParamListAddUInt(params, resdata[i]->stats[j]->id,
-
"memory.bandwidth.monitor.%zu.node.%zu.id", i, j);
-
+ virTypedParamListAddUInt(
+ params, resdata[i]->stats[j]->id,
+ VIR_DOMAIN_STATS_MEMORY_BANDWIDTH_MONITOR_PREFIX "%zu"
+ VIR_DOMAIN_STATS_MEMORY_BANDWIDTH_MONITOR_SUFFIX_NODE_PREFIX
"%zu"
+ VIR_DOMAIN_STATS_MEMORY_BANDWIDTH_MONITOR_SUFFIX_NODE_SUFFIX_ID, i, j);
formatting
features = resdata[i]->stats[j]->features;
for (k = 0; features[k]; k++) {
if (STREQ(features[k], "mbm_local_bytes")) {
/* The accumulative data passing through local memory
* controller is recorded with 64 bit counter. */
- virTypedParamListAddULLong(params,
resdata[i]->stats[j]->vals[k],
-
"memory.bandwidth.monitor.%zu.node.%zu.bytes.local", i, j);
+ virTypedParamListAddULLong(
+ params, resdata[i]->stats[j]->vals[k],
+ VIR_DOMAIN_STATS_MEMORY_BANDWIDTH_MONITOR_PREFIX
"%zu"
+ VIR_DOMAIN_STATS_MEMORY_BANDWIDTH_MONITOR_SUFFIX_NODE_PREFIX
"%zu"
+
VIR_DOMAIN_STATS_MEMORY_BANDWIDTH_MONITOR_SUFFIX_NODE_SUFFIX_BYTES_LOCAL, i, j);
...
}
if (STREQ(features[k], "mbm_total_bytes")) {
/* The accumulative data passing through local and remote
* memory controller is recorded with 64 bit counter. */
- virTypedParamListAddULLong(params,
resdata[i]->stats[j]->vals[k],
-
"memory.bandwidth.monitor.%zu.node.%zu.bytes.total", i, j);
+ virTypedParamListAddULLong(
+ params, resdata[i]->stats[j]->vals[k],
+ VIR_DOMAIN_STATS_MEMORY_BANDWIDTH_MONITOR_PREFIX
"%zu"
+ VIR_DOMAIN_STATS_MEMORY_BANDWIDTH_MONITOR_SUFFIX_NODE_PREFIX
"%zu"
+
VIR_DOMAIN_STATS_MEMORY_BANDWIDTH_MONITOR_SUFFIX_NODE_SUFFIX_BYTES_TOTAL, i, j);
...
Reviewed-by: Peter Krempa <pkrempa(a)redhat.com>