diff mbox

[5/5] trace: enable tracing in qemu-img

Message ID 1464892545-26544-6-git-send-email-den@openvz.org (mailing list archive)
State New, archived
Headers show

Commit Message

Denis V. Lunev June 2, 2016, 6:35 p.m. UTC
The command will work this way:
    qemu-img --trace qcow2* create -f qcow2 1.img 64G

Signed-off-by: Denis V. Lunev <den@openvz.org>
Suggested by: Daniel P. Berrange <berrange@redhat.com>
CC: Eric Blake <eblake@redhat.com>
CC: Paolo Bonzini <pbonzini@redhat.com>
CC: Stefan Hajnoczi <stefanha@redhat.com>
CC: Kevin Wolf <kwolf@redhat.com>
---
 qemu-img.c    | 24 +++++++++++++++++++++---
 qemu-img.texi | 34 +++++++++++++++++++++++++++++++++-
 2 files changed, 54 insertions(+), 4 deletions(-)

Comments

Eric Blake June 3, 2016, 2:55 p.m. UTC | #1
On 06/02/2016 12:35 PM, Denis V. Lunev wrote:
> The command will work this way:
>     qemu-img --trace qcow2* create -f qcow2 1.img 64G
> 
> Signed-off-by: Denis V. Lunev <den@openvz.org>
> Suggested by: Daniel P. Berrange <berrange@redhat.com>
> CC: Eric Blake <eblake@redhat.com>
> CC: Paolo Bonzini <pbonzini@redhat.com>
> CC: Stefan Hajnoczi <stefanha@redhat.com>
> CC: Kevin Wolf <kwolf@redhat.com>
> ---
>  qemu-img.c    | 24 +++++++++++++++++++++---
>  qemu-img.texi | 34 +++++++++++++++++++++++++++++++++-
>  2 files changed, 54 insertions(+), 4 deletions(-)
> 

