On 2/20/22 14:28, huangy81(a)chinatelecom.cn wrote:
From: Hyman Huang(黄勇) <huangy81(a)chinatelecom.cn>
Add calc_mode for dirtyrate statistics retured by
virsh domstats --dirtyrate api, also add vcpu dirtyrate
if dirty-ring mode was used in last measurement.
Signed-off-by: Hyman Huang(黄勇) <huangy81(a)chinatelecom.cn>
---
src/libvirt-domain.c | 6 +++++
src/qemu/qemu_driver.c | 22 +++++++++++++++---
src/qemu/qemu_monitor.h | 10 +++++++++
src/qemu/qemu_monitor_json.c | 53 ++++++++++++++++++++++++++++++++++++++++++++
4 files changed, 88 insertions(+), 3 deletions(-)
diff --git a/src/libvirt-domain.c b/src/libvirt-domain.c
index 7be4e02..a197618 100644
--- a/src/libvirt-domain.c
+++ b/src/libvirt-domain.c
@@ -11980,6 +11980,12 @@ virConnectGetDomainCapabilities(virConnectPtr conn,
* "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.
+ * "dirtyrate.calc_mode" - the calculation mode used last measurement,
either
+ * of these 3
'page-sampling,dirty-bitmap,dirty-ring'
+ * values returned.
+ * "dirtyrate.vcpu.<num>.megabytes_per_second" - the calculated
memory dirty
+ * rate for a virtual cpu as
+ * unsigned long long.
*
* Note that entire stats groups or individual stat fields may be missing from
* the output in case they are not supported by the given hypervisor, are not
diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index 3297513..de2fdf7 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -18556,11 +18556,27 @@ qemuDomainGetStatsDirtyRate(virQEMUDriver *driver,
"dirtyrate.calc_period") < 0)
return -1;
- if ((info.status == VIR_DOMAIN_DIRTYRATE_MEASURED) &&
- virTypedParamListAddLLong(params, info.dirtyRate,
- "dirtyrate.megabytes_per_second") < 0)
+ if (virTypedParamListAddString(params,
+ qemuMonitorDirtyRateCalcModeTypeToString(info.mode),
+ "dirtyrate.calc_mode") < 0)
return -1;
+ if (info.status == VIR_DOMAIN_DIRTYRATE_MEASURED) {
+ if (virTypedParamListAddLLong(params, info.dirtyRate,
+ "dirtyrate.megabytes_per_second") <
0)
+ return -1;
+
+ if (info.mode == QEMU_MONITOR_DIRTYRATE_CALC_MODE_DIRTY_RING) {
+ int i;
Since info.nvcpus is size_t so must be i. We are not guaranteed that
size_t == int.
+ for (i = 0; i < info.nvcpus; i++) {
+ if (virTypedParamListAddULLong(params, info.rates[i].value,
+
"dirtyrate.vcpu.%d.megabytes_per_second",
+ info.rates[i].index) < 0)
+ return -1;
+ }
+ }
+ }
+
return 0;
}
diff --git a/src/qemu/qemu_monitor.h b/src/qemu/qemu_monitor.h
index 053479b..2c0eed5 100644
--- a/src/qemu/qemu_monitor.h
+++ b/src/qemu/qemu_monitor.h
@@ -1553,6 +1553,12 @@ qemuMonitorStartDirtyRateCalc(qemuMonitor *mon,
int seconds,
qemuMonitorDirtyRateCalcMode mode);
+typedef struct _qemuMonitorDirtyRateVcpu qemuMonitorDirtyRateVcpu;
+struct _qemuMonitorDirtyRateVcpu {
+ int index; /* virtual cpu index */
This makes our syntax-check report an error, because it thinks that
'index' is used to access an array (which must then be type of size_t
because that's the only type which is guaranteed to be big enough to
address individual bytes in memory). Let me change the name to 'idx'.
+ unsigned long long value; /* virtual cpu dirty page rate in
MB/s */
+};
+
typedef struct _qemuMonitorDirtyRateInfo qemuMonitorDirtyRateInfo;
struct _qemuMonitorDirtyRateInfo {
int status; /* the status of last dirtyrate calculation,
@@ -1560,6 +1566,10 @@ struct _qemuMonitorDirtyRateInfo {
int calcTime; /* the period of dirtyrate calculation */
long long startTime; /* the start time of dirtyrate calculation */
long long dirtyRate; /* the dirtyrate in MiB/s */
+ qemuMonitorDirtyRateCalcMode mode; /* calculation mode used in
+ last measurement */
+ size_t nvcpus; /* number of virtual cpu */
+ qemuMonitorDirtyRateVcpu *rates; /* array of dirty page rate */
};
int
diff --git a/src/qemu/qemu_monitor_json.c b/src/qemu/qemu_monitor_json.c
index da9a4d9..a07f8c9 100644
--- a/src/qemu/qemu_monitor_json.c
+++ b/src/qemu/qemu_monitor_json.c
@@ -8782,11 +8782,45 @@ VIR_ENUM_IMPL(qemuMonitorDirtyRateStatus,
"measured");
static int
+qemuMonitorJSONExtractVcpuDirtyRate(virJSONValue *data,
+ qemuMonitorDirtyRateInfo *info)
+{
+ size_t nvcpus;
+ int i;
Again, i has to be size_t.
+
+ nvcpus = virJSONValueArraySize(data);
+ info->nvcpus = nvcpus;
+ info->rates = g_new0(qemuMonitorDirtyRateVcpu, nvcpus);
+
+ for (i = 0; i < nvcpus; i++) {
+ virJSONValue *entry = virJSONValueArrayGet(data, i);
+ if (virJSONValueObjectGetNumberInt(entry, "id",
+ &info->rates[i].index) < 0) {
+ virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
+ _("query-dirty-rate reply was missing 'id'
data"));
+ return -1;
+ }
+
+ if (virJSONValueObjectGetNumberUlong(entry, "dirty-rate",
+ &info->rates[i].value) < 0) {
+ virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
+ _("query-dirty-rate reply was missing
'dirty-rate' data"));
+ return -1;
+ }
+ }
+
+ return 0;
+}
Michal