All of lore.kernel.org
 help / color / mirror / Atom feed
From: Paolo Bonzini <pbonzini@redhat.com>
To: qemu-devel@nongnu.org
Cc: berrange@redhat.com, armbru@redhat.com, dgilbert@redhat.com
Subject: [PATCH 8/8] hmp: add filtering of statistics by name
Date: Tue, 26 Apr 2022 16:16:19 +0200	[thread overview]
Message-ID: <20220426141619.304611-9-pbonzini@redhat.com> (raw)
In-Reply-To: <20220426141619.304611-1-pbonzini@redhat.com>

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.

Extracted from a patch by Mark Kanda.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
 hmp-commands-info.hx |  8 ++++----
 monitor/hmp-cmds.c   | 35 +++++++++++++++++++++++++----------
 2 files changed, 29 insertions(+), 14 deletions(-)

diff --git a/hmp-commands-info.hx b/hmp-commands-info.hx
index 1a3e16175f..d533036bc9 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 2bce9d7016..4150d76fd9 100644
--- a/monitor/hmp-cmds.c
+++ b/monitor/hmp-cmds.c
@@ -2340,10 +2340,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) {
@@ -2364,15 +2366,27 @@ 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.  */
-    StatsRequest *request = g_new0(StatsRequest, 1);
-    request->provider = provider;
-    StatsRequestList *request_list = g_new0(StatsRequestList, 1);
-    QAPI_LIST_PREPEND(request_list, request);
+    /*
+     * "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 = request_list;
     return filter;
@@ -2382,6 +2396,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;
@@ -2412,11 +2427,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.35.1



  parent reply	other threads:[~2022-04-26 14:23 UTC|newest]

Thread overview: 34+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-04-26 14:16 [PATCH 0/8] qmp, hmp: statistics subsystem and KVM suport Paolo Bonzini
2022-04-26 14:16 ` [PATCH 1/8] qmp: Support for querying stats Paolo Bonzini
2022-04-27  9:19   ` Dr. David Alan Gilbert
2022-04-27 12:10     ` Paolo Bonzini
2022-05-04 13:22   ` Markus Armbruster
2022-05-05  7:10     ` Paolo Bonzini
2022-05-05  8:00       ` Daniel P. Berrangé
2022-05-05 13:28       ` Markus Armbruster
2022-05-05 13:39         ` Daniel P. Berrangé
2022-05-05 17:21           ` Dr. David Alan Gilbert
2022-05-05 13:58         ` Paolo Bonzini
2022-05-13 13:10           ` Markus Armbruster
2022-05-13 13:57             ` Paolo Bonzini
2022-05-13 14:35               ` Markus Armbruster
2022-05-13 15:50                 ` Paolo Bonzini
2022-05-13 17:47                   ` Markus Armbruster
2022-04-26 14:16 ` [PATCH 2/8] kvm: Support for querying fd-based stats Paolo Bonzini
2022-04-26 14:16 ` [PATCH 3/8] qmp: add filtering of statistics by target vCPU Paolo Bonzini
2022-05-05 13:45   ` Markus Armbruster
2022-05-05 13:59     ` Paolo Bonzini
2022-04-26 14:16 ` [PATCH 4/8] hmp: add basic "info stats" implementation Paolo Bonzini
2022-04-26 14:16 ` [PATCH 5/8] qmp: add filtering of statistics by provider Paolo Bonzini
2022-04-26 14:16 ` [PATCH 6/8] hmp: " Paolo Bonzini
2022-04-26 14:16 ` [PATCH 7/8] qmp: add filtering of statistics by name Paolo Bonzini
2022-04-27 12:01   ` Dr. David Alan Gilbert
2022-04-27 12:18     ` Paolo Bonzini
2022-04-27 12:34       ` Dr. David Alan Gilbert
2022-04-27 14:17         ` Paolo Bonzini
2022-04-27 15:16           ` Dr. David Alan Gilbert
2022-04-27 15:50             ` Paolo Bonzini
2022-04-27 17:16               ` Dr. David Alan Gilbert
2022-04-28  9:53                 ` Paolo Bonzini
2022-04-26 14:16 ` Paolo Bonzini [this message]
2022-05-23 15:05 [PATCH v4 0/8] qmp, hmp: statistics subsystem and KVM suport Paolo Bonzini
2022-05-23 15:07 ` [PATCH 1/8] qmp: Support for querying stats Paolo Bonzini
2022-05-23 15:07   ` [PATCH 8/8] hmp: add filtering of statistics by name Paolo Bonzini

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220426141619.304611-9-pbonzini@redhat.com \
    --to=pbonzini@redhat.com \
    --cc=armbru@redhat.com \
    --cc=berrange@redhat.com \
    --cc=dgilbert@redhat.com \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.