From patchwork Thu Jun 2 18:35:43 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: 9151081 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 C3A026074E for ; Thu, 2 Jun 2016 18:37:22 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B398625E13 for ; Thu, 2 Jun 2016 18:37:22 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id A856628327; Thu, 2 Jun 2016 18:37:22 +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 13BCB25E13 for ; Thu, 2 Jun 2016 18:37:21 +0000 (UTC) Received: from localhost ([::1]:49729 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1b8XUe-0003hd-Vh for patchwork-qemu-devel@patchwork.kernel.org; Thu, 02 Jun 2016 14:37:21 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:36052) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1b8XTV-00033F-Hb for qemu-devel@nongnu.org; Thu, 02 Jun 2016 14:36:14 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1b8XTQ-0006gy-DM for qemu-devel@nongnu.org; Thu, 02 Jun 2016 14:36:08 -0400 Received: from mailhub.sw.ru ([195.214.232.25]:33086 helo=relay.sw.ru) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1b8XTP-0006gZ-VB for qemu-devel@nongnu.org; Thu, 02 Jun 2016 14:36:04 -0400 Received: from irbis.sw.ru ([10.30.2.139]) by relay.sw.ru (8.13.4/8.13.4) with ESMTP id u52IZjA2004792; Thu, 2 Jun 2016 21:35:52 +0300 (MSK) From: "Denis V. Lunev" To: qemu-block@nongnu.org, qemu-devel@nongnu.org Date: Thu, 2 Jun 2016 21:35:43 +0300 Message-Id: <1464892545-26544-4-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 3/5] trace: enable tracing in qemu-nbd 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 Please note, trace_init_backends() must be called in the final process, i.e. after daemonization. This is necessary to keep tracing thread in the proper process. Signed-off-by: Denis V. Lunev CC: Eric Blake CC: Paolo Bonzini CC: Stefan Hajnoczi CC: Kevin Wolf --- qemu-nbd.c | 18 +++++++++++++++++- qemu-nbd.texi | 28 ++++++++++++++++++++++++++++ 2 files changed, 45 insertions(+), 1 deletion(-) diff --git a/qemu-nbd.c b/qemu-nbd.c index 6554f0a..cd29164 100644 --- a/qemu-nbd.c +++ b/qemu-nbd.c @@ -27,12 +27,14 @@ #include "qemu/error-report.h" #include "qemu/config-file.h" #include "qemu/bswap.h" +#include "qemu/log.h" #include "block/snapshot.h" #include "qapi/util.h" #include "qapi/qmp/qstring.h" #include "qom/object_interfaces.h" #include "io/channel-socket.h" #include "crypto/init.h" +#include "trace/control.h" #include #include @@ -88,6 +90,8 @@ static void usage(const char *name) "General purpose options:\n" " --object type,id=ID,... define an object such as 'secret' for providing\n" " passwords and/or encryption keys\n" +" --trace [[enable=]][,events=][,file=]\n" +" specify tracing options\n" #ifdef __linux__ "Kernel NBD client support:\n" " -c, --connect=DEV connect FILE to the local NBD device DEV\n" @@ -470,7 +474,7 @@ int main(int argc, char **argv) off_t fd_size; QemuOpts *sn_opts = NULL; const char *sn_id_or_name = NULL; - const char *sopt = "hVb:o:p:rsnP:c:dvk:e:f:tl:x:"; + const char *sopt = "hVb:o:p:rsnP:c:dvk:e:f:tl:x:T:"; struct option lopt[] = { { "help", no_argument, NULL, 'h' }, { "version", no_argument, NULL, 'V' }, @@ -498,6 +502,7 @@ int main(int argc, char **argv) { "export-name", required_argument, NULL, 'x' }, { "tls-creds", required_argument, NULL, QEMU_NBD_OPT_TLSCREDS }, { "image-opts", no_argument, NULL, QEMU_NBD_OPT_IMAGE_OPTS }, + { "trace", required_argument, NULL, 'T' }, { NULL, 0, NULL, 0 } }; int ch; @@ -518,6 +523,7 @@ int main(int argc, char **argv) const char *tlscredsid = NULL; bool imageOpts = false; bool writethrough = true; + char *trace_file = NULL; /* The client thread uses SIGTERM to interrupt the server. A signal * handler ensures that "qemu-nbd -v -c" exits with a nice status code. @@ -531,6 +537,7 @@ int main(int argc, char **argv) module_call_init(MODULE_INIT_QOM); qemu_add_opts(&qemu_object_opts); + qemu_add_opts(&qemu_trace_opts); qemu_init_exec_dir(argv[0]); while ((ch = getopt_long(argc, argv, sopt, lopt, &opt_ind)) != -1) { @@ -703,6 +710,9 @@ int main(int argc, char **argv) case QEMU_NBD_OPT_IMAGE_OPTS: imageOpts = true; break; + case 'T': + trace_file = trace_opt_parse(optarg, trace_file); + break; } } @@ -718,6 +728,12 @@ int main(int argc, char **argv) exit(EXIT_FAILURE); } + if (!trace_init_backends()) { + exit(1); + } + trace_init_file(trace_file); + qemu_set_log(LOG_TRACE); + if (tlscredsid) { if (sockpath) { error_report("TLS is only supported with IPv4/IPv6"); diff --git a/qemu-nbd.texi b/qemu-nbd.texi index 9f23343..e6943ad 100644 --- a/qemu-nbd.texi +++ b/qemu-nbd.texi @@ -92,6 +92,34 @@ Display extra debugging information Display this help and exit @item -V, --version Display version information and exit +@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 NBD 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 NBD 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 NBD has been compiled with +the @var{simple} tracing backend. +@end table @end table @c man end