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@redhat.com>
---
include/libvirt/libvirt-domain.h | 70 ++++++++++++++++++++++++++++++++
src/libvirt-domain.c | 5 ++-
src/qemu/qemu_driver.c | 22 ++++++----
3 files changed, 87 insertions(+), 10 deletions(-)
diff --git a/include/libvirt/libvirt-domain.h b/include/libvirt/libvirt-domain.h
index e76d1d9319..a412f9ecfd 100644
--- a/include/libvirt/libvirt-domain.h
+++ b/include/libvirt/libvirt-domain.h
@@ -3835,6 +3835,76 @@ struct _virDomainStatsRecord {
*/
#define VIR_DOMAIN_STATS_MEMORY_BANDWIDTH_MONITOR_SUFFIX_NODE_SUFFIX_BYTES_TOTAL ".bytes.total"
+
+/**
+ * VIR_DOMAIN_STATS_DIRTYRATE_CALC_STATUS:
+ *
+ * The status of last memory dirty rate calculation as an int from the
+ * virDomainDirtyRateStatus enum.
+ *
+ * Since: 11.2.0
+ */
+#define VIR_DOMAIN_STATS_DIRTYRATE_CALC_STATUS "dirtyrate.calc_status"
+
+/**
+ * VIR_DOMAIN_STATS_DIRTYRATE_CALC_START_TIME:
+ *
+ * The start time in seconds of the last memory dirty rate calculation as long
+ * long.
+ *
+ * Since: 11.2.0
+ */
+#define VIR_DOMAIN_STATS_DIRTYRATE_CALC_START_TIME "dirtyrate.calc_start_time"
+
+/**
+ * VIR_DOMAIN_STATS_DIRTYRATE_CALC_PERIOD:
+ *
+ * The period in seconds of last memory dirty rate calculation as int.
+ *
+ * Since: 11.2.0
+ */
+#define VIR_DOMAIN_STATS_DIRTYRATE_CALC_PERIOD "dirtyrate.calc_period"
+
+/**
+ * VIR_DOMAIN_STATS_DIRTYRATE_MEGABYTES_PER_SECOND:
+ *
+ * The calculated memory dirty rate in MiB/s as long long. It is produced only
+ * if the calc_status is measured.
+ *
+ * Since: 11.2.0
+ */
+#define VIR_DOMAIN_STATS_DIRTYRATE_MEGABYTES_PER_SECOND "dirtyrate.megabytes_per_second"
+
+/**
+ * VIR_DOMAIN_STATS_DIRTYRATE_CALC_MODE:
+ *
+ * The calculation mode used last measurement as string, either of these
+ * 'page-sampling', 'dirty-bitmap' or 'dirty-ring' values returned.
+ *
+ * Since: 11.2.0
+ */
+#define VIR_DOMAIN_STATS_DIRTYRATE_CALC_MODE "dirtyrate.calc_mode"
+
+/**
+ * VIR_DOMAIN_STATS_DIRTYRATE_VCPU_PREFIX:
+ *
+ * The parameter name prefix to access each VCPU entry. Concatenate the
+ * prefix, the entry number formatted as an unsigned integer and one of the
+ * VCPU suffix parameters to form a complete parameter name.
+ *
+ * Since: 11.2.0
+ */
+#define VIR_DOMAIN_STATS_DIRTYRATE_VCPU_PREFIX "dirtyrate.vcpu."
+
+/**
+ * VIR_DOMAIN_STATS_DIRTYRATE_VCPU_SUFFIX_MEGABYTES_PER_SECOND:
+ *
+ * The calculated memory dirty rate for a virtual cpu as unsigned long long.
+ *
+ * Since: 11.2.0
+ */
+#define VIR_DOMAIN_STATS_DIRTYRATE_VCPU_SUFFIX_MEGABYTES_PER_SECOND ".megabytes_per_second"
+
/**
* virDomainStatsTypes:
*
diff --git a/src/libvirt-domain.c b/src/libvirt-domain.c
index 9111184d57..02fee7b5b9 100644
--- a/src/libvirt-domain.c
+++ b/src/libvirt-domain.c
@@ -12320,8 +12320,9 @@ virConnectGetDomainCapabilities(virConnectPtr conn,
* parameter keys.
*
* VIR_DOMAIN_STATS_DIRTYRATE:
- * Return memory dirty rate information. The typed parameter keys are in
- * this format:
+ * Return memory dirty rate information.
+ * The VIR_DOMAIN_STATS_DIRTYRATE_* constants define the known typed
+ * parameter keys.
*
* "dirtyrate.calc_status" - the status of last memory dirty rate calculation,
* returned as int from virDomainDirtyRateStatus
diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index d48e79d5c6..4747308d01 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -17743,21 +17743,27 @@ qemuDomainGetStatsDirtyRate(virQEMUDriver *driver G_GNUC_UNUSED,
return;
}
- virTypedParamListAddInt(params, info.status, "dirtyrate.calc_status");
- virTypedParamListAddLLong(params, info.startTime, "dirtyrate.calc_start_time");
- virTypedParamListAddInt(params, info.calcTime, "dirtyrate.calc_period");
+ virTypedParamListAddInt(params, info.status,
+ VIR_DOMAIN_STATS_DIRTYRATE_CALC_STATUS);
+ virTypedParamListAddLLong(params, info.startTime,
+ VIR_DOMAIN_STATS_DIRTYRATE_CALC_START_TIME);
+ virTypedParamListAddInt(params, info.calcTime,
+ VIR_DOMAIN_STATS_DIRTYRATE_CALC_PERIOD);
virTypedParamListAddString(params, qemuMonitorDirtyRateCalcModeTypeToString(info.mode),
- "dirtyrate.calc_mode");
+ VIR_DOMAIN_STATS_DIRTYRATE_CALC_MODE);
if (info.status == VIR_DOMAIN_DIRTYRATE_MEASURED) {
- virTypedParamListAddLLong(params, info.dirtyRate, "dirtyrate.megabytes_per_second");
+ virTypedParamListAddLLong(params, info.dirtyRate,
+ VIR_DOMAIN_STATS_DIRTYRATE_MEGABYTES_PER_SECOND);
if (info.mode == QEMU_MONITOR_DIRTYRATE_CALC_MODE_DIRTY_RING) {
size_t i;
for (i = 0; i < info.nvcpus; i++) {
- virTypedParamListAddULLong(params, info.rates[i].value,
- "dirtyrate.vcpu.%d.megabytes_per_second",
- info.rates[i].idx);
+ virTypedParamListAddULLong(
+ params, info.rates[i].value,
+ VIR_DOMAIN_STATS_DIRTYRATE_VCPU_PREFIX "%d"
+ VIR_DOMAIN_STATS_DIRTYRATE_VCPU_SUFFIX_MEGABYTES_PER_SECOND,
+ info.rates[i].idx);
}
}
}
--
2.48.1