diff mbox series

[RFC,17/21] hmp: expose status of plugins to the monitor

Message ID 20181005154910.3099-18-alex.bennee@linaro.org
State New
Headers show
Series Trace updates and plugin RFC | expand

Commit Message

Alex Bennée Oct. 5, 2018, 3:49 p.m. UTC
Signed-off-by: Alex Bennée <alex.bennee@linaro.org>
---
 hmp-commands-info.hx   | 17 +++++++++++++++++
 include/qemu/plugins.h |  1 +
 monitor.c              | 14 ++++++++++++++
 trace/plugins.c        | 15 +++++++++++++++
 4 files changed, 47 insertions(+)

Comments

Richard Henderson Oct. 15, 2018, 5:27 p.m. UTC | #1
On 10/5/18 8:49 AM, Alex Bennée wrote:
> Signed-off-by: Alex Bennée <alex.bennee@linaro.org>
> ---
>  hmp-commands-info.hx   | 17 +++++++++++++++++
>  include/qemu/plugins.h |  1 +
>  monitor.c              | 14 ++++++++++++++
>  trace/plugins.c        | 15 +++++++++++++++
>  4 files changed, 47 insertions(+)

Reviewed-by: Richard Henderson <richard.henderson@linaro.org>

r~
Dr. David Alan Gilbert Oct. 17, 2018, 12:04 p.m. UTC | #2
* Alex Bennée (alex.bennee@linaro.org) wrote:
> Signed-off-by: Alex Bennée <alex.bennee@linaro.org>
> ---
>  hmp-commands-info.hx   | 17 +++++++++++++++++
>  include/qemu/plugins.h |  1 +
>  monitor.c              | 14 ++++++++++++++
>  trace/plugins.c        | 15 +++++++++++++++
>  4 files changed, 47 insertions(+)

I'm OK with this; although it's worth thinking about whether this should
be available via qmp, but it is just for debug/tracing.


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


> diff --git a/hmp-commands-info.hx b/hmp-commands-info.hx
> index cbee8b944d..e245a852ae 100644
> --- a/hmp-commands-info.hx
> +++ b/hmp-commands-info.hx
> @@ -683,6 +683,23 @@ STEXI
>  Show available trace-events & their state.
>  ETEXI

