diff mbox series

[v5,5/7] docs/qapi-code-gen: update to cover trace events code generation

Message ID 20220125215655.3111881-6-vsementsov@virtuozzo.com (mailing list archive)
State New, archived
Headers show
Series trace qmp commands | expand

Commit Message

Vladimir Sementsov-Ogievskiy Jan. 25, 2022, 9:56 p.m. UTC
Previous commits enabled trace events generation for most of QAPI
generated code (except for tests/ and qga/). Let's update documentation
to illustrate it.

Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
---
 docs/devel/qapi-code-gen.rst | 21 ++++++++++++++++++++-
 1 file changed, 20 insertions(+), 1 deletion(-)

Comments

Markus Armbruster Jan. 26, 2022, 2:24 p.m. UTC | #1
Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com> writes:

> Previous commits enabled trace events generation for most of QAPI
> generated code (except for tests/ and qga/). Let's update documentation
> to illustrate it.
>
> Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
> ---
>  docs/devel/qapi-code-gen.rst | 21 ++++++++++++++++++++-
>  1 file changed, 20 insertions(+), 1 deletion(-)
>
> diff --git a/docs/devel/qapi-code-gen.rst b/docs/devel/qapi-code-gen.rst
> index feafed79b5..a3430740bd 100644
> --- a/docs/devel/qapi-code-gen.rst
> +++ b/docs/devel/qapi-code-gen.rst
> @@ -1619,7 +1619,10 @@ Code generated for commands
>  
>  These are the marshaling/dispatch functions for the commands defined
>  in the schema.  The generated code provides qmp_marshal_COMMAND(), and
> -declares qmp_COMMAND() that the user must implement.
> +declares qmp_COMMAND() that the user must implement.  The generated code
> +contains trace events code.  Corresponding .trace-events file with list
> +of trace events is generated too, and should be parsed by trace generator
> +later to generate trace event code, see `tracing <tracing.html>`.

I think references look like :ref:`tracing`.

The last sentence is kind of redundant with the text added in the next
hunk.  Drop both new sentences?

>  
>  The following files are generated:
>  
> @@ -1630,6 +1633,9 @@ The following files are generated:
>   ``$(prefix)qapi-commands.h``
>       Function prototypes for the QMP commands specified in the schema
>  
> + ``$(prefix)qapi-commands.trace-events``
> +     Trace events file for trace generator, see `tracing <tracing.html>`.

Suggest

        Trace event declarations, see :ref:`tracing`.

> +
>   ``$(prefix)qapi-init-commands.h``
>       Command initialization prototype
>  
> @@ -1689,14 +1695,27 @@ Example::
>              goto out;
>          }
>  
> +        if (trace_event_get_state_backends(TRACE_QMP_ENTER_MY_COMMAND)) {
> +            g_autoptr(GString) req_json = qobject_to_json(QOBJECT(args));
> +
> +            trace_qmp_enter_my_command(req_json->str);
> +        }
> +
>          retval = qmp_my_command(arg.arg1, &err);
>          if (err) {
> +            trace_qmp_exit_my_command(error_get_pretty(err), false);
>              error_propagate(errp, err);
>              goto out;
>          }
>  
>          qmp_marshal_output_UserDefOne(retval, ret, errp);
>  
> +        if (trace_event_get_state_backends(TRACE_QMP_EXIT_MY_COMMAND)) {
> +            g_autoptr(GString) ret_json = qobject_to_json(*ret);
> +
> +            trace_qmp_exit_my_command(ret_json->str, true);
> +        }
> +
>      out:
>          visit_free(v);
>          v = qapi_dealloc_visitor_new();

Let's add

       $ cat qapi-generated/example-qapi-commands.trace-events
       # AUTOMATICALLY GENERATED, DO NOT MODIFY

       qmp_enter_my_command(const char *json) "%s"
       qmp_exit_my_command(const char *result, bool succeeded) "%s %d"

between .h and .c.
diff mbox series

Patch

diff --git a/docs/devel/qapi-code-gen.rst b/docs/devel/qapi-code-gen.rst
index feafed79b5..a3430740bd 100644
--- a/docs/devel/qapi-code-gen.rst
+++ b/docs/devel/qapi-code-gen.rst
@@ -1619,7 +1619,10 @@  Code generated for commands
 
 These are the marshaling/dispatch functions for the commands defined
 in the schema.  The generated code provides qmp_marshal_COMMAND(), and
-declares qmp_COMMAND() that the user must implement.
+declares qmp_COMMAND() that the user must implement.  The generated code
+contains trace events code.  Corresponding .trace-events file with list
+of trace events is generated too, and should be parsed by trace generator
+later to generate trace event code, see `tracing <tracing.html>`.
 
 The following files are generated:
 
@@ -1630,6 +1633,9 @@  The following files are generated:
  ``$(prefix)qapi-commands.h``
      Function prototypes for the QMP commands specified in the schema
 
+ ``$(prefix)qapi-commands.trace-events``
+     Trace events file for trace generator, see `tracing <tracing.html>`.
+
  ``$(prefix)qapi-init-commands.h``
      Command initialization prototype
 
@@ -1689,14 +1695,27 @@  Example::
             goto out;
         }
 
+        if (trace_event_get_state_backends(TRACE_QMP_ENTER_MY_COMMAND)) {
+            g_autoptr(GString) req_json = qobject_to_json(QOBJECT(args));
+
+            trace_qmp_enter_my_command(req_json->str);
+        }
+
         retval = qmp_my_command(arg.arg1, &err);
         if (err) {
+            trace_qmp_exit_my_command(error_get_pretty(err), false);
             error_propagate(errp, err);
             goto out;
         }
 
         qmp_marshal_output_UserDefOne(retval, ret, errp);
 
+        if (trace_event_get_state_backends(TRACE_QMP_EXIT_MY_COMMAND)) {
+            g_autoptr(GString) ret_json = qobject_to_json(*ret);
+
+            trace_qmp_exit_my_command(ret_json->str, true);
+        }
+
     out:
         visit_free(v);
         v = qapi_dealloc_visitor_new();