Skip to content

Commit

Permalink
trace: enable tracing in qemu-img
Browse files Browse the repository at this point in the history
The command will work this way:
    qemu-img --trace "qcow2*" create -f qcow2 1.img 64G

[Quote "qcow2*" to protect against shell globbing as suggested by Eric
Blake <[email protected]>.
--Stefan]

Signed-off-by: Denis V. Lunev <[email protected]>
Reviewed-by: Eric Blake <[email protected]>
Reviewed-by: Stefan Hajnoczi <[email protected]>
Message-id: [email protected]
Suggested by: Daniel P. Berrange <[email protected]>
Reviewed-by: Eric Blake <[email protected]>
Reviewed-by: Stefan Hajnoczi <[email protected]>
CC: Paolo Bonzini <[email protected]>
CC: Kevin Wolf <[email protected]>
Signed-off-by: Stefan Hajnoczi <[email protected]>
  • Loading branch information
Denis V. Lunev authored and stefanhaRH committed Jun 28, 2016
1 parent 1098513 commit 06a1e0c
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 2 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -566,7 +566,7 @@ qemu.1: qemu-doc.texi qemu-options.texi qemu-monitor.texi qemu-monitor-info.texi
" GEN $@")
qemu.1: qemu-option-trace.texi

qemu-img.1: qemu-img.texi qemu-img-cmds.texi
qemu-img.1: qemu-img.texi qemu-option-trace.texi qemu-img-cmds.texi
$(call quiet-command, \
perl -Ww -- $(SRC_PATH)/scripts/texi2pod.pl $< qemu-img.pod && \
$(POD2MAN) --section=1 --center=" " --release=" " qemu-img.pod > $@, \
Expand Down
19 changes: 18 additions & 1 deletion qemu-img.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,15 @@
#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"
#include "block/block_int.h"
#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 \
Expand Down Expand Up @@ -96,6 +98,8 @@ static void QEMU_NORETURN help(void)
"\n"
" '-h', '--help' display this help and exit\n"
" '-V', '--version' output version information and exit\n"
" '-T', '--trace' [[enable=]<pattern>][,events=<file>][,file=<file>]\n"
" specify tracing options\n"
"\n"
"Command syntax:\n"
#define DEF(option, callback, arg_string) \
Expand Down Expand Up @@ -3806,10 +3810,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}
};

Expand All @@ -3835,15 +3841,20 @@ 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, "+hV", long_options, NULL)) != -1) {
while ((c = getopt_long(argc, argv, "+hVT:", long_options, NULL)) != -1) {
switch (c) {
case 'h':
help();
return 0;
case 'V':
printf(QEMU_IMG_VERSION);
return 0;
case 'T':
g_free(trace_file);
trace_file = trace_opt_parse(optarg);
break;
}
}

Expand All @@ -3857,6 +3868,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)) {
Expand Down
3 changes: 3 additions & 0 deletions qemu-img.texi
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ Standard options:
Display this help and exit
@item -V, --version
Display version information and exit
@item -T, --trace [[enable=]@var{pattern}][,events=@var{file}][,file=@var{file}]
@findex --trace
@include qemu-option-trace.texi
@end table

The following commands are supported:
Expand Down

0 comments on commit 06a1e0c

Please sign in to comment.