diff options
author | Paolo Bonzini <pbonzini@redhat.com> | 2022-04-26 11:49:33 +0200 |
---|---|---|
committer | Paolo Bonzini <pbonzini@redhat.com> | 2022-06-14 16:50:30 +0200 |
commit | 068cc51d42f771d2a453d628c10e199e7d104edd (patch) | |
tree | e89f2af7614e6975703837af8c2f3bc7137ec80c /monitor | |
parent | 433815f5bdf71b5b2c47d9f1104816b95b551c49 (diff) |
qmp: add filtering of statistics by provider
Allow retrieving the statistics from a specific provider only.
This can be used in the future by HMP commands such as "info
sync-profile" or "info profile". The next patch also adds
filter-by-provider capabilities to the HMP equivalent of
query-stats, "info stats".
Example:
{ "execute": "query-stats",
"arguments": {
"target": "vm",
"providers": [
{ "provider": "kvm" } ] } }
The QAPI is a bit more verbose than just a list of StatsProvider,
so that it can be subsequently extended with filtering of statistics
by name.
If a provider is specified more than once in the filter, each request
will be included separately in the output.
Extracted from a patch by Mark Kanda.
Reviewed-by: Markus Armbruster <armbru@redhat.com>
Reviewed-by: Dr. David Alan Gilbert <dgilbert@redhat.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Diffstat (limited to 'monitor')
-rw-r--r-- | monitor/hmp-cmds.c | 2 | ||||
-rw-r--r-- | monitor/qmp-cmds.c | 41 |
2 files changed, 33 insertions, 10 deletions
diff --git a/monitor/hmp-cmds.c b/monitor/hmp-cmds.c index 04d5ee8fb7..9180cf1841 100644 --- a/monitor/hmp-cmds.c +++ b/monitor/hmp-cmds.c @@ -2397,7 +2397,7 @@ void hmp_info_stats(Monitor *mon, const QDict *qdict) goto exit_no_print; } - schema = qmp_query_stats_schemas(&err); + schema = qmp_query_stats_schemas(false, STATS_PROVIDER__MAX, &err); if (err) { goto exit; } diff --git a/monitor/qmp-cmds.c b/monitor/qmp-cmds.c index 5f8f1e620b..e49ab345d7 100644 --- a/monitor/qmp-cmds.c +++ b/monitor/qmp-cmds.c @@ -445,6 +445,7 @@ HumanReadableText *qmp_x_query_irq(Error **errp) } typedef struct StatsCallbacks { + StatsProvider provider; StatRetrieveFunc *stats_cb; SchemaRetrieveFunc *schemas_cb; QTAILQ_ENTRY(StatsCallbacks) next; @@ -453,10 +454,12 @@ typedef struct StatsCallbacks { static QTAILQ_HEAD(, StatsCallbacks) stats_callbacks = QTAILQ_HEAD_INITIALIZER(stats_callbacks); -void add_stats_callbacks(StatRetrieveFunc *stats_fn, +void add_stats_callbacks(StatsProvider provider, + StatRetrieveFunc *stats_fn, SchemaRetrieveFunc *schemas_fn) { StatsCallbacks *entry = g_new(StatsCallbacks, 1); + entry->provider = provider; entry->stats_cb = stats_fn; entry->schemas_cb = schemas_fn; @@ -465,12 +468,18 @@ void add_stats_callbacks(StatRetrieveFunc *stats_fn, static bool invoke_stats_cb(StatsCallbacks *entry, StatsResultList **stats_results, - StatsFilter *filter, + StatsFilter *filter, StatsRequest *request, Error **errp) { strList *targets = NULL; ERRP_GUARD(); + if (request) { + if (request->provider != entry->provider) { + return true; + } + } + switch (filter->target) { case STATS_TARGET_VM: break; @@ -500,27 +509,41 @@ StatsResultList *qmp_query_stats(StatsFilter *filter, Error **errp) { StatsResultList *stats_results = NULL; StatsCallbacks *entry; + StatsRequestList *request; QTAILQ_FOREACH(entry, &stats_callbacks, next) { - if (!invoke_stats_cb(entry, &stats_results, filter, errp)) { - break; + if (filter->has_providers) { + for (request = filter->providers; request; request = request->next) { + if (!invoke_stats_cb(entry, &stats_results, filter, + request->value, errp)) { + break; + } + } + } else { + if (!invoke_stats_cb(entry, &stats_results, filter, NULL, errp)) { + break; + } } } return stats_results; } -StatsSchemaList *qmp_query_stats_schemas(Error **errp) +StatsSchemaList *qmp_query_stats_schemas(bool has_provider, + StatsProvider provider, + Error **errp) { StatsSchemaList *stats_results = NULL; StatsCallbacks *entry; ERRP_GUARD(); QTAILQ_FOREACH(entry, &stats_callbacks, next) { - entry->schemas_cb(&stats_results, errp); - if (*errp) { - qapi_free_StatsSchemaList(stats_results); - return NULL; + if (!has_provider || provider == entry->provider) { + entry->schemas_cb(&stats_results, errp); + if (*errp) { + qapi_free_StatsSchemaList(stats_results); + return NULL; + } } } |