> @@ -87,7 +89,7 @@ static void QEMU_NORETURN help(void)
>  {
>      const char *help_msg =
>             QEMU_IMG_VERSION
> -           "usage: qemu-img command [command options]\n"
> +           "usage: qemu-img [common options] command [command options]\n"
>             "QEMU disk image utility\n"

This hunk belongs in the previous patch

>             "\n"
>             "Command syntax:\n"
> @@ -156,10 +158,14 @@ static void QEMU_NORETURN help(void)
>             "  '-f' first image format\n"
>             "  '-F' second image format\n"
>             "  '-s' run in Strict mode - fail on different image size or sector allocation\n";
> +    const char *help_msg2 =
> +           "Common options:\n"
> +           "  '-T', --trace [[enable=]<pattern>][,events=<file>][,file=<file>]\n"
> +           "       specify tracing options\n";

Part of this hunk belongs in the previous patch, along with mention of
-h/--help as a common option moved up to this area, and adding mention
of -v/--version (once you fix -v to actually work).


> +++ b/qemu-img.texi
> @@ -1,6 +1,6 @@
>  @example
>  @c man begin SYNOPSIS
> -@command{qemu-img} @var{command} [@var{command} @var{options}]
> +@command{qemu-img} [@var{common} @var{options}] @var{command} [@var{command} @var{options}]

Again, this hunk belongs in the previous commit.

>  @c man end
>  @end example
>  
> @@ -16,6 +16,38 @@ inconsistent state.
>  
>  @c man begin OPTIONS
>  
> +Common options:
> +@table @option
> +@item -T, --trace [events=@var{file}][,file=@var{file}]

As in patch 3, why does this synopsis vary from the --help output?

Rather than duplicating the same text in multiple .texi files, should we
put the text in a single sub-file then use inclusion to pull it in? That
way, if we ever tweak the common option parsing for --trace, updating
the one sub-file will update all 3 man pages (qemu, qemu-img, qemu-nbd).
Denis V. Lunev June 3, 2016, 2:58 p.m. UTC | #2
On 06/03/2016 05:55 PM, Eric Blake wrote:
> On 06/02/2016 12:35 PM, Denis V. Lunev wrote:
>> The command will work this way:
>>      qemu-img --trace qcow2* create -f qcow2 1.img 64G
>>
>> Signed-off-by: Denis V. Lunev <den@openvz.org>
>> Suggested by: Daniel P. Berrange <berrange@redhat.com>
>> CC: Eric Blake <eblake@redhat.com>
>> CC: Paolo Bonzini <pbonzini@redhat.com>
>> CC: Stefan Hajnoczi <stefanha@redhat.com>
>> CC: Kevin Wolf <kwolf@redhat.com>
>> ---
>>   qemu-img.c    | 24 +++++++++++++++++++++---
>>   qemu-img.texi | 34 +++++++++++++++++++++++++++++++++-
>>   2 files changed, 54 insertions(+), 4 deletions(-)
>>
>> @@ -87,7 +89,7 @@ static void QEMU_NORETURN help(void)
>>   {
>>       const char *help_msg =
>>              QEMU_IMG_VERSION
>> -           "usage: qemu-img command [command options]\n"
>> +           "usage: qemu-img [common options] command [command options]\n"
>>              "QEMU disk image utility\n"
> This hunk belongs in the previous patch
>
>>              "\n"
>>              "Command syntax:\n"
>> @@ -156,10 +158,14 @@ static void QEMU_NORETURN help(void)
>>              "  '-f' first image format\n"
>>              "  '-F' second image format\n"
>>              "  '-s' run in Strict mode - fail on different image size or sector allocation\n";
>> +    const char *help_msg2 =
>> +           "Common options:\n"
>> +           "  '-T', --trace [[enable=]<pattern>][,events=<file>][,file=<file>]\n"
>> +           "       specify tracing options\n";
> Part of this hunk belongs in the previous patch, along with mention of
> -h/--help as a common option moved up to this area, and adding mention
> of -v/--version (once you fix -v to actually work).
>
>
>> +++ b/qemu-img.texi
>> @@ -1,6 +1,6 @@
>>   @example
>>   @c man begin SYNOPSIS
>> -@command{qemu-img} @var{command} [@var{command} @var{options}]
>> +@command{qemu-img} [@var{common} @var{options}] @var{command} [@var{command} @var{options}]
> Again, this hunk belongs in the previous commit.
>
>>   @c man end
>>   @end example
>>   
>> @@ -16,6 +16,38 @@ inconsistent state.
>>   
>>   @c man begin OPTIONS
>>   
>> +Common options:
>> +@table @option
>> +@item -T, --trace [events=@var{file}][,file=@var{file}]
> As in patch 3, why does this synopsis vary from the --help output?
same mistake, have tossed these bits several times. Will fix.

> Rather than duplicating the same text in multiple .texi files, should we
> put the text in a single sub-file then use inclusion to pull it in? That
> way, if we ever tweak the common option parsing for --trace, updating
> the one sub-file will update all 3 man pages (qemu, qemu-img, qemu-nbd).
>
thanks a lot for a review!
diff mbox

Patch

diff --git a/qemu-img.c b/qemu-img.c
index aa85b6c..3b069d8 100644
--- a/qemu-img.c
+++ b/qemu-img.c
@@ -31,6 +31,7 @@ 
 #include "qemu/config-file.h"
 #include "qemu/option.h"
 #include "qemu/error-report.h"
+#include "qemu/log.h"
 #include "qom/object_interfaces.h"
 #include "sysemu/sysemu.h"
 #include "sysemu/block-backend.h"
@@ -38,6 +39,7 @@ 
 #include "block/blockjob.h"
 #include "block/qapi.h"
 #include "crypto/init.h"
+#include "trace/control.h"
 #include <getopt.h>
 
 #define QEMU_IMG_VERSION "qemu-img version " QEMU_VERSION QEMU_PKGVERSION \
@@ -87,7 +89,7 @@  static void QEMU_NORETURN help(void)
 {
     const char *help_msg =
            QEMU_IMG_VERSION
-           "usage: qemu-img command [command options]\n"
+           "usage: qemu-img [common options] command [command options]\n"
            "QEMU disk image utility\n"
            "\n"
            "Command syntax:\n"
@@ -156,10 +158,14 @@  static void QEMU_NORETURN help(void)
            "  '-f' first image format\n"
            "  '-F' second image format\n"
            "  '-s' run in Strict mode - fail on different image size or sector allocation\n";
+    const char *help_msg2 =
+           "Common options:\n"
+           "  '-T', --trace [[enable=]<pattern>][,events=<file>][,file=<file>]\n"
+           "       specify tracing options\n";
 
     printf("%s\nSupported formats:", help_msg);
     bdrv_iterate_format(format_print, NULL);
-    printf("\n");
+    printf("\n\n%s", help_msg2);
     exit(EXIT_SUCCESS);
 }
 
@@ -3473,10 +3479,12 @@  int main(int argc, char **argv)
     const img_cmd_t *cmd;
     const char *cmdname;
     Error *local_error = NULL;
+    char *trace_file = NULL;
     int c;
     static const struct option long_options[] = {
         {"help", no_argument, 0, 'h'},
         {"version", no_argument, 0, 'v'},
+        {"trace", required_argument, NULL, 'T'},
         {0, 0, 0, 0}
     };
 
@@ -3502,8 +3510,9 @@  int main(int argc, char **argv)
 
     qemu_add_opts(&qemu_object_opts);
     qemu_add_opts(&qemu_source_opts);
+    qemu_add_opts(&qemu_trace_opts);
 
-    while ((c = getopt_long(argc, argv, "+h", long_options, NULL)) != -1) {
+    while ((c = getopt_long(argc, argv, "+hT:", long_options, NULL)) != -1) {
         switch (c) {
         case 'h':
             help();
@@ -3511,6 +3520,9 @@  int main(int argc, char **argv)
         case 'v':
             printf(QEMU_IMG_VERSION);
             return 0;
+        case 'T':
+            trace_file = trace_opt_parse(optarg, trace_file);
+            break;
         }
     }
 
@@ -3521,6 +3533,12 @@  int main(int argc, char **argv)
     argv += optind;
     optind = 1;
 
+    if (!trace_init_backends()) {
+        exit(1);
+    }
+    trace_init_file(trace_file);
+    qemu_set_log(LOG_TRACE);
+
     /* find the command */
     for (cmd = img_cmds; cmd->name != NULL; cmd++) {
         if (!strcmp(cmdname, cmd->name)) {
diff --git a/qemu-img.texi b/qemu-img.texi
index afaebdd..36f4240 100644
--- a/qemu-img.texi
+++ b/qemu-img.texi
@@ -1,6 +1,6 @@ 
 @example
 @c man begin SYNOPSIS
-@command{qemu-img} @var{command} [@var{command} @var{options}]
+@command{qemu-img} [@var{common} @var{options}] @var{command} [@var{command} @var{options}]
 @c man end
 @end example
 
@@ -16,6 +16,38 @@  inconsistent state.
 
 @c man begin OPTIONS
 
+Common options:
+@table @option
+@item -T, --trace [events=@var{file}][,file=@var{file}]
+@findex --trace
+
+Specify tracing options.
+
+@table @option
+@item [enable=]@var{pattern}
+Immediately enable events matching @var{pattern}.
+The file must contain one event name (as listed in the @file{trace-events} file)
+per line; globbing patterns are accepted too.  This option is only
+available if QEMU IMG has been compiled with the @var{simple}, @var{stderr}
+or @var{ftrace} tracing backend.  To specify multiple events or patterns,
+specify the @option{--trace} option multiple times.
+
+Use @code{--trace help} to print a list of names of trace points.
+
+@item events=@var{file}
+Immediately enable events listed in @var{file}.
+The file must contain one event name (as listed in the @file{trace-events} file)
+per line; globbing patterns are accepted too.  This option is only
+available if QEMU IMG has been compiled with the @var{simple}, @var{stderr} or
+@var{ftrace} tracing backend.
+
+@item file=@var{file}
+Log output traces to @var{file}.
+This option is only available if QEMU IMG has been compiled with
+the @var{simple} tracing backend.
+@end table
+@end table
+
 The following commands are supported:
 
 @include qemu-img-cmds.texi