From patchwork Thu Jun 2 18:35:45 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: 9151087 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 8D36460467 for ; Thu, 2 Jun 2016 18:42:44 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 721E928309 for ; Thu, 2 Jun 2016 18:42:44 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 66A1628327; Thu, 2 Jun 2016 18:42:44 +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 C2B0E28309 for ; Thu, 2 Jun 2016 18:42:43 +0000 (UTC) Received: from localhost ([::1]:49756 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1b8XZq-0008TH-UF for patchwork-qemu-devel@patchwork.kernel.org; Thu, 02 Jun 2016 14:42:42 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:36011) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1b8XTQ-0002zl-L3 for qemu-devel@nongnu.org; Thu, 02 Jun 2016 14:36:06 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1b8XTP-0006gV-8b for qemu-devel@nongnu.org; Thu, 02 Jun 2016 14:36:04 -0400 Received: from mailhub.sw.ru ([195.214.232.25]:8092 helo=relay.sw.ru) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1b8XTO-0006gH-QH for qemu-devel@nongnu.org; Thu, 02 Jun 2016 14:36:03 -0400 Received: from irbis.sw.ru ([10.30.2.139]) by relay.sw.ru (8.13.4/8.13.4) with ESMTP id u52IZjA4004792; Thu, 2 Jun 2016 21:35:55 +0300 (MSK) From: "Denis V. Lunev" To: qemu-block@nongnu.org, qemu-devel@nongnu.org Date: Thu, 2 Jun 2016 21:35:45 +0300 Message-Id: <1464892545-26544-6-git-send-email-den@openvz.org> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1464892545-26544-1-git-send-email-den@openvz.org> References: <1464892545-26544-1-git-send-email-den@openvz.org> X-detected-operating-system: by eggs.gnu.org: OpenBSD 3.x X-Received-From: 195.214.232.25 Subject: [Qemu-devel] [PATCH 5/5] trace: enable tracing 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 --trace qcow2* create -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 | 24 +++++++++++++++++++++--- qemu-img.texi | 34 +++++++++++++++++++++++++++++++++- 2 files changed, 54 insertions(+), 4 deletions(-) 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 #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=]][,events=][,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