From 62e41312acd0f7fe7f3622a73d6f6efc27b1b511 Mon Sep 17 00:00:00 2001 From: "Richard W.M. Jones" Date: Thu, 2 Jul 2009 15:11:59 +0100 Subject: [PATCH] Add list of function_names to the daemon. Messages which include the proc_nr can now also include the name of the actual function being called. --- .gitignore | 1 + daemon/Makefile.am | 1 + daemon/daemon.h | 3 +++ daemon/proto.c | 6 ++++-- src/generator.ml | 20 ++++++++++++++++++++ 5 files changed, 29 insertions(+), 2 deletions(-) diff --git a/.gitignore b/.gitignore index 495b844..a101547 100644 --- a/.gitignore +++ b/.gitignore @@ -50,6 +50,7 @@ daemon/actions.h daemon/guestfsd daemon/install-sh daemon/missing +daemon/names.c daemon/stubs.c depcomp emptydisk diff --git a/daemon/Makefile.am b/daemon/Makefile.am index 8b909c5..141dfad 100644 --- a/daemon/Makefile.am +++ b/daemon/Makefile.am @@ -48,6 +48,7 @@ guestfsd_SOURCES = \ lvm.c \ mknod.c \ mount.c \ + names.c \ ntfs.c \ pingdaemon.c \ proto.c \ diff --git a/daemon/daemon.h b/daemon/daemon.h index 553973d..5f22a4f 100644 --- a/daemon/daemon.h +++ b/daemon/daemon.h @@ -55,6 +55,9 @@ extern void udev_settle (void); extern int verbose; +/*-- in names.c (auto-generated) --*/ +extern const char *function_names[]; + /*-- in proto.c --*/ extern int proc_nr; extern int serial; diff --git a/daemon/proto.c b/daemon/proto.c index 39cee5a..3ca4316 100644 --- a/daemon/proto.c +++ b/daemon/proto.c @@ -146,8 +146,10 @@ main_loop (int _sock) start_us = (int64_t) start_t.tv_sec * 1000000 + start_t.tv_usec; end_us = (int64_t) end_t.tv_sec * 1000000 + end_t.tv_usec; elapsed_us = end_us - start_us; - fprintf (stderr, "proc %d serial %d took %d.%02d seconds\n", - proc_nr, serial, + fprintf (stderr, "proc %d (%s) took %d.%02d seconds\n", + proc_nr, + proc_nr >= 0 && proc_nr < GUESTFS_PROC_NR_PROCS + ? function_names[proc_nr] : "UNKNOWN PROCEDURE", (int) (elapsed_us / 1000000), (int) ((elapsed_us / 10000) % 100)); } diff --git a/src/generator.ml b/src/generator.ml index 29e6651..f41413e 100755 --- a/src/generator.ml +++ b/src/generator.ml @@ -4318,6 +4318,22 @@ and generate_daemon_actions () = ) ["pv", pv_cols; "vg", vg_cols; "lv", lv_cols] +(* Generate a list of function names, for debugging in the daemon.. *) +and generate_daemon_names () = + generate_header CStyle GPLv2; + + pr "#include \n"; + pr "\n"; + pr "#include \"daemon.h\"\n"; + pr "\n"; + + pr "/* This array is indexed by proc_nr. See guestfs_protocol.x. */\n"; + pr "const char *function_names[] = {\n"; + List.iter ( + fun (name, _, proc_nr, _, _, _, _) -> pr " [%d] = \"%s\",\n" proc_nr name + ) daemon_functions; + pr "};\n"; + (* Generate the tests. *) and generate_tests () = generate_header CStyle GPLv2; @@ -8610,6 +8626,10 @@ Run it from the top source directory using the command generate_daemon_actions (); close (); + let close = output_to "daemon/names.c" in + generate_daemon_names (); + close (); + let close = output_to "capitests/tests.c" in generate_tests (); close (); -- 1.8.3.1