All of lore.kernel.org
 help / color / mirror / Atom feed
From: Prerna Saxena <prerna@linux.vnet.ibm.com>
To: qemu-devel <qemu-devel@nongnu.org>
Cc: Maneesh Soni <maneesh@linux.vnet.ibm.com>,
	Ananth Narayan <ananth@linux.vnet.ibm.com>,
	Stefan Hajnoczi <stefanha@linux.vnet.ibm.com>
Subject: [Qemu-devel] [PATCH][Tracing] Specify trace file name
Date: Fri, 9 Jul 2010 16:30:19 +0530	[thread overview]
Message-ID: <20100709163019.2dc123bc@zephyr> (raw)

[PATCH] Allow users to specify a file for trace-outputs at configuration.
Also, allow trace files to be annotated by <pid> so each qemu instance has 
unique traces.

The trace file name can be passed as a config option:
--trace-file=/path/to/file
(Default : /tmp/trace )
At runtime, the pid of the qemu process is appended to the filename so 
that mutiple qemu instances do not have overlapping logs.

Eg : /tmp/trace-1234 for qemu launched with pid 1234.

I have yet to test this on windows. getpid() is used at many places
in code(including vnc.c), so I'm hoping this would be okay too.

Signed-off-by: Prerna Saxena <prerna@linux.vnet.ibm.com>
---
 configure     |   20 ++++++++++++++++++++
 simpletrace.c |   13 ++++++++++++-
 tracetool     |    1 +
 vl.c          |    8 ++++++++
 4 files changed, 41 insertions(+), 1 deletions(-)

diff --git a/configure b/configure
index 02bf602..18cb6ab 100755
--- a/configure
+++ b/configure
@@ -313,6 +313,7 @@ check_utests="no"
 user_pie="no"
 zero_malloc=""
 trace_backend="nop"
+trace_file=""
 
 # OS specific
 if check_define __linux__ ; then
@@ -517,6 +518,8 @@ for opt do
   ;;
   --trace-backend=*) trace_backend="$optarg"
   ;;
+  --trace-file=*) trace_file="$optarg"
+  ;;
   --enable-gprof) gprof="yes"
   ;;
   --static)
@@ -876,6 +879,9 @@ echo "  --disable-docs           disable documentation build"
 echo "  --disable-vhost-net      disable vhost-net acceleration support"
 echo "  --enable-vhost-net       enable vhost-net acceleration support"
 echo "  --trace-backend=B        Trace backend nop simple ust"
+echo "  --trace-file=NAME        Full PATH,NAME of file to store traces"
+echo "                           Default:/tmp/trace-<pid>"
+echo "                           Default:trace-<pid> on Windows"
 echo ""
 echo "NOTE: The object files are built at the place where configure is launched"
 exit 1
@@ -2132,6 +2138,7 @@ echo "fdatasync         $fdatasync"
 echo "uuid support      $uuid"
 echo "vhost-net support $vhost_net"
 echo "Trace backend     $trace_backend"
+echo "Trace Output File $trace_file-<pid>"
 
 if test $sdl_too_old = "yes"; then
 echo "-> Your SDL version is too old - please upgrade to have SDL support"
@@ -2387,6 +2394,19 @@ fi
 if test "$trace_backend" = "ust"; then
   LIBS="-lust $LIBS"
 fi
+# Set the appropriate trace file.
+if test "$trace_backend" = "simple"; then
+  if test "$trace_file" = ""; then
+    if test "$mingw32" = "yes" ; then
+      trace_file="\"trace-%u\""
+    else
+      trace_file="\"/tmp/trace-%u\""
+    fi
+  else
+    trace_file="\"$trace_file-%u\""
+  fi
+fi
+echo "CONFIG_TRACE_FILE=$trace_file" >> $config_host_mak
 echo "TOOLS=$tools" >> $config_host_mak
 echo "ROMS=$roms" >> $config_host_mak
 echo "MAKE=$make" >> $config_host_mak
diff --git a/simpletrace.c b/simpletrace.c
index 57c41fc..4f3228f 100644
--- a/simpletrace.c
+++ b/simpletrace.c
@@ -20,6 +20,16 @@ static TraceRecord trace_buf[TRACE_BUF_LEN];
 static unsigned int trace_idx;
 static FILE *trace_fp;
 
+char* trace_file_name;
+
+/**
+ * Initialize trace file name.
+ */
+int init_trace_file(void)
+{
+   return asprintf(&trace_file_name, CONFIG_TRACE_FILE, getpid());
+}
+
 static void trace(TraceEventID event, unsigned long x1,
                   unsigned long x2, unsigned long x3,
                   unsigned long x4, unsigned long x5) {
@@ -40,7 +50,7 @@ static void trace(TraceEventID event, unsigned long x1,
         trace_idx = 0;
 
         if (!trace_fp) {
-            trace_fp = fopen("/tmp/trace.log", "w");
+            trace_fp = fopen(trace_file_name, "w");
         }
         if (trace_fp) {
             size_t result = fwrite(trace_buf, sizeof trace_buf, 1, trace_fp);
@@ -78,6 +88,7 @@ void do_info_trace(Monitor *mon)
                           trace_buf[i].event, trace_buf[i].x1, trace_buf[i].x2,
                             trace_buf[i].x3, trace_buf[i].x4, trace_buf[i].x5);
     }
+    monitor_printf(mon, "Trace output logged at %s", trace_file_name);
 }
 
 void do_info_all_trace_events(Monitor *mon)
diff --git a/tracetool b/tracetool
index c77280d..05ece45 100755
--- a/tracetool
+++ b/tracetool
@@ -125,6 +125,7 @@ typedef struct {
     bool state;
 } TraceEvent;
 
+int init_trace_file(void);
 void trace1(TraceEventID event, unsigned long x1);
 void trace2(TraceEventID event, unsigned long x1, unsigned long x2);
 void trace3(TraceEventID event, unsigned long x1, unsigned long x2, unsigned long x3);
diff --git a/vl.c b/vl.c
index 920717a..adc28ef 100644
--- a/vl.c
+++ b/vl.c
@@ -95,6 +95,10 @@ extern int madvise(caddr_t, size_t, int);
 #include <windows.h>
 #endif
 
+#ifdef CONFIG_SIMPLE_TRACE
+#include "trace.h"
+#endif
+
 #ifdef CONFIG_SDL
 #if defined(__APPLE__) || defined(main)
 #include <SDL.h>
@@ -2758,6 +2762,10 @@ int main(int argc, char **argv, char **envp)
         exit(1);
     }
 
+    /* Init tracing, if configured */
+#ifdef CONFIG_SIMPLE_TRACE
+    init_trace_file();
+#endif
     /* init the bluetooth world */
     if (foreach_device_config(DEV_BT, bt_parse))
         exit(1);
-- 
1.6.2.5

-- 
Prerna Saxena

Linux Technology Centre,
IBM Systems and Technology Lab,
Bangalore, India

                 reply	other threads:[~2010-07-09 11:00 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20100709163019.2dc123bc@zephyr \
    --to=prerna@linux.vnet.ibm.com \
    --cc=ananth@linux.vnet.ibm.com \
    --cc=maneesh@linux.vnet.ibm.com \
    --cc=qemu-devel@nongnu.org \
    --cc=stefanha@linux.vnet.ibm.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.