From 9410b56c82a107ed48c1f40aa6820c03094d97e9 Mon Sep 17 00:00:00 2001 From: Prerna Saxena Date: Tue, 13 Jul 2010 09:26:32 +0100 Subject: trace: Specify trace file name Allow users to specify a file for trace-outputs at configuration. Also, allow trace files to be annotated by 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 Signed-off-by: Stefan Hajnoczi --- simpletrace.c | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) (limited to 'simpletrace.c') 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 */ -- cgit v1.1