+ } else {
+ virReportError(VIR_ERR_ARGUMENT_UNSUPPORTED, "%s",
+ _("Unsupported resctrl monitor type"));
+ return -1;
+ }
+
+ if (virStringListLength((const char * const *)features) == 0)
+ return 0;
+
for (i = 0; i < dom->def->nresctrls; i++) {
resctrl = dom->def->resctrls[i];
@@ -20041,9 +20055,8 @@ qemuDomainGetResctrlMonData(virDomainObjPtr
dom,
if (VIR_STRDUP(res->name,
virResctrlMonitorGetID(monitor)) < 0)
goto error;
- if (virResctrlMonitorGetCacheOccupancy(monitor,
- &res->stats,
- &res->nstats) < 0)
+ if (virResctrlMonitorGetStats(monitor, (const char
**)features,
+ &res->stats, &res->nstats)
< 0)
goto error;
if (VIR_APPEND_ELEMENT(*resdata, *nresdata, res) < 0)
@@ -20060,7 +20073,8 @@ qemuDomainGetResctrlMonData(virDomainObjPtr dom,
static int
-qemuDomainGetStatsCpuCache(virDomainObjPtr dom,
+qemuDomainGetStatsCpuCache(virQEMUDriverPtr driver,
+ virDomainObjPtr dom,
virDomainStatsRecordPtr record,
int *maxparams)
{
@@ -20074,10 +20088,13 @@ qemuDomainGetStatsCpuCache(virDomainObjPtr
dom,
if (!virDomainObjIsActive(dom))
return 0;
- if (qemuDomainGetResctrlMonData(dom, &resdata, &nresdata,
+ if (qemuDomainGetResctrlMonData(driver, dom, &resdata, &nresdata,
VIR_RESCTRL_MONITOR_TYPE_CACHE) < 0)
goto cleanup;
+ if (nresdata == 0)
+ return 0;
+
snprintf(param_name, VIR_TYPED_PARAM_FIELD_LENGTH,
"cpu.cache.monitor.count");
if (virTypedParamsAddUInt(&record->params, &record->nparams,
@@ -20175,7 +20192,7 @@ qemuDomainGetStatsCpuCgroup(virDomainObjPtr dom,
static int
-qemuDomainGetStatsCpu(virQEMUDriverPtr driver ATTRIBUTE_UNUSED,
+qemuDomainGetStatsCpu(virQEMUDriverPtr driver,
virDomainObjPtr dom,
virDomainStatsRecordPtr record,
int *maxparams,
@@ -20184,7 +20201,7 @@ qemuDomainGetStatsCpu(virQEMUDriverPtr driver
ATTRIBUTE_UNUSED,
if (qemuDomainGetStatsCpuCgroup(dom, record, maxparams) < 0)
return -1;
- if (qemuDomainGetStatsCpuCache(dom, record, maxparams) < 0)
+ if (qemuDomainGetStatsCpuCache(driver, dom, record, maxparams) < 0)
return -1;
return 0;
diff --git a/src/util/virresctrl.c b/src/util/virresctrl.c
index c2fe2ed..76a8d02 100644
--- a/src/util/virresctrl.c
+++ b/src/util/virresctrl.c
@@ -2668,8 +2668,7 @@ virResctrlMonitorStatsSorter(const void *a,
* virResctrlMonitorGetStats
*
* @monitor: The monitor that the statistic data will be retrieved
from.
- * @resource: The name for resource name. 'llc_occupancy' for cache
resource.
- * "mbm_total_bytes" and "mbm_local_bytes" for memory bandwidth
resource.
+ * @resources: A string list for the monitor feature names.
* @stats: Pointer of of virResctrlMonitorStatsPtr array for
holding cache or
* memory bandwidth usage data.
* @nstats: A size_t pointer to hold the returned array length of
@stats
@@ -2678,14 +2677,15 @@ virResctrlMonitorStatsSorter(const void *a,
*
* Returns 0 on success, -1 on error.
*/
-static int
+int
virResctrlMonitorGetStats(virResctrlMonitorPtr monitor,
- const char *resource,
+ const char **resources,
virResctrlMonitorStatsPtr **stats,
size_t *nstats)
{
int rv = -1;
int ret = -1;
+ size_t i = 0;
unsigned int val = 0;
DIR *dirp = NULL;
char *datapath = NULL;
@@ -2743,21 +2743,23 @@
virResctrlMonitorGetStats(virResctrlMonitorPtr monitor,
if (virStrToLong_uip(node_id, NULL, 0, &stat->id) < 0)
goto cleanup;
- rv = virFileReadValueUint(&val, "%s/%s/%s", datapath,
- ent->d_name, resource);
- if (rv == -2) {
- virReportError(VIR_ERR_INTERNAL_ERROR,
- _("File '%s/%s/%s' does not exist."),
- datapath, ent->d_name, resource);
- }
- if (rv < 0)
- goto cleanup;
+ for (i = 0; resources[i]; i++) {
+ rv = virFileReadValueUint(&val, "%s/%s/%s", datapath,
+ ent->d_name, resources[i]);
+ if (rv == -2) {
+ virReportError(VIR_ERR_INTERNAL_ERROR,
+ _("File '%s/%s/%s' does not exist."),
+ datapath, ent->d_name, resources[i]);
+ }
+ if (rv < 0)
+ goto cleanup;
- if (VIR_APPEND_ELEMENT(stat->vals, stat->nvals, val) < 0)
- goto cleanup;
+ if (VIR_APPEND_ELEMENT(stat->vals, stat->nvals, val) < 0)
+ goto cleanup;
- if (virStringListAdd(&stat->features, resource) < 0)
- goto cleanup;
+ if (virStringListAdd(&stat->features, resources[i]) < 0)
+ goto cleanup;
+ }
if (VIR_APPEND_ELEMENT(*stats, *nstats, stat) < 0)
goto cleanup;
@@ -2813,6 +2815,12 @@
virResctrlMonitorGetCacheOccupancy(virResctrlMonitorPtr monitor,
virResctrlMonitorStatsPtr **stats,
size_t *nstats)
{
- return virResctrlMonitorGetStats(monitor, "llc_occupancy",
- stats, nstats);
+ char **features = NULL;
+ int ret = -1;
+
+ virStringListAdd(&features, "llc_occupancy");
+ ret = virResctrlMonitorGetStats(monitor, (const char**)features,
stats, nstats);
+ virStringListFree(features);