trace: enable tracing in qemu-io/qemu-nbd
v2 cover trace: enable tracing in qemu-io/qemu-nbd
Actually this is a rework of the original patch, set as a part of write-zeroes patchset. Moving it out to process via trace tree.
Changes from v1:
- fixed nits found by Eric
Denis V. Lunev (3):
trace: move qemu_trace_opts to trace/control.c
trace: enable tracing in qemu-io
trace: enable tracing in qemu-nbd
qemu-io.c | 17 +++++++++++++---- qemu-nbd.c | 17 +++++++++++++++++ trace/control.c | 44 +++++++++++++++++++++++++++++++++++++++++++- trace/control.h | 24 +++++++++++++----------- vl.c | 37 +------------------------------------ 5 files changed, 87 insertions(+), 52 deletions(-)
Signature · 1 line
2.5.0
PATCH v2 1/3 trace: move qemu_trace_opts to trace/control.c
The patch also creates trace_opt_parse() helper in trace/control.c to reuse this code in next patches for qemu-nbd and qemu-io.
The patch also makes trace_init_events() static, as this call is not used outside the module anymore.
--- trace/control.c | 44 +++++++++++++++++++++++++++++++++++++++++++- trace/control.h | 24 +++++++++++++----------- vl.c | 37 +------------------------------------ 3 files changed, 57 insertions(+), 48 deletions(-)
trace/control.c +43 -1
@@ -20,11 +20,33 @@#include "qemu/log.h" #endif #include "qemu/error-report.h" +#include "qemu/config-file.h" #include "monitor/monitor.h" int trace_events_enabled_count;bool trace_events_dstate[TRACE_EVENT_COUNT ]; +QemuOptsList qemu_trace_opts = { + .name ="trace" , + .implied_opt_name ="enable" , + .head =QTAILQ_HEAD_INITIALIZER (qemu_trace_opts.head), + .desc = { + { + .name ="enable" , + .type =QEMU_OPT_STRING , + }, + { + .name ="events" , + .type =QEMU_OPT_STRING , + },{ + .name ="file" , + .type =QEMU_OPT_STRING , + }, + {/* end of list */ } + }, +}; + +TraceEvent *trace_event_name (const char *name) {assert (name !=NULL );
@@ -141,7 +163,7 @@ void trace_enable_events(const char *line_buf) } } -void trace_init_events (const char *fname) +static void trace_init_events (const char *fname) {Location loc;FILE *fp;
@@ -216,3 +238,23 @@ bool trace_init_backends(void)return true; } + +char *trace_opt_parse (const char *optarg,char *trace_file) +{ +QemuOpts *opts =qemu_opts_parse_noisily (qemu_find_opts ("trace" ), + optarg, true); +if (!opts) { +exit (1 ); + } +if (qemu_opt_get (opts,"enable" )) { +trace_enable_events (qemu_opt_get (opts,"enable" )); + } +trace_init_events (qemu_opt_get (opts,"events" )); +if (trace_file) { +g_free (trace_file); + } + trace_file =g_strdup (qemu_opt_get (opts,"file" )); +qemu_opts_del (opts); + +return trace_file; +}
trace/control.h +13 -11
@@ -160,17 +160,6 @@ static void trace_event_set_state_dynamic(TraceEvent *ev, bool state);bool trace_init_backends (void );/** -* trace_init_events: -* @events: Name of file with events to be enabled at startup; may be NULL. -* Corresponds to commandline option "-trace events=...". -* -* Read the list of enabled tracing events. -* -* Returns: Whether the backends could be successfully initialized. -*/ -void trace_init_events (const char *file); - -/** * trace_init_file: * @file: Name of trace output file; may be NULL. * Corresponds to commandline option "-trace file=...".
@@ -197,6 +186,19 @@ void trace_list_events(void);*/ void trace_enable_events (const char *line_buf); +/** +* Definition of QEMU options describing trace subsystem configuration +*/ +extern QemuOptsList qemu_trace_opts; + +/** +* trace_opt_parse: +* @optarg: A string argument of --trace command line argument +* @trace_file: current filename to save traces to +* +* Initialize tracing subsystem. +*/ +char *trace_opt_parse (const char *optarg,char *trace_file);#include "trace/control-internal.h"
vl.c +1 -36
@@ -261,26 +261,6 @@ static QemuOptsList qemu_sandbox_opts = { }, }; -static QemuOptsList qemu_trace_opts = { - .name ="trace" , - .implied_opt_name ="enable" , - .head =QTAILQ_HEAD_INITIALIZER (qemu_trace_opts.head), - .desc = { - { - .name ="enable" , - .type =QEMU_OPT_STRING , - }, - { - .name ="events" , - .type =QEMU_OPT_STRING , - },{ - .name ="file" , - .type =QEMU_OPT_STRING , - }, - {/* end of list */ } - }, -}; -static QemuOptsList qemu_option_rom_opts = { .name ="option-rom" , .implied_opt_name ="romfile" ,
@@ -3869,23 +3849,8 @@ int main(int argc, char **argv, char **envp) xen_mode =XEN_ATTACH ;break ;case QEMU_OPTION_trace: - { - opts =qemu_opts_parse_noisily (qemu_find_opts ("trace" ), - optarg, true); -if (!opts) { -exit (1 ); - } -if (qemu_opt_get (opts,"enable" )) { -trace_enable_events (qemu_opt_get (opts,"enable" )); - } -trace_init_events (qemu_opt_get (opts,"events" )); -if (trace_file) { -g_free (trace_file); - } - trace_file =g_strdup (qemu_opt_get (opts,"file" )); -qemu_opts_del (opts); + trace_file =trace_opt_parse (optarg, trace_file);break ; - }case QEMU_OPTION_readconfig: {int ret =qemu_read_config_file (optarg);
Signature · 1 line
2.5.0
PATCH v2 2/3 trace: enable tracing in qemu-io
In reply to Denis V. LunevMoving trace_init_backends() into trace_opt_parse() is not possible. This should be called after daemonize() in vl.c.
--- qemu-io.c | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-)
qemu-io.c +13 -4
@@ -18,6 +18,7 @@#include "qemu/option.h" #include "qemu/config-file.h" #include "qemu/readline.h" +#include "qemu/log.h" #include "qapi/qmp/qstring.h" #include "qom/object_interfaces.h" #include "sysemu/block-backend.h"
@@ -253,7 +254,9 @@ static void usage(const char *name)" -k, --native-aio use kernel AIO implementation (on Linux only)\n" " -t, --cache=MODE use the given cache mode for the image\n" " -d, --discard=MODE use the given discard mode for the image\n" -" -T, --trace FILE enable trace events listed in the given file\n" +" -T, --trace [[enable=]<pattern>][,events=<file>][,file=<file>]\n" +" specify tracing options\n" +" see qemu(1) man page for full description\n" " -h, --help display this help and exit\n" " -V, --version output version information and exit\n" "\n"
@@ -458,6 +461,7 @@ int main(int argc, char **argv)Error *local_error =NULL ;QDict *opts =NULL ;const char *format =NULL ; +char *trace_file =NULL ;#ifdef CONFIG_POSIX signal (SIGPIPE ,SIG_IGN );
@@ -470,6 +474,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);bdrv_init ();while ((c =getopt_long (argc, argv, sopt, lopt, &opt_index)) !=-1 ) {
@@ -509,9 +514,7 @@ int main(int argc, char **argv) }break ;case 'T' : -if (!trace_init_backends ()) { -exit (1 );/* error message will have been printed */ - } + trace_file =trace_opt_parse (optarg, trace_file);break ;case 'V' :printf ("%s version %s\n" , progname,QEMU_VERSION );
@@ -557,6 +560,12 @@ int main(int argc, char **argv)exit (1 ); } +if (!trace_init_backends ()) { +exit (1 ); + } +trace_init_file (trace_file); +qemu_set_log (LOG_TRACE ); +/* initialize commands */ qemuio_add_command (&quit_cmd);qemuio_add_command (&open_cmd);
Signature · 1 line
2.5.0
Re: [Qemu-devel] [PATCH 2/3] trace: enable tracing in qemu-io
Quoted 12 lines · Denis V. Lunev
Moving
trace_init_backends()intotrace_opt_parse()is not possible. This should be called afterdaemonize()invl.c.Signed-off-by Denis V. Lunev <[email protected]>CC Eric Blake <[email protected]>CC Paolo Bonzini <[email protected]>CC Stefan Hajnoczi <[email protected]>CC Kevin Wolf <[email protected]>--- qemu-io.c | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-)
Signature · 2 lines
Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org
PATCH v2 3/3 trace: enable tracing in qemu-nbd
In reply to Denis V. LunevPlease 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.
--- qemu-nbd.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+)
qemu-nbd.c +17 -0
@@ -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 <getopt.h> #include <libgen.h>
@@ -88,6 +90,9 @@ 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" +" -T, --trace [[enable=]<pattern>][,events=<file>][,file=<file>]\n" +" specify tracing options\n" +" see qemu(1) man page for full description\n" #ifdef __linux__"Kernel NBD client support:\n" " -c, --connect=DEV connect FILE to the local NBD device DEV\n"
@@ -498,6 +503,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 +524,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 +538,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 +711,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 +729,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" );
Signature · 1 line
2.5.0
Re: [Qemu-devel] [PATCH 3/3] trace: enable tracing in qemu-nbd
Quoted 4 lines · Denis V. Lunev
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.
Quoted 8 lines
Signed-off-by Denis V. Lunev <[email protected]>CC Eric Blake <[email protected]>CC Paolo Bonzini <[email protected]>CC Stefan Hajnoczi <[email protected]>CC Kevin Wolf <[email protected]>--- qemu-nbd.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+)
Still missing the man page additions. :(
Signature · 2 lines
Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org
Quoted 12 lines · Denis V. Lunev
Actually this is a rework of the original patch, set as a part of write-zeroes patchset. Moving it out to process via trace tree.
Changes from v1:
- fixed nits found by EricSigned-off-by Denis V. Lunev <[email protected]>CC Eric Blake <[email protected]>CC Paolo Bonzini <[email protected]>CC Stefan Hajnoczi <[email protected]>CC Kevin Wolf <[email protected]>
Quoted 4 lines
Denis V. Lunev (3):
trace: moveqemu_trace_optstotrace/control.c
trace: enable tracing in qemu-io
trace: enable tracing in qemu-nbd
Cool, I wanted this feature just the other day ! Do you fancy also addinbg it to qemu-img while you're at it, so we have complete coverage of all block tools.
Regards,
Daniel
Signature · 4 lines
|: http://berrange.com -o- http://www.flickr.com/photos/dberrange/ :| |: http://libvirt.org -o- http://virt-manager.org :| |: http://autobuild.org -o- http://search.cpan.org/~danberr/ :| |: http://entangle-photo.org -o- http://live.gnome.org/gtk-vnc :|
Quoted 17 lines · Daniel P. Berrange
Quoted 12 lines · Denis V. Lunev
Actually this is a rework of the original patch, set as a part of write-zeroes patchset. Moving it out to process via trace tree.
Changes from v1:
- fixed nits found by EricSigned-off-by Denis V. Lunev <[email protected]>CC Eric Blake <[email protected]>CC Paolo Bonzini <[email protected]>CC Stefan Hajnoczi <[email protected]>CC Kevin Wolf <[email protected]>Quoted 4 lines
Denis V. Lunev (3):
trace: moveqemu_trace_optstotrace/control.c
trace: enable tracing in qemu-io
trace: enable tracing in qemu-nbd
Quoted 7 lines
Cool, I wanted this feature just the other day ! Do you fancy also addinbg it to qemu-img while you're at it, so we have complete coverage of all block tools.
Regards,
Daniel
ok. no prob ;)