From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:33429) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WtztJ-0006cW-DX for qemu-devel@nongnu.org; Mon, 09 Jun 2014 09:45:44 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1WtztB-00042l-Tj for qemu-devel@nongnu.org; Mon, 09 Jun 2014 09:45:37 -0400 Received: from mx1.redhat.com ([209.132.183.28]:43648) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WtztB-00042a-I4 for qemu-devel@nongnu.org; Mon, 09 Jun 2014 09:45:29 -0400 From: Stefan Hajnoczi Date: Mon, 9 Jun 2014 15:45:09 +0200 Message-Id: <1402321522-18408-2-git-send-email-stefanha@redhat.com> In-Reply-To: <1402321522-18408-1-git-send-email-stefanha@redhat.com> References: <1402321522-18408-1-git-send-email-stefanha@redhat.com> Subject: [Qemu-devel] [PULL 1/5] trace: add pid field to simpletrace record List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: Peter Maydell , Stefan Hajnoczi It is useful to know the QEMU process ID when working with traces from multiple VMs. Although the trace filename may contain the pid, tools that aggregate traces or even trace globally need somewhere to record the pid. There is a reserved field in the trace event header struct that we can use. It is not necessary to bump the simpletrace file format version number because it has already been incremented for the QEMU 2.1 release cycle in commit "trace: [simple] Bump up log version number". Signed-off-by: Stefan Hajnoczi --- trace/simple.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/trace/simple.c b/trace/simple.c index bb0b52c..5a2e188 100644 --- a/trace/simple.c +++ b/trace/simple.c @@ -75,6 +75,7 @@ uint8_t trace_buf[TRACE_BUF_LEN]; static volatile gint trace_idx; static unsigned int writeout_idx; static volatile gint dropped_events; +static uint32_t trace_pid; static FILE *trace_fp; static char *trace_file_name; @@ -83,7 +84,7 @@ typedef struct { uint64_t event; /* TraceEventID */ uint64_t timestamp_ns; uint32_t length; /* in bytes */ - uint32_t reserved; /* unused */ + uint32_t pid; uint64_t arguments[]; } TraceRecord; @@ -190,7 +191,7 @@ static gpointer writeout_thread(gpointer opaque) dropped.rec.event = DROPPED_EVENT_ID, dropped.rec.timestamp_ns = get_clock(); dropped.rec.length = sizeof(TraceRecord) + sizeof(uint64_t), - dropped.rec.reserved = 0; + dropped.rec.pid = trace_pid; do { dropped_count = g_atomic_int_get(&dropped_events); } while (!g_atomic_int_compare_and_exchange(&dropped_events, @@ -249,6 +250,7 @@ int trace_record_start(TraceBufferRecord *rec, TraceEventID event, size_t datasi rec_off = write_to_buffer(rec_off, &event_u64, sizeof(event_u64)); rec_off = write_to_buffer(rec_off, ×tamp_ns, sizeof(timestamp_ns)); rec_off = write_to_buffer(rec_off, &rec_len, sizeof(rec_len)); + rec_off = write_to_buffer(rec_off, &trace_pid, sizeof(trace_pid)); rec->tbuf_idx = idx; rec->rec_off = (idx + sizeof(TraceRecord)) % TRACE_BUF_LEN; @@ -414,6 +416,8 @@ bool trace_backend_init(const char *events, const char *file) { GThread *thread; + trace_pid = getpid(); + #if !GLIB_CHECK_VERSION(2, 31, 0) trace_available_cond = g_cond_new(); trace_empty_cond = g_cond_new(); -- 1.9.3