Richard W.M. Jones
2011-Jan-28 11:15 UTC
[Libguestfs] [PATCH] Add a prefix to output when tracing (RHBZ#673479).
-- Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones virt-p2v converts physical machines to virtual machines. Boot with a live CD or over the network (PXE) and turn machines into Xen guests. http://et.redhat.com/~rjones/virt-p2v -------------- next part -------------->From 21d41177fd8bc429f514227903329bc18bc33a64 Mon Sep 17 00:00:00 2001From: Richard W.M. Jones <rjones at redhat.com> Date: Fri, 28 Jan 2011 11:14:42 +0000 Subject: [PATCH] Add a prefix to output when tracing (RHBZ#673479). --- generator/generator_c.ml | 5 +++-- 1 files changed, 3 insertions(+), 2 deletions(-) diff --git a/generator/generator_c.ml b/generator/generator_c.ml index 46ba691..5a38e0c 100644 --- a/generator/generator_c.ml +++ b/generator/generator_c.ml @@ -1,5 +1,5 @@ (* libguestfs - * Copyright (C) 2009-2010 Red Hat Inc. + * Copyright (C) 2009-2011 Red Hat Inc. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -729,7 +729,8 @@ check_state (guestfs_h *g, const char *caller) pr "\n" ); - pr " fprintf (stderr, \"%s\");\n" shortname; + pr " fprintf (stderr, \"%%s: %%s: %%s\",\n"; + pr " \"libguestfs\", \"trace\", \"%s\");\n" shortname; (* Required arguments. *) List.iter ( -- 1.7.3.5
Matthew Booth
2011-Jan-28 11:25 UTC
[Libguestfs] [PATCH] Add a prefix to output when tracing (RHBZ#673479).
On 28/01/11 11:15, Richard W.M. Jones wrote:> From 21d41177fd8bc429f514227903329bc18bc33a64 Mon Sep 17 00:00:00 2001 > From: Richard W.M. Jones<rjones at redhat.com> > Date: Fri, 28 Jan 2011 11:14:42 +0000 > Subject: [PATCH] Add a prefix to output when tracing (RHBZ#673479). > > --- > generator/generator_c.ml | 5 +++-- > 1 files changed, 3 insertions(+), 2 deletions(-)This is fine. However, it doesn't completely solve the issue of intermingling TRACE and DEBUG output, because DEBUG will be embedded in between the command and result parts of the TRACE output. As discussed on IRC, how about putting the result on a separate line? Matt -- Matthew Booth, RHCA, RHCSS Red Hat Engineering, Virtualisation Team GPG ID: D33C3490 GPG FPR: 3733 612D 2D05 5458 8A8A 1600 3441 EA19 D33C 3490
Richard W.M. Jones
2011-Jan-28 11:41 UTC
[Libguestfs] [PATCH v2] Add a prefix to output when tracing (RHBZ#673479).
-- Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones virt-top is 'top' for virtual machines. Tiny program with many powerful monitoring features, net stats, disk stats, logging, etc. http://et.redhat.com/~rjones/virt-top -------------- next part -------------->From 54d40aa2776d12b1de2f23b9e90022222ec7aea0 Mon Sep 17 00:00:00 2001From: Richard W.M. Jones <rjones at redhat.com> Date: Fri, 28 Jan 2011 11:14:42 +0000 Subject: [PATCH] Add a prefix to output when tracing (RHBZ#673479). Also separate the call and return lines so that everything can be easily 'grepped' from debug output. The trace output now looks like this: $ guestfish -x -N fs exit libguestfs: trace: is_config libguestfs: trace: is_config = 1 libguestfs: trace: add_drive "test1.img" libguestfs: trace: add_drive = 0 libguestfs: trace: is_config libguestfs: trace: is_config = 1 libguestfs: trace: launch libguestfs: trace: launch = 0 libguestfs: trace: part_disk "/dev/sda" "mbr" libguestfs: trace: part_disk = 0 &c. --- generator/generator_c.ml | 48 ++++++++++++++++++++++++++++----------------- 1 files changed, 30 insertions(+), 18 deletions(-) diff --git a/generator/generator_c.ml b/generator/generator_c.ml index 46ba691..82da6b8 100644 --- a/generator/generator_c.ml +++ b/generator/generator_c.ml @@ -1,5 +1,5 @@ (* libguestfs - * Copyright (C) 2009-2010 Red Hat Inc. + * Copyright (C) 2009-2011 Red Hat Inc. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -729,7 +729,8 @@ check_state (guestfs_h *g, const char *caller) pr "\n" ); - pr " fprintf (stderr, \"%s\");\n" shortname; + pr " fprintf (stderr, \"%%s: %%s: %%s\",\n"; + pr " \"libguestfs\", \"trace\", \"%s\");\n" shortname; (* Required arguments. *) List.iter ( @@ -791,11 +792,12 @@ check_state (guestfs_h *g, const char *caller) ); ) optargs; + pr " fputc ('\\n', stderr);\n"; pr " }\n"; pr "\n"; in - let trace_return ?(indent = 2) (ret, _, _) rv + let trace_return ?(indent = 2) shortname (ret, _, _) rv let indent = spaces indent in pr "%sif (trace_flag) {\n" indent; @@ -809,7 +811,10 @@ check_state (guestfs_h *g, const char *caller) pr "\n" ); - pr "%s fputs (\" = \", stderr);\n" indent; + pr "%s fprintf (stderr, \"%%s: %%s: %%s = \",\n" indent; + pr "%s \"libguestfs\", \"trace\", \"%s\");\n" + indent shortname; + (match ret with | RErr | RInt _ | RBool _ -> pr "%s fprintf (stderr, \"%%d\", %s);\n" indent rv @@ -845,23 +850,30 @@ check_state (guestfs_h *g, const char *caller) pr "\n"; in - let trace_return_error ?(indent = 2) (ret, _, _) + let trace_return_error ?(indent = 2) shortname (ret, _, _) let indent = spaces indent in - pr "%sif (trace_flag)\n" indent; + pr "%sif (trace_flag) {\n" indent; + + pr "%s fprintf (stderr, \"%%s: %%s: %%s = \",\n" indent; + pr "%s \"libguestfs\", \"trace\", \"%s\");\n" + indent shortname; (match ret with | RErr | RInt _ | RBool _ | RInt64 _ -> - pr "%s fputs (\" = -1 (error)\\n\", stderr);\n" indent + pr "%s fputs (\"-1 (error)\\n\", stderr);\n" indent | RConstString _ | RString _ | RConstOptString _ | RBufferOut _ | RStringList _ | RHashtable _ | RStruct _ | RStructList _ -> - pr "%s fputs (\" = NULL (error)\\n\", stderr);\n" indent + pr "%s fputs (\"NULL (error)\\n\", stderr);\n" indent ); + + pr "%s}\n" indent; + pr "\n"; in (* For non-daemon functions, generate a wrapper around each function. *) @@ -900,7 +912,7 @@ check_state (guestfs_h *g, const char *caller) pr " r = guestfs__%s " shortname; generate_c_call_args ~handle:"g" style; pr ";\n"; - trace_return style "r"; + trace_return shortname style "r"; pr " return r;\n"; pr "}\n"; pr "\n" @@ -990,7 +1002,7 @@ check_state (guestfs_h *g, const char *caller) (* Check we are in the right state for sending a request. *) pr " if (check_state (g, \"%s\") == -1) {\n" shortname; - trace_return_error ~indent:4 style; + trace_return_error ~indent:4 shortname style; pr " return %s;\n" error_code; pr " }\n"; pr " guestfs___set_busy (g);\n"; @@ -1021,7 +1033,7 @@ check_state (guestfs_h *g, const char *caller) | BufferIn n -> pr " /* Just catch grossly large sizes. XDR encoding will make this precise. */\n"; pr " if (%s_size >= GUESTFS_MESSAGE_MAX) {\n" n; - trace_return_error ~indent:4 style; + trace_return_error ~indent:4 shortname style; pr " error (g, \"%%s: size of input buffer too large\", \"%s\");\n" shortname; pr " guestfs___end_busy (g);\n"; @@ -1063,7 +1075,7 @@ check_state (guestfs_h *g, const char *caller) ); pr " if (serial == -1) {\n"; pr " guestfs___end_busy (g);\n"; - trace_return_error ~indent:4 style; + trace_return_error ~indent:4 shortname style; pr " return %s;\n" error_code; pr " }\n"; pr "\n"; @@ -1076,7 +1088,7 @@ check_state (guestfs_h *g, const char *caller) pr " r = guestfs___send_file (g, %s);\n" n; pr " if (r == -1) {\n"; pr " guestfs___end_busy (g);\n"; - trace_return_error ~indent:4 style; + trace_return_error ~indent:4 shortname style; pr " return %s;\n" error_code; pr " }\n"; pr " if (r == -2) /* daemon cancelled */\n"; @@ -1101,7 +1113,7 @@ check_state (guestfs_h *g, const char *caller) pr " if (r == -1) {\n"; pr " guestfs___end_busy (g);\n"; - trace_return_error ~indent:4 style; + trace_return_error ~indent:4 shortname style; pr " return %s;\n" error_code; pr " }\n"; pr "\n"; @@ -1109,13 +1121,13 @@ check_state (guestfs_h *g, const char *caller) pr " if (check_reply_header (g, &hdr, GUESTFS_PROC_%s, serial) == -1) {\n" (String.uppercase shortname); pr " guestfs___end_busy (g);\n"; - trace_return_error ~indent:4 style; + trace_return_error ~indent:4 shortname style; pr " return %s;\n" error_code; pr " }\n"; pr "\n"; pr " if (hdr.status == GUESTFS_STATUS_ERROR) {\n"; - trace_return_error ~indent:4 style; + trace_return_error ~indent:4 shortname style; pr " int errnum = 0;\n"; pr " if (err.errno_string[0] != '\\0')\n"; pr " errnum = guestfs___string_to_errno (err.errno_string);\n"; @@ -1139,7 +1151,7 @@ check_state (guestfs_h *g, const char *caller) | FileOut n -> pr " if (guestfs___recv_file (g, %s) == -1) {\n" n; pr " guestfs___end_busy (g);\n"; - trace_return_error ~indent:4 style; + trace_return_error ~indent:4 shortname style; pr " return %s;\n" error_code; pr " }\n"; pr "\n"; @@ -1187,7 +1199,7 @@ check_state (guestfs_h *g, const char *caller) pr " ret_v = p;\n"; pr " }\n"; ); - trace_return style "ret_v"; + trace_return shortname style "ret_v"; pr " return ret_v;\n"; pr "}\n\n" ) daemon_functions; -- 1.7.3.5