[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PULL 09/21] hmp: add filtering of statistics by name
From: |
Paolo Bonzini |
Subject: |
[PULL 09/21] hmp: add filtering of statistics by name |
Date: |
Thu, 16 Jun 2022 10:31:57 +0200 |
Allow the user to request only a specific subset of statistics.
This can be useful when working on a feature or optimization that is
known to affect that statistic.
Example:
(qemu) info stats vcpu halt_poll_fail_ns
provider: kvm
halt_poll_fail_ns (cumulative, ns): 0
In case multiple providers have the same statistic, the provider can be
specified too:
(qemu) info stats vcpu halt_poll_fail_ns kvm
provider: kvm
halt_poll_fail_ns (cumulative, ns): 0
Extracted from a patch by Mark Kanda.
Reviewed-by: Dr. David Alan Gilbert <dgilbert@redhat.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
hmp-commands-info.hx | 8 ++++----
monitor/hmp-cmds.c | 35 ++++++++++++++++++++++++++---------
2 files changed, 30 insertions(+), 13 deletions(-)
diff --git a/hmp-commands-info.hx b/hmp-commands-info.hx
index a67040443b..3ffa24bd67 100644
--- a/hmp-commands-info.hx
+++ b/hmp-commands-info.hx
@@ -897,10 +897,10 @@ ERST
{
.name = "stats",
- .args_type = "target:s,provider:s?",
- .params = "target [provider]",
- .help = "show statistics for the given target (vm or vcpu);
optionally filter by "
- "provider",
+ .args_type = "target:s,names:s?,provider:s?",
+ .params = "target [names] [provider]",
+ .help = "show statistics for the given target (vm or vcpu);
optionally filter by"
+ "name (comma-separated list, or * for all) and provider",
.cmd = hmp_info_stats,
},
diff --git a/monitor/hmp-cmds.c b/monitor/hmp-cmds.c
index 9278439533..47a27326ee 100644
--- a/monitor/hmp-cmds.c
+++ b/monitor/hmp-cmds.c
@@ -2359,10 +2359,12 @@ static void print_stats_results(Monitor *mon,
StatsTarget target,
}
/* Create the StatsFilter that is needed for an "info stats" invocation. */
-static StatsFilter *stats_filter(StatsTarget target, int cpu_index,
- StatsProvider provider)
+static StatsFilter *stats_filter(StatsTarget target, const char *names,
+ int cpu_index, StatsProvider provider)
{
StatsFilter *filter = g_malloc0(sizeof(*filter));
+ StatsProvider provider_idx;
+ StatsRequestList *request_list = NULL;
filter->target = target;
switch (target) {
@@ -2383,15 +2385,29 @@ static StatsFilter *stats_filter(StatsTarget target,
int cpu_index,
break;
}
- if (provider == STATS_PROVIDER__MAX) {
+ if (!names && provider == STATS_PROVIDER__MAX) {
return filter;
}
- /* "info stats" can only query either one or all the providers. */
+ /*
+ * "info stats" can only query either one or all the providers. Querying
+ * by name, but not by provider, requires the creation of one filter per
+ * provider.
+ */
+ for (provider_idx = 0; provider_idx < STATS_PROVIDER__MAX; provider_idx++)
{
+ if (provider == STATS_PROVIDER__MAX || provider == provider_idx) {
+ StatsRequest *request = g_new0(StatsRequest, 1);
+ request->provider = provider_idx;
+ if (names && !g_str_equal(names, "*")) {
+ request->has_names = true;
+ request->names = strList_from_comma_list(names);
+ }
+ QAPI_LIST_PREPEND(request_list, request);
+ }
+ }
+
filter->has_providers = true;
- filter->providers = g_new0(StatsRequestList, 1);
- filter->providers->value = g_new0(StatsRequest, 1);
- filter->providers->value->provider = provider;
+ filter->providers = request_list;
return filter;
}
@@ -2399,6 +2415,7 @@ void hmp_info_stats(Monitor *mon, const QDict *qdict)
{
const char *target_str = qdict_get_str(qdict, "target");
const char *provider_str = qdict_get_try_str(qdict, "provider");
+ const char *names = qdict_get_try_str(qdict, "names");
StatsProvider provider = STATS_PROVIDER__MAX;
StatsTarget target;
@@ -2429,11 +2446,11 @@ void hmp_info_stats(Monitor *mon, const QDict *qdict)
switch (target) {
case STATS_TARGET_VM:
- filter = stats_filter(target, -1, provider);
+ filter = stats_filter(target, names, -1, provider);
break;
case STATS_TARGET_VCPU: {}
int cpu_index = monitor_get_cpu_index(mon);
- filter = stats_filter(target, cpu_index, provider);
+ filter = stats_filter(target, names, cpu_index, provider);
break;
default:
abort();
--
2.36.1
- [PULL 00/21] Statistics, preconfig and cleanup patches for 2022-06-16, Paolo Bonzini, 2022/06/16
- [PULL 03/21] qmp: add filtering of statistics by target vCPU, Paolo Bonzini, 2022/06/16
- [PULL 02/21] kvm: Support for querying fd-based stats, Paolo Bonzini, 2022/06/16
- [PULL 05/21] hmp: add basic "info stats" implementation, Paolo Bonzini, 2022/06/16
- [PULL 08/21] qmp: add filtering of statistics by name, Paolo Bonzini, 2022/06/16
- [PULL 09/21] hmp: add filtering of statistics by name,
Paolo Bonzini <=
- [PULL 04/21] cutils: add functions for IEC and SI prefixes, Paolo Bonzini, 2022/06/16
- [PULL 06/21] qmp: add filtering of statistics by provider, Paolo Bonzini, 2022/06/16
- [PULL 01/21] qmp: Support for querying stats, Paolo Bonzini, 2022/06/16
- [PULL 07/21] hmp: add filtering of statistics by provider, Paolo Bonzini, 2022/06/16
- [PULL 10/21] block: add more commands to preconfig mode, Paolo Bonzini, 2022/06/16
- [PULL 11/21] s390x: simplify virtio_ccw_reset_virtio, Paolo Bonzini, 2022/06/16
- [PULL 12/21] virtio-mmio: stop ioeventfd on legacy reset, Paolo Bonzini, 2022/06/16
- [PULL 13/21] virtio: stop ioeventfd on reset, Paolo Bonzini, 2022/06/16
- [PULL 15/21] configure: update list of preserved environment variables, Paolo Bonzini, 2022/06/16
- [PULL 18/21] build: fix check for -fsanitize-coverage-allowlist, Paolo Bonzini, 2022/06/16