dcavalca / rpms / qemu

Forked from rpms/qemu a year ago
Clone

Blame 0107-trace-add-pid-field-to-simpletrace-record.patch

0410ae
From 32f3e4afa3c9e67c6448b2f3e3aefc4d7cf5a0d3 Mon Sep 17 00:00:00 2001
0410ae
From: Stefan Hajnoczi <stefanha@redhat.com>
0410ae
Date: Wed, 7 May 2014 19:24:10 +0200
0410ae
Subject: [PATCH] trace: add pid field to simpletrace record
0410ae
0410ae
It is useful to know the QEMU process ID when working with traces from
0410ae
multiple VMs.  Although the trace filename may contain the pid, tools
0410ae
that aggregate traces or even trace globally need somewhere to record
0410ae
the pid.
0410ae
0410ae
There is a reserved field in the trace event header struct that we can
0410ae
use.
0410ae
0410ae
It is not necessary to bump the simpletrace file format version number
0410ae
because it has already been incremented for the QEMU 2.1 release cycle
0410ae
in commit "trace: [simple] Bump up log version number".
0410ae
0410ae
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
0410ae
(cherry picked from commit 26896cbf353e3017f76da8193074839b6e875250)
0410ae
---
0410ae
 trace/simple.c | 8 ++++++--
0410ae
 1 file changed, 6 insertions(+), 2 deletions(-)
0410ae
0410ae
diff --git a/trace/simple.c b/trace/simple.c
0410ae
index aaa010e..1584bf7 100644
0410ae
--- a/trace/simple.c
0410ae
+++ b/trace/simple.c
0410ae
@@ -75,6 +75,7 @@ uint8_t trace_buf[TRACE_BUF_LEN];
0410ae
 static volatile gint trace_idx;
0410ae
 static unsigned int writeout_idx;
0410ae
 static volatile gint dropped_events;
0410ae
+static uint32_t trace_pid;
0410ae
 static FILE *trace_fp;
0410ae
 static char *trace_file_name;
0410ae
 
0410ae
@@ -83,7 +84,7 @@ typedef struct {
0410ae
     uint64_t event; /*   TraceEventID */
0410ae
     uint64_t timestamp_ns;
0410ae
     uint32_t length;   /*    in bytes */
0410ae
-    uint32_t reserved; /*    unused */
0410ae
+    uint32_t pid;
0410ae
     uint64_t arguments[];
0410ae
 } TraceRecord;
0410ae
 
0410ae
@@ -190,7 +191,7 @@ static gpointer writeout_thread(gpointer opaque)
0410ae
             dropped.rec.event = DROPPED_EVENT_ID,
0410ae
             dropped.rec.timestamp_ns = get_clock();
0410ae
             dropped.rec.length = sizeof(TraceRecord) + sizeof(uint64_t),
0410ae
-            dropped.rec.reserved = 0;
0410ae
+            dropped.rec.pid = trace_pid;
0410ae
             do {
0410ae
                 dropped_count = g_atomic_int_get(&dropped_events);
0410ae
             } while (!g_atomic_int_compare_and_exchange(&dropped_events,
0410ae
@@ -249,6 +250,7 @@ int trace_record_start(TraceBufferRecord *rec, TraceEventID event, size_t datasi
0410ae
     rec_off = write_to_buffer(rec_off, &event_u64, sizeof(event_u64));
0410ae
     rec_off = write_to_buffer(rec_off, &timestamp_ns, sizeof(timestamp_ns));
0410ae
     rec_off = write_to_buffer(rec_off, &rec_len, sizeof(rec_len));
0410ae
+    rec_off = write_to_buffer(rec_off, &trace_pid, sizeof(trace_pid));
0410ae
 
0410ae
     rec->tbuf_idx = idx;
0410ae
     rec->rec_off  = (idx + sizeof(TraceRecord)) % TRACE_BUF_LEN;
0410ae
@@ -414,6 +416,8 @@ bool trace_backend_init(const char *events, const char *file)
0410ae
 {
0410ae
     GThread *thread;
0410ae
 
0410ae
+    trace_pid = getpid();
0410ae
+
0410ae
 #if !GLIB_CHECK_VERSION(2, 31, 0)
0410ae
     trace_available_cond = g_cond_new();
0410ae
     trace_empty_cond = g_cond_new();