From patchwork Tue May 31 10:07:02 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Denis V. Lunev" X-Patchwork-Id: 9144147 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id BF71460777 for ; Tue, 31 May 2016 10:07:39 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B0B7E27BF1 for ; Tue, 31 May 2016 10:07:39 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id A51B02793B; Tue, 31 May 2016 10:07:39 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id A2A892793B for ; Tue, 31 May 2016 10:07:38 +0000 (UTC) Received: from localhost ([::1]:35698 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1b7gaH-000100-SF for patchwork-qemu-devel@patchwork.kernel.org; Tue, 31 May 2016 06:07:37 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:50017) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1b7gZr-0000xW-Md for qemu-devel@nongnu.org; Tue, 31 May 2016 06:07:13 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1b7gZn-0007SD-BZ for qemu-devel@nongnu.org; Tue, 31 May 2016 06:07:10 -0400 Received: from mailhub.sw.ru ([195.214.232.25]:22246 helo=relay.sw.ru) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1b7gZm-0007Rn-OW for qemu-devel@nongnu.org; Tue, 31 May 2016 06:07:07 -0400 Received: from hades.sw.ru ([10.30.8.132]) by relay.sw.ru (8.13.4/8.13.4) with ESMTP id u4VA72uI018981; Tue, 31 May 2016 13:07:03 +0300 (MSK) From: "Denis V. Lunev" To: qemu-devel@nongnu.org Date: Tue, 31 May 2016 13:07:02 +0300 Message-Id: <1464689222-1513-1-git-send-email-den@openvz.org> X-Mailer: git-send-email 2.5.0 X-detected-operating-system: by eggs.gnu.org: OpenBSD 3.x X-Received-From: 195.214.232.25 Subject: [Qemu-devel] [PATCH 4/4] trace: enable trace events in qemu-img X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , den@openvz.org, Stefan Hajnoczi , Paolo Bonzini Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP The command will work this way: qemu-img create --trace qcow2* -f qcow2 1.img 64G Signed-off-by: Denis V. Lunev Suggested by: Daniel P. Berrange CC: Eric Blake CC: Paolo Bonzini CC: Stefan Hajnoczi CC: Kevin Wolf --- qemu-img.c | 97 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 96 insertions(+), 1 deletion(-) diff --git a/qemu-img.c b/qemu-img.c index 4b56ad3..9dc4efc 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 #define QEMU_IMG_VERSION "qemu-img version " QEMU_VERSION QEMU_PKGVERSION \ @@ -155,7 +157,12 @@ static void QEMU_NORETURN help(void) "Parameters to compare subcommand:\n" " '-f' first image format\n" " '-F' second image format\n" - " '-s' run in Strict mode - fail on different image size or sector allocation\n"; + " '-s' run in Strict mode - fail on different image size or sector allocation\n" + "\n" + "General purpose options:\n" + " -R, --trace [[enable=]][,events=][,file=]\n" + " specify tracing options\n" + " see qemu(1) man page for full description\n"; printf("%s\nSupported formats:", help_msg); bdrv_iterate_format(format_print, NULL); @@ -194,6 +201,15 @@ static int GCC_FMT_ATTR(2, 3) qprintf(bool quiet, const char *fmt, ...) } +static void trace_setup(const char *trace_file) +{ + if (!trace_init_backends()) { + exit(1); + } + trace_init_file(trace_file); + qemu_set_log(LOG_TRACE); +} + static int print_block_option_help(const char *filename, const char *fmt) { BlockDriver *drv, *proto_drv; @@ -360,11 +376,13 @@ static int img_create(int argc, char **argv) char *options = NULL; Error *local_err = NULL; bool quiet = false; + char *trace_file = NULL; for(;;) { static const struct option long_options[] = { {"help", no_argument, 0, 'h'}, {"object", required_argument, 0, OPTION_OBJECT}, + {"trace", required_argument, NULL, 'R'}, {0, 0, 0, 0} }; c = getopt_long(argc, argv, "F:b:f:he6o:q", @@ -410,6 +428,9 @@ static int img_create(int argc, char **argv) case 'q': quiet = true; break; + case 'R': + trace_file = trace_opt_parse(optarg, trace_file); + break; case OPTION_OBJECT: { QemuOpts *opts; opts = qemu_opts_parse_noisily(&qemu_object_opts, @@ -421,6 +442,8 @@ static int img_create(int argc, char **argv) } } + trace_setup(trace_file); + /* Get the filename */ filename = (optind < argc) ? argv[optind] : NULL; if (options && has_help_option(options)) { @@ -598,6 +621,7 @@ static int img_check(int argc, char **argv) ImageCheck *check; bool quiet = false; bool image_opts = false; + char *trace_file = NULL; fmt = NULL; output = NULL; @@ -612,6 +636,7 @@ static int img_check(int argc, char **argv) {"output", required_argument, 0, OPTION_OUTPUT}, {"object", required_argument, 0, OPTION_OBJECT}, {"image-opts", no_argument, 0, OPTION_IMAGE_OPTS}, + {"trace", required_argument, NULL, 'R'}, {0, 0, 0, 0} }; c = getopt_long(argc, argv, "hf:r:T:q", @@ -648,6 +673,9 @@ static int img_check(int argc, char **argv) case 'q': quiet = true; break; + case 'R': + trace_file = trace_opt_parse(optarg, trace_file); + break; case OPTION_OBJECT: { QemuOpts *opts; opts = qemu_opts_parse_noisily(&qemu_object_opts, @@ -661,6 +689,9 @@ static int img_check(int argc, char **argv) break; } } + + trace_setup(trace_file); + if (optind != argc - 1) { error_exit("Expecting one image file name"); } @@ -801,6 +832,7 @@ static int img_commit(int argc, char **argv) Error *local_err = NULL; CommonBlockJobCBInfo cbi; bool image_opts = false; + char *trace_file = NULL; fmt = NULL; cache = BDRV_DEFAULT_CACHE; @@ -810,6 +842,7 @@ static int img_commit(int argc, char **argv) {"help", no_argument, 0, 'h'}, {"object", required_argument, 0, OPTION_OBJECT}, {"image-opts", no_argument, 0, OPTION_IMAGE_OPTS}, + {"trace", required_argument, NULL, 'R'}, {0, 0, 0, 0} }; c = getopt_long(argc, argv, "f:ht:b:dpq", @@ -842,6 +875,9 @@ static int img_commit(int argc, char **argv) case 'q': quiet = true; break; + case 'R': + trace_file = trace_opt_parse(optarg, trace_file); + break; case OPTION_OBJECT: { QemuOpts *opts; opts = qemu_opts_parse_noisily(&qemu_object_opts, @@ -856,6 +892,8 @@ static int img_commit(int argc, char **argv) } } + trace_setup(trace_file); + /* Progress is not shown in Quiet mode */ if (quiet) { progress = false; @@ -1131,6 +1169,7 @@ static int img_compare(int argc, char **argv) int c, pnum; uint64_t progress_base; bool image_opts = false; + char *trace_file = NULL; cache = BDRV_DEFAULT_CACHE; for (;;) { @@ -1138,6 +1177,7 @@ static int img_compare(int argc, char **argv) {"help", no_argument, 0, 'h'}, {"object", required_argument, 0, OPTION_OBJECT}, {"image-opts", no_argument, 0, OPTION_IMAGE_OPTS}, + {"trace", required_argument, NULL, 'R'}, {0, 0, 0, 0} }; c = getopt_long(argc, argv, "hf:F:T:pqs", @@ -1168,6 +1208,9 @@ static int img_compare(int argc, char **argv) case 's': strict = true; break; + case 'R': + trace_file = trace_opt_parse(optarg, trace_file); + break; case OPTION_OBJECT: { QemuOpts *opts; opts = qemu_opts_parse_noisily(&qemu_object_opts, @@ -1183,6 +1226,8 @@ static int img_compare(int argc, char **argv) } } + trace_setup(trace_file); + /* Progress is not shown in Quiet mode */ if (quiet) { progress = false; @@ -1754,6 +1799,7 @@ static int img_convert(int argc, char **argv) QemuOpts *sn_opts = NULL; ImgConvertState state; bool image_opts = false; + char *trace_file = NULL; fmt = NULL; out_fmt = "raw"; @@ -1767,6 +1813,7 @@ static int img_convert(int argc, char **argv) {"help", no_argument, 0, 'h'}, {"object", required_argument, 0, OPTION_OBJECT}, {"image-opts", no_argument, 0, OPTION_IMAGE_OPTS}, + {"trace", required_argument, NULL, 'R'}, {0, 0, 0, 0} }; c = getopt_long(argc, argv, "hf:O:B:ce6o:s:l:S:pt:T:qn", @@ -1861,6 +1908,9 @@ static int img_convert(int argc, char **argv) case 'n': skip_create = 1; break; + case 'R': + trace_file = trace_opt_parse(optarg, trace_file); + break; case OPTION_OBJECT: opts = qemu_opts_parse_noisily(&qemu_object_opts, optarg, true); @@ -1874,6 +1924,8 @@ static int img_convert(int argc, char **argv) } } + trace_setup(trace_file); + if (qemu_opts_foreach(&qemu_object_opts, user_creatable_add_opts_foreach, NULL, NULL)) { @@ -2311,6 +2363,7 @@ static int img_info(int argc, char **argv) const char *filename, *fmt, *output; ImageInfoList *list; bool image_opts = false; + char *trace_file = NULL; fmt = NULL; output = NULL; @@ -2323,6 +2376,7 @@ static int img_info(int argc, char **argv) {"backing-chain", no_argument, 0, OPTION_BACKING_CHAIN}, {"object", required_argument, 0, OPTION_OBJECT}, {"image-opts", no_argument, 0, OPTION_IMAGE_OPTS}, + {"trace", required_argument, NULL, 'R'}, {0, 0, 0, 0} }; c = getopt_long(argc, argv, "f:h", @@ -2344,6 +2398,9 @@ static int img_info(int argc, char **argv) case OPTION_BACKING_CHAIN: chain = true; break; + case 'R': + trace_file = trace_opt_parse(optarg, trace_file); + break; case OPTION_OBJECT: { QemuOpts *opts; opts = qemu_opts_parse_noisily(&qemu_object_opts, @@ -2357,6 +2414,9 @@ static int img_info(int argc, char **argv) break; } } + + trace_setup(trace_file); + if (optind != argc - 1) { error_exit("Expecting one image file name"); } @@ -2523,6 +2583,7 @@ static int img_map(int argc, char **argv) MapEntry curr = { .length = 0 }, next; int ret = 0; bool image_opts = false; + char *trace_file = NULL; fmt = NULL; output = NULL; @@ -2534,6 +2595,7 @@ static int img_map(int argc, char **argv) {"output", required_argument, 0, OPTION_OUTPUT}, {"object", required_argument, 0, OPTION_OBJECT}, {"image-opts", no_argument, 0, OPTION_IMAGE_OPTS}, + {"trace", required_argument, NULL, 'R'}, {0, 0, 0, 0} }; c = getopt_long(argc, argv, "f:h", @@ -2552,6 +2614,9 @@ static int img_map(int argc, char **argv) case OPTION_OUTPUT: output = optarg; break; + case 'R': + trace_file = trace_opt_parse(optarg, trace_file); + break; case OPTION_OBJECT: { QemuOpts *opts; opts = qemu_opts_parse_noisily(&qemu_object_opts, @@ -2648,6 +2713,7 @@ static int img_snapshot(int argc, char **argv) bool quiet = false; Error *err = NULL; bool image_opts = false; + char *trace_file = NULL; bdrv_oflags = BDRV_O_RDWR; /* Parse commandline parameters */ @@ -2656,6 +2722,7 @@ static int img_snapshot(int argc, char **argv) {"help", no_argument, 0, 'h'}, {"object", required_argument, 0, OPTION_OBJECT}, {"image-opts", no_argument, 0, OPTION_IMAGE_OPTS}, + {"trace", required_argument, NULL, 'R'}, {0, 0, 0, 0} }; c = getopt_long(argc, argv, "la:c:d:hq", @@ -2703,6 +2770,9 @@ static int img_snapshot(int argc, char **argv) case 'q': quiet = true; break; + case 'R': + trace_file = trace_opt_parse(optarg, trace_file); + break; case OPTION_OBJECT: { QemuOpts *opts; opts = qemu_opts_parse_noisily(&qemu_object_opts, @@ -2717,6 +2787,8 @@ static int img_snapshot(int argc, char **argv) } } + trace_setup(trace_file); + if (optind != argc - 1) { error_exit("Expecting one image file name"); } @@ -2797,6 +2869,7 @@ static int img_rebase(int argc, char **argv) bool quiet = false; Error *local_err = NULL; bool image_opts = false; + char *trace_file = NULL; /* Parse commandline parameters */ fmt = NULL; @@ -2809,6 +2882,7 @@ static int img_rebase(int argc, char **argv) {"help", no_argument, 0, 'h'}, {"object", required_argument, 0, OPTION_OBJECT}, {"image-opts", no_argument, 0, OPTION_IMAGE_OPTS}, + {"trace", required_argument, NULL, 'R'}, {0, 0, 0, 0} }; c = getopt_long(argc, argv, "hf:F:b:upt:T:q", @@ -2845,6 +2919,9 @@ static int img_rebase(int argc, char **argv) case 'q': quiet = true; break; + case 'R': + trace_file = trace_opt_parse(optarg, trace_file); + break; case OPTION_OBJECT: { QemuOpts *opts; opts = qemu_opts_parse_noisily(&qemu_object_opts, @@ -2859,6 +2936,8 @@ static int img_rebase(int argc, char **argv) } } + trace_setup(trace_file); + if (quiet) { progress = 0; } @@ -3157,6 +3236,7 @@ static int img_resize(int argc, char **argv) }, }; bool image_opts = false; + char *trace_file = NULL; /* Remove size from argv manually so that negative numbers are not treated * as options by getopt. */ @@ -3174,6 +3254,7 @@ static int img_resize(int argc, char **argv) {"help", no_argument, 0, 'h'}, {"object", required_argument, 0, OPTION_OBJECT}, {"image-opts", no_argument, 0, OPTION_IMAGE_OPTS}, + {"trace", required_argument, NULL, 'R'}, {0, 0, 0, 0} }; c = getopt_long(argc, argv, "f:hq", @@ -3192,6 +3273,9 @@ static int img_resize(int argc, char **argv) case 'q': quiet = true; break; + case 'R': + trace_file = trace_opt_parse(optarg, trace_file); + break; case OPTION_OBJECT: { QemuOpts *opts; opts = qemu_opts_parse_noisily(&qemu_object_opts, @@ -3205,6 +3289,9 @@ static int img_resize(int argc, char **argv) break; } } + + trace_setup(trace_file); + if (optind != argc - 1) { error_exit("Expecting one image file name"); } @@ -3305,6 +3392,7 @@ static int img_amend(int argc, char **argv) BlockBackend *blk = NULL; BlockDriverState *bs = NULL; bool image_opts = false; + char *trace_file = NULL; cache = BDRV_DEFAULT_CACHE; for (;;) { @@ -3312,6 +3400,7 @@ static int img_amend(int argc, char **argv) {"help", no_argument, 0, 'h'}, {"object", required_argument, 0, OPTION_OBJECT}, {"image-opts", no_argument, 0, OPTION_IMAGE_OPTS}, + {"trace", required_argument, NULL, 'R'}, {0, 0, 0, 0} }; c = getopt_long(argc, argv, "ho:f:t:pq", @@ -3351,6 +3440,9 @@ static int img_amend(int argc, char **argv) case 'q': quiet = true; break; + case 'R': + trace_file = trace_opt_parse(optarg, trace_file); + break; case OPTION_OBJECT: opts = qemu_opts_parse_noisily(&qemu_object_opts, optarg, true); @@ -3365,6 +3457,8 @@ static int img_amend(int argc, char **argv) } } + trace_setup(trace_file); + if (!options) { error_exit("Must specify options (-o)"); } @@ -3503,6 +3597,7 @@ int main(int argc, char **argv) qemu_add_opts(&qemu_object_opts); qemu_add_opts(&qemu_source_opts); + qemu_add_opts(&qemu_trace_opts); /* find the command */ for (cmd = img_cmds; cmd->name != NULL; cmd++) {