> +#if defined(CONFIG_TRACE_PLUGIN)
> +    {
> +        .name       = "trace-plugins",
> +        .args_type  = "name:s?",
> +        .params     = "[name]",
> +        .help       = "show available plugins and any extra info "
> +                      "(name: plugin name pattern)",
> +        .cmd = hmp_info_trace_plugins,
> +    },
> +
> +STEXI
> +@item info trace-plugins
> +@findex info trace-plugins
> +Show available trace-plugins & their state.
> +ETEXI
> +#endif
> +
>      {
>          .name       = "tpm",
>          .args_type  = "",
> diff --git a/include/qemu/plugins.h b/include/qemu/plugins.h
> index c86bb7ae67..44f2ec8c98 100644
> --- a/include/qemu/plugins.h
> +++ b/include/qemu/plugins.h
> @@ -6,6 +6,7 @@
>  void qemu_plugin_parse_cmd_args(const char *optarg);
>  void qemu_plugin_load(const char *filename, const char *args);
>  void qemu_plugins_init(void);
> +GString *qemu_plugin_status(const char *name);
>  
>  #else
>  
> diff --git a/monitor.c b/monitor.c
> index d8229cd2b0..0d0de9ece7 100644
> --- a/monitor.c
> +++ b/monitor.c
> @@ -67,6 +67,9 @@
>  #ifdef CONFIG_TRACE_SIMPLE
>  #include "trace/simple.h"
>  #endif
> +#ifdef CONFIG_TRACE_PLUGIN
> +#include "qemu/plugins.h"
> +#endif
>  #include "exec/memory.h"
>  #include "exec/exec-all.h"
>  #include "qemu/log.h"
> @@ -1429,6 +1432,17 @@ static void hmp_info_trace_events(Monitor *mon, const QDict *qdict)
>      qapi_free_TraceEventInfoList(events);
>  }
>  
> +#ifdef CONFIG_TRACE_PLUGIN
> +static void hmp_info_trace_plugins(Monitor *mon, const QDict *qdict)
> +{
> +    const char *name = qdict_get_try_str(qdict, "name");
> +    GString *status = qemu_plugin_status(name);
> +
> +    monitor_printf(mon, "%s", status->str);
> +    g_string_free(status, true);
> +}
> +#endif
> +
>  void qmp_client_migrate_info(const char *protocol, const char *hostname,
>                               bool has_port, int64_t port,
>                               bool has_tls_port, int64_t tls_port,
> diff --git a/trace/plugins.c b/trace/plugins.c
> index 25aec2ff70..05630b02e6 100644
> --- a/trace/plugins.c
> +++ b/trace/plugins.c
> @@ -58,6 +58,21 @@ void qemu_plugin_parse_cmd_args(const char *optarg)
>                       qemu_opt_get(opts, "args"));
>  }
>  
> +GString *qemu_plugin_status(const char *name)
> +{
> +    QemuPluginInfo *info;
> +    GString *status = g_string_new("");
> +
> +    QLIST_FOREACH(info, &qemu_plugins, next) {
> +        if (info->status) {
> +            char *pstatus = info->status();
> +            g_string_append_printf(status, "%s: %s\n", info->filename, pstatus);
> +            g_free(pstatus);
> +        }
> +    }
> +    return status;
> +}
> +
>  static int bind_to_tracepoints(GModule *g_module, GPtrArray *events)
>  {
>      int count = 0;
> -- 
> 2.17.1
> 
--
Dr. David Alan Gilbert / dgilbert@redhat.com / Manchester, UK
Markus Armbruster Oct. 17, 2018, 5:36 p.m. UTC | #3
"Dr. David Alan Gilbert" <dgilbert@redhat.com> writes:

> * Alex Bennée (alex.bennee@linaro.org) wrote:
>> Signed-off-by: Alex Bennée <alex.bennee@linaro.org>
>> ---
>>  hmp-commands-info.hx   | 17 +++++++++++++++++
>>  include/qemu/plugins.h |  1 +
>>  monitor.c              | 14 ++++++++++++++
>>  trace/plugins.c        | 15 +++++++++++++++
>>  4 files changed, 47 insertions(+)
>
> I'm OK with this; although it's worth thinking about whether this should
> be available via qmp, but it is just for debug/tracing.

Standard operating procedure for adding HMP commands without a QMP
equivalent: have the commit message explain why the QMP equivalent isn't
useful.

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

Patch

diff --git a/hmp-commands-info.hx b/hmp-commands-info.hx
index cbee8b944d..e245a852ae 100644
--- a/hmp-commands-info.hx
+++ b/hmp-commands-info.hx
@@ -683,6 +683,23 @@  STEXI
 Show available trace-events & their state.
 ETEXI
 
+#if defined(CONFIG_TRACE_PLUGIN)
+    {
+        .name       = "trace-plugins",
+        .args_type  = "name:s?",
+        .params     = "[name]",
+        .help       = "show available plugins and any extra info "
+                      "(name: plugin name pattern)",
+        .cmd = hmp_info_trace_plugins,
+    },
+
+STEXI
+@item info trace-plugins
+@findex info trace-plugins
+Show available trace-plugins & their state.
+ETEXI
+#endif
+
     {
         .name       = "tpm",
         .args_type  = "",
diff --git a/include/qemu/plugins.h b/include/qemu/plugins.h
index c86bb7ae67..44f2ec8c98 100644
--- a/include/qemu/plugins.h
+++ b/include/qemu/plugins.h
@@ -6,6 +6,7 @@ 
 void qemu_plugin_parse_cmd_args(const char *optarg);
 void qemu_plugin_load(const char *filename, const char *args);
 void qemu_plugins_init(void);
+GString *qemu_plugin_status(const char *name);
 
 #else
 
diff --git a/monitor.c b/monitor.c
index d8229cd2b0..0d0de9ece7 100644
--- a/monitor.c
+++ b/monitor.c
@@ -67,6 +67,9 @@ 
 #ifdef CONFIG_TRACE_SIMPLE
 #include "trace/simple.h"
 #endif
+#ifdef CONFIG_TRACE_PLUGIN
+#include "qemu/plugins.h"
+#endif
 #include "exec/memory.h"
 #include "exec/exec-all.h"
 #include "qemu/log.h"
@@ -1429,6 +1432,17 @@  static void hmp_info_trace_events(Monitor *mon, const QDict *qdict)
     qapi_free_TraceEventInfoList(events);
 }
 
+#ifdef CONFIG_TRACE_PLUGIN
+static void hmp_info_trace_plugins(Monitor *mon, const QDict *qdict)
+{
+    const char *name = qdict_get_try_str(qdict, "name");
+    GString *status = qemu_plugin_status(name);
+
+    monitor_printf(mon, "%s", status->str);
+    g_string_free(status, true);
+}
+#endif
+
 void qmp_client_migrate_info(const char *protocol, const char *hostname,
                              bool has_port, int64_t port,
                              bool has_tls_port, int64_t tls_port,
diff --git a/trace/plugins.c b/trace/plugins.c
index 25aec2ff70..05630b02e6 100644
--- a/trace/plugins.c
+++ b/trace/plugins.c
@@ -58,6 +58,21 @@  void qemu_plugin_parse_cmd_args(const char *optarg)
                      qemu_opt_get(opts, "args"));
 }
 
+GString *qemu_plugin_status(const char *name)
+{
+    QemuPluginInfo *info;
+    GString *status = g_string_new("");
+
+    QLIST_FOREACH(info, &qemu_plugins, next) {
+        if (info->status) {
+            char *pstatus = info->status();
+            g_string_append_printf(status, "%s: %s\n", info->filename, pstatus);
+            g_free(pstatus);
+        }
+    }
+    return status;
+}
+
 static int bind_to_tracepoints(GModule *g_module, GPtrArray *events)
 {
     int count = 0;