From cf7405bc0228c795557e19bacbaa3b145bb17370 Mon Sep 17 00:00:00 2001 From: Paolo Bonzini Date: Tue, 24 May 2022 19:13:16 +0200 Subject: qmp: add filtering of statistics by name Allow retrieving only a subset of statistics. This can be useful for example in order to plot a subset of the statistics many times a second: KVM publishes ~40 statistics for each vCPU on x86; retrieving and serializing all of them would be useless. Another use will be in HMP in the following patch; implementing the filter in the backend is easy enough that it was deemed okay to make this a public interface. Example: { "execute": "query-stats", "arguments": { "target": "vcpu", "vcpus": [ "/machine/unattached/device[2]", "/machine/unattached/device[4]" ], "providers": [ { "provider": "kvm", "names": [ "l1d_flush", "exits" ] } } } { "return": { "vcpus": [ { "path": "/machine/unattached/device[2]" "providers": [ { "provider": "kvm", "stats": [ { "name": "l1d_flush", "value": 41213 }, { "name": "exits", "value": 74291 } ] } ] }, { "path": "/machine/unattached/device[4]" "providers": [ { "provider": "kvm", "stats": [ { "name": "l1d_flush", "value": 16132 }, { "name": "exits", "value": 57922 } ] } ] } ] } } Extracted from a patch by Mark Kanda. Reviewed-by: Dr. David Alan Gilbert Signed-off-by: Paolo Bonzini --- monitor/qmp-cmds.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'monitor/qmp-cmds.c') diff --git a/monitor/qmp-cmds.c b/monitor/qmp-cmds.c index e49ab345d7..7314cd813d 100644 --- a/monitor/qmp-cmds.c +++ b/monitor/qmp-cmds.c @@ -472,12 +472,17 @@ static bool invoke_stats_cb(StatsCallbacks *entry, Error **errp) { strList *targets = NULL; + strList *names = NULL; ERRP_GUARD(); if (request) { if (request->provider != entry->provider) { return true; } + if (request->has_names && !request->names) { + return true; + } + names = request->has_names ? request->names : NULL; } switch (filter->target) { @@ -496,7 +501,7 @@ static bool invoke_stats_cb(StatsCallbacks *entry, abort(); } - entry->stats_cb(stats_results, filter->target, targets, errp); + entry->stats_cb(stats_results, filter->target, names, targets, errp); if (*errp) { qapi_free_StatsResultList(*stats_results); *stats_results = NULL; -- cgit v1.2.3-55-g7522