All of lore.kernel.org
 help / color / mirror / Atom feed
From: Stefan Hajnoczi <stefanha@linux.vnet.ibm.com>
To: qemu-devel@nongnu.org
Cc: Blue Swirl <blauwirbel@gmail.com>,
	Anthony Liguori <aliguori@us.ibm.com>,
	"Michael S. Tsirkin" <mst@redhat.com>,
	Stefan Hajnoczi <stefanha@linux.vnet.ibm.com>,
	Prerna Saxena <prerna@linux.vnet.ibm.com>
Subject: [Qemu-devel] [PATCH 05/14] trace: Specify trace file name
Date: Mon,  6 Sep 2010 16:14:02 +0100	[thread overview]
Message-ID: <1283786051-29530-6-git-send-email-stefanha@linux.vnet.ibm.com> (raw)
In-Reply-To: <1283786051-29530-1-git-send-email-stefanha@linux.vnet.ibm.com>

From: Prerna Saxena <prerna@linux.vnet.ibm.com>

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: 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 : 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.

Edited-by: Stefan Hajnoczi <stefanha@linux.vnet.ibm.com>
Signed-off-by: Stefan Hajnoczi <stefanha@linux.vnet.ibm.com>
---
 configure     |   12 ++++++++++++
 simpletrace.c |   21 +++++++++++++++++----
 2 files changed, 29 insertions(+), 4 deletions(-)

diff --git a/configure b/configure
index 5afb3b5..234e75b 100755
--- a/configure
+++ b/configure
@@ -318,6 +318,7 @@ check_utests="no"
 user_pie="no"
 zero_malloc=""
 trace_backend="nop"
+trace_file="trace"
 
 # OS specific
 if check_define __linux__ ; then
@@ -522,6 +523,8 @@ for opt do
   ;;
   --trace-backend=*) trace_backend="$optarg"
   ;;
+  --trace-file=*) trace_file="$optarg"
+  ;;
   --enable-gprof) gprof="yes"
   ;;
   --static)
@@ -901,6 +904,8 @@ 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"
+echo "  --trace-file=NAME        Full PATH,NAME of file to store traces"
+echo "                           Default:trace-<pid>"
 echo ""
 echo "NOTE: The object files are built at the place where configure is launched"
 exit 1
@@ -2206,6 +2211,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"
@@ -2471,6 +2477,12 @@ echo "TRACE_BACKEND=$trace_backend" >> $config_host_mak
 if test "$trace_backend" = "simple"; then
   echo "CONFIG_SIMPLE_TRACE=y" >> $config_host_mak
 fi
+# Set the appropriate trace file.
+if test "$trace_backend" = "simple"; then
+  trace_file="\"$trace_file-%u\""
+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 688959a..97045a6 100644
--- a/simpletrace.c
+++ b/simpletrace.c
@@ -54,13 +54,26 @@ static bool write_header(FILE *fp)
     return fwrite(&header, sizeof header, 1, fp) == 1;
 }
 
+static bool open_trace_file(void)
+{
+    char *filename;
+
+    if (asprintf(&filename, CONFIG_TRACE_FILE, getpid()) < 0) {
+        return false;
+    }
+
+    trace_fp = fopen(filename, "w");
+    free(filename);
+    if (!trace_fp) {
+        return false;
+    }
+    return write_header(trace_fp);
+}
+
 static void flush_trace_buffer(void)
 {
     if (!trace_fp) {
-        trace_fp = fopen("trace.log", "w");
-        if (trace_fp) {
-            write_header(trace_fp);
-        }
+        open_trace_file();
     }
     if (trace_fp) {
         size_t unused; /* for when fwrite(3) is declared warn_unused_result */
-- 
1.7.1

  parent reply	other threads:[~2010-09-06 15:15 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-09-06 15:13 [Qemu-devel] [PATCH v3 00/14] trace: Add static tracing to QEMU Stefan Hajnoczi
2010-09-06 15:13 ` [Qemu-devel] [PATCH 01/14] trace: Add trace-events file for declaring trace events Stefan Hajnoczi
2010-09-11 21:53   ` Andreas Färber
2010-09-12 17:16     ` Stefan Hajnoczi
2010-09-06 15:13 ` [Qemu-devel] [PATCH 02/14] trace: Add simple built-in tracing backend Stefan Hajnoczi
2010-09-06 15:14 ` [Qemu-devel] [PATCH 03/14] trace: Support for dynamically enabling/disabling trace events Stefan Hajnoczi
2010-09-06 15:14 ` [Qemu-devel] [PATCH 04/14] trace: Support disabled events in trace-events Stefan Hajnoczi
2010-09-06 15:14 ` Stefan Hajnoczi [this message]
2010-09-06 15:14 ` [Qemu-devel] [PATCH 06/14] trace: Add trace-file command to open/close/flush trace file Stefan Hajnoczi
2010-09-06 15:14 ` [Qemu-devel] [PATCH 07/14] trace: Add trace file name command-line option Stefan Hajnoczi
2010-09-06 15:14 ` [Qemu-devel] [PATCH 08/14] trace: Add LTTng Userspace Tracer backend Stefan Hajnoczi
2010-09-06 15:14 ` [Qemu-devel] [PATCH 09/14] trace: Add user documentation Stefan Hajnoczi
2010-09-06 15:14 ` [Qemu-devel] [PATCH 10/14] trace: Trace qemu_malloc() and qemu_vmalloc() Stefan Hajnoczi
2010-09-06 15:14 ` [Qemu-devel] [PATCH 11/14] trace: Trace virtio-blk, multiwrite, and paio_submit Stefan Hajnoczi
2010-09-06 15:14 ` [Qemu-devel] [PATCH 12/14] trace: Trace virtqueue operations Stefan Hajnoczi
2010-09-06 15:14 ` [Qemu-devel] [PATCH 13/14] trace: Trace port IO Stefan Hajnoczi
2010-09-06 15:14 ` [Qemu-devel] [PATCH 14/14] trace: Trace entry point of balloon request handler Stefan Hajnoczi
2010-09-06 16:51 ` [Qemu-devel] [PATCH v3 00/14] trace: Add static tracing to QEMU Daniel P. Berrange
2010-09-06 17:12   ` Anthony Liguori
2010-09-07  9:09     ` Stefan Hajnoczi
2010-09-09 10:06       ` Stefan Hajnoczi
  -- strict thread matches above, loose matches on Subject: below --
2010-08-30 13:27 [Qemu-devel] [PATCH 00/14 v2] " Stefan Hajnoczi
2010-08-30 13:27 ` [Qemu-devel] [PATCH 05/14] trace: Specify trace file name Stefan Hajnoczi

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=1283786051-29530-6-git-send-email-stefanha@linux.vnet.ibm.com \
    --to=stefanha@linux.vnet.ibm.com \
    --cc=aliguori@us.ibm.com \
    --cc=blauwirbel@gmail.com \
    --cc=mst@redhat.com \
    --cc=prerna@linux.vnet.ibm.com \
    --cc=qemu-devel@nongnu.org \
    /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.