qemu_driver: add new stats worker qemuDomainGetStatsVm

This patch adds a new worker qemuDomainGetStatsVm which reports the
stats returned by "query-stats" via qemuMonitorQueryStats for the VM
target.

Signed-off-by: Amneesh Singh <natto@weirdnatto.in>
This commit is contained in:
Amneesh Singh 2022-09-07 16:04:23 +05:30 committed by Martin Kletzander
parent 0f867a3831
commit 8c9e3dae14
4 changed files with 52 additions and 0 deletions

View File

@ -2710,6 +2710,7 @@ typedef enum {
VIR_DOMAIN_STATS_IOTHREAD = (1 << 7), /* return iothread poll info (Since: 4.10.0) */
VIR_DOMAIN_STATS_MEMORY = (1 << 8), /* return domain memory info (Since: 6.0.0) */
VIR_DOMAIN_STATS_DIRTYRATE = (1 << 9), /* return domain dirty rate info (Since: 7.2.0) */
VIR_DOMAIN_STATS_VM = (1 << 10), /* return vm info (Since: 8.6.0) */
} virDomainStatsTypes;
/**

View File

@ -12481,6 +12481,9 @@ virConnectGetDomainCapabilities(virConnectPtr conn,
* rate for a virtual cpu as
* unsigned long long.
*
* VIR_DOMAIN_STATS_VM:
* Return fd-based KVM statistics for the target VM
*
* 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
* applicable for the current state of the guest domain, or their retrieval

View File

@ -18709,6 +18709,41 @@ qemuDomainGetStatsDirtyRate(virQEMUDriver *driver G_GNUC_UNUSED,
return 0;
}
static int
qemuDomainGetStatsVm(virQEMUDriver *driver G_GNUC_UNUSED,
virDomainObj *dom,
virTypedParamList *params,
unsigned int privflags)
{
qemuDomainObjPrivate *priv = dom->privateData;
g_autoptr(virJSONValue) queried_stats = NULL;
g_autoptr(GHashTable) stats = NULL;
virJSONValue *stats_obj = NULL;
if (!HAVE_JOB(privflags) || !virDomainObjIsActive(dom))
return 0;
if (qemuDomainRefreshStatsSchema(dom) < 0)
return 0;
qemuDomainObjEnterMonitor(dom);
queried_stats = qemuMonitorQueryStats(priv->mon,
QEMU_MONITOR_QUERY_STATS_TARGET_VM,
NULL, NULL);
qemuDomainObjExitMonitor(dom);
if (!queried_stats || virJSONValueArraySize(queried_stats) != 1)
return 0;
stats_obj = virJSONValueArrayGet(queried_stats, 0);
stats = qemuMonitorExtractQueryStats(stats_obj);
qemuDomainAddStatsFromHashTable(stats, priv->statsSchema, "vm", params);
return 0;
}
typedef int
(*qemuDomainGetStatsFunc)(virQEMUDriver *driver,
virDomainObj *dom,
@ -18733,6 +18768,11 @@ static virQEMUCapsFlags queryDirtyRateRequired[] = {
QEMU_CAPS_LAST
};
static virQEMUCapsFlags queryVmRequired[] = {
QEMU_CAPS_QUERY_STATS,
QEMU_CAPS_LAST
};
static struct qemuDomainGetStatsWorker qemuDomainGetStatsWorkers[] = {
{ qemuDomainGetStatsState, VIR_DOMAIN_STATS_STATE, false, NULL },
{ qemuDomainGetStatsCpu, VIR_DOMAIN_STATS_CPU_TOTAL, true, NULL },
@ -18744,6 +18784,7 @@ static struct qemuDomainGetStatsWorker qemuDomainGetStatsWorkers[] = {
{ qemuDomainGetStatsIOThread, VIR_DOMAIN_STATS_IOTHREAD, true, queryIOThreadRequired },
{ qemuDomainGetStatsMemory, VIR_DOMAIN_STATS_MEMORY, false, NULL },
{ qemuDomainGetStatsDirtyRate, VIR_DOMAIN_STATS_DIRTYRATE, true, queryDirtyRateRequired },
{ qemuDomainGetStatsVm, VIR_DOMAIN_STATS_VM, true, queryVmRequired },
{ NULL, 0, false, NULL }
};

View File

@ -2065,6 +2065,10 @@ static const vshCmdOptDef opts_domstats[] = {
.type = VSH_OT_BOOL,
.help = N_("report domain dirty rate information"),
},
{.name = "vm",
.type = VSH_OT_BOOL,
.help = N_("report fd-based VM statistics by KVM"),
},
{.name = "list-active",
.type = VSH_OT_BOOL,
.help = N_("list only active domains"),
@ -2186,6 +2190,9 @@ cmdDomstats(vshControl *ctl, const vshCmd *cmd)
if (vshCommandOptBool(cmd, "dirtyrate"))
stats |= VIR_DOMAIN_STATS_DIRTYRATE;
if (vshCommandOptBool(cmd, "vm"))
stats |= VIR_DOMAIN_STATS_VM;
if (vshCommandOptBool(cmd, "list-active"))
flags |= VIR_CONNECT_GET_ALL_DOMAINS_STATS_ACTIVE;