[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH 10/14] trace: Specify trace file name
From: |
Stefan Hajnoczi |
Subject: |
[Qemu-devel] [PATCH 10/14] trace: Specify trace file name |
Date: |
Thu, 12 Aug 2010 11:36:31 +0100 |
From: Prerna Saxena <address@hidden>
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.
Edited-by: Stefan Hajnoczi <address@hidden>
Signed-off-by: Stefan Hajnoczi <address@hidden>
---
configure | 14 ++++++++++++++
simpletrace.c | 20 +++++++++++++++++---
2 files changed, 31 insertions(+), 3 deletions(-)
diff --git a/configure b/configure
index 830e49e..5c48a90 100755
--- a/configure
+++ b/configure
@@ -316,6 +316,7 @@ check_utests="no"
user_pie="no"
zero_malloc=""
trace_backend="nop"
+trace_file="/tmp/trace"
# OS specific
if check_define __linux__ ; then
@@ -473,6 +474,7 @@ if test "$mingw32" = "yes" ; then
bindir="\${prefix}"
sysconfdir="\${prefix}"
confsuffix=""
+ trace_file="trace"
fi
# find source path
@@ -520,6 +522,8 @@ for opt do
;;
--trace-backend=*) trace_backend="$optarg"
;;
+ --trace-file=*) trace_file="$optarg"
+ ;;
--enable-gprof) gprof="yes"
;;
--static)
@@ -899,6 +903,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"
+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
@@ -2204,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"
@@ -2469,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 311fa44..c3a4b73 100644
--- a/simpletrace.c
+++ b/simpletrace.c
@@ -53,12 +53,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("/tmp/trace.log", "w");
- if (trace_fp) {
- write_header(trace_fp);
+ if (open_trace_file()) {
atexit(flush_trace_buffer);
}
}
--
1.7.1
- [Qemu-devel] [PATCH 01/14] trace: Add trace-events file for declaring trace events, (continued)
- [Qemu-devel] [PATCH 10/14] trace: Specify trace file name,
Stefan Hajnoczi <=
- [Qemu-devel] [PATCH 05/14] trace: Trace port IO, Stefan Hajnoczi, 2010/08/12
- [Qemu-devel] [PATCH 09/14] trace: Support disabled events in trace-events, Stefan Hajnoczi, 2010/08/12
- [Qemu-devel] [PATCH 02/14] trace: Trace qemu_malloc() and qemu_vmalloc(), Stefan Hajnoczi, 2010/08/12
- Re: [Qemu-devel] [PATCH 00/14] trace: Add static tracing to QEMU, Blue Swirl, 2010/08/12
- Re: [Qemu-devel] [PATCH 00/14] trace: Add static tracing to QEMU, Anthony Liguori, 2010/08/22