qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: "Dr. David Alan Gilbert" <dgilbert@redhat.com>
To: Paolo Bonzini <pbonzini@redhat.com>
Cc: qemu-devel@nongnu.org, armbru@redhat.com
Subject: Re: [PATCH v5 08/10] hmp: add filtering of statistics by provider
Date: Wed, 8 Jun 2022 13:06:29 +0100	[thread overview]
Message-ID: <YqCQxdIQTxPrbDka@work-vm> (raw)
In-Reply-To: <20220530150714.756954-9-pbonzini@redhat.com>

* Paolo Bonzini (pbonzini@redhat.com) wrote:
> Allow the user to request statistics for a single provider of interest.
> Extracted from a patch by Mark Kanda.
> 
> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>

Reviewed-by: Dr. David Alan Gilbert <dgilbert@redhat.com>

> ---
>  hmp-commands-info.hx |  7 ++++---
>  monitor/hmp-cmds.c   | 39 ++++++++++++++++++++++++++++++++-------
>  2 files changed, 36 insertions(+), 10 deletions(-)
> 
> diff --git a/hmp-commands-info.hx b/hmp-commands-info.hx
> index 28757768f7..a67040443b 100644
> --- a/hmp-commands-info.hx
> +++ b/hmp-commands-info.hx
> @@ -897,9 +897,10 @@ ERST
>  
>      {
>          .name       = "stats",
> -        .args_type  = "target:s",
> -        .params     = "target",
> -        .help       = "show statistics; target is either vm or vcpu",
> +        .args_type  = "target:s,provider:s?",
> +        .params     = "target [provider]",
> +        .help       = "show statistics for the given target (vm or vcpu); optionally filter by "
> +                      "provider",
>          .cmd        = hmp_info_stats,
>      },
>  
> diff --git a/monitor/hmp-cmds.c b/monitor/hmp-cmds.c
> index c501d1fa2b..a71887e54c 100644
> --- a/monitor/hmp-cmds.c
> +++ b/monitor/hmp-cmds.c
> @@ -2300,6 +2300,7 @@ static StatsSchemaValueList *find_schema_value_list(
>  }
>  
>  static void print_stats_results(Monitor *mon, StatsTarget target,
> +                                bool show_provider,
>                                  StatsResult *result,
>                                  StatsSchemaList *schema)
>  {
> @@ -2314,8 +2315,10 @@ static void print_stats_results(Monitor *mon, StatsTarget target,
>          return;
>      }
>  
> -    monitor_printf(mon, "provider: %s\n",
> -                   StatsProvider_str(result->provider));
> +    if (show_provider) {
> +        monitor_printf(mon, "provider: %s\n",
> +                       StatsProvider_str(result->provider));
> +    }
>  
>      for (stats_list = result->stats; stats_list;
>               stats_list = stats_list->next,
> @@ -2356,7 +2359,8 @@ 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)
> +static StatsFilter *stats_filter(StatsTarget target, int cpu_index,
> +                                 StatsProvider provider)
>  {
>      StatsFilter *filter = g_malloc0(sizeof(*filter));
>  
> @@ -2378,12 +2382,25 @@ static StatsFilter *stats_filter(StatsTarget target, int cpu_index)
>      default:
>          break;
>      }
> +
> +    if (provider == STATS_PROVIDER__MAX) {
> +        return filter;
> +    }
> +
> +    /* "info stats" can only query either one or all the providers.  */
> +    filter->has_providers = true;
> +    filter->providers = g_new0(StatsRequestList, 1);
> +    filter->providers->value = g_new0(StatsRequest, 1);
> +    filter->providers->value->provider = provider;
>      return filter;
>  }
>  
>  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");
> +
> +    StatsProvider provider = STATS_PROVIDER__MAX;
>      StatsTarget target;
>      Error *err = NULL;
>      g_autoptr(StatsSchemaList) schema = NULL;
> @@ -2396,19 +2413,27 @@ void hmp_info_stats(Monitor *mon, const QDict *qdict)
>          monitor_printf(mon, "invalid stats target %s\n", target_str);
>          goto exit_no_print;
>      }
> +    if (provider_str) {
> +        provider = qapi_enum_parse(&StatsProvider_lookup, provider_str, -1, &err);
> +        if (err) {
> +            monitor_printf(mon, "invalid stats provider %s\n", provider_str);
> +            goto exit_no_print;
> +        }
> +    }
>  
> -    schema = qmp_query_stats_schemas(false, STATS_PROVIDER__MAX, &err);
> +    schema = qmp_query_stats_schemas(provider_str ? true : false,
> +                                     provider, &err);
>      if (err) {
>          goto exit;
>      }
>  
>      switch (target) {
>      case STATS_TARGET_VM:
> -        filter = stats_filter(target, -1);
> +        filter = stats_filter(target, -1, provider);
>          break;
>      case STATS_TARGET_VCPU: {}
>          int cpu_index = monitor_get_cpu_index(mon);
> -        filter = stats_filter(target, cpu_index);
> +        filter = stats_filter(target, cpu_index, provider);
>          break;
>      default:
>          abort();
> @@ -2419,7 +2444,7 @@ void hmp_info_stats(Monitor *mon, const QDict *qdict)
>          goto exit;
>      }
>      for (entry = stats; entry; entry = entry->next) {
> -        print_stats_results(mon, target, entry->value, schema);
> +        print_stats_results(mon, target, provider_str == NULL, entry->value, schema);
>      }
>  
>  exit:
> -- 
> 2.36.1
> 
> 
-- 
Dr. David Alan Gilbert / dgilbert@redhat.com / Manchester, UK



  reply	other threads:[~2022-06-08 12:12 UTC|newest]

Thread overview: 28+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-05-30 15:07 [PATCH v5 00/10] qmp, hmp: statistics subsystem and KVM suport Paolo Bonzini
2022-05-30 15:07 ` [PATCH v5 01/10] qmp: Support for querying stats Paolo Bonzini
2022-05-30 15:07 ` [PATCH v5 02/10] kvm: Support for querying fd-based stats Paolo Bonzini
2022-06-07 17:44   ` Dr. David Alan Gilbert
2022-06-08 14:13     ` Paolo Bonzini
2022-06-08 14:52       ` Dr. David Alan Gilbert
2022-06-08 15:58         ` Paolo Bonzini
2022-06-08 16:01           ` Dr. David Alan Gilbert
2022-06-08 16:10             ` Paolo Bonzini
2022-06-08 16:17               ` Dr. David Alan Gilbert
2022-05-30 15:07 ` [PATCH v5 03/10] qmp: add filtering of statistics by target vCPU Paolo Bonzini
2022-05-30 15:07 ` [PATCH v5 04/10] cutils: fix case for "kilo" and "kibi" Paolo Bonzini
2022-05-30 21:56   ` Philippe Mathieu-Daudé via
2022-05-30 15:07 ` [PATCH v5 05/10] cutils: add functions for IEC and SI prefixes Paolo Bonzini
2022-05-30 21:59   ` Philippe Mathieu-Daudé via
2022-05-31 10:28     ` Paolo Bonzini
2022-05-30 15:07 ` [PATCH v5 06/10] hmp: add basic "info stats" implementation Paolo Bonzini
2022-06-07 18:35   ` Dr. David Alan Gilbert
2022-06-08 14:27     ` Paolo Bonzini
2022-06-08 15:23       ` Dr. David Alan Gilbert
2022-05-30 15:07 ` [PATCH v5 07/10] qmp: add filtering of statistics by provider Paolo Bonzini
2022-06-08 11:52   ` Dr. David Alan Gilbert
2022-05-30 15:07 ` [PATCH v5 08/10] hmp: " Paolo Bonzini
2022-06-08 12:06   ` Dr. David Alan Gilbert [this message]
2022-05-30 15:07 ` [PATCH v5 09/10] qmp: add filtering of statistics by name Paolo Bonzini
2022-06-08 13:36   ` Dr. David Alan Gilbert
2022-05-30 15:07 ` [PATCH v5 10/10] hmp: " Paolo Bonzini
2022-06-08 13:40   ` Dr. David Alan Gilbert

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=YqCQxdIQTxPrbDka@work-vm \
    --to=dgilbert@redhat.com \
    --cc=armbru@redhat.com \
    --cc=pbonzini@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).