yeahuh / rpms / qemu-kvm

Forked from rpms/qemu-kvm 2 years ago
Clone

Blame SOURCES/kvm-trace-add-pid-field-to-simpletrace-record.patch

958e1b
From af89b472e5fb4743a41cd7304ac831e777eadaa4 Mon Sep 17 00:00:00 2001
958e1b
From: Stefan Hajnoczi <stefanha@redhat.com>
958e1b
Date: Tue, 7 Oct 2014 14:06:51 +0200
958e1b
Subject: [PATCH 33/43] trace: add pid field to simpletrace record
958e1b
958e1b
Message-id: <1412690820-31016-3-git-send-email-stefanha@redhat.com>
958e1b
Patchwork-id: 61607
958e1b
O-Subject: [RHEL7.1 qemu-kvm PATCH 02/11] trace: add pid field to simpletrace record
958e1b
Bugzilla: 1088112
958e1b
RH-Acked-by: Laszlo Ersek <lersek@redhat.com>
958e1b
RH-Acked-by: Miroslav Rezanina <mrezanin@redhat.com>
958e1b
RH-Acked-by: Paolo Bonzini <pbonzini@redhat.com>
958e1b
958e1b
It is useful to know the QEMU process ID when working with traces from
958e1b
multiple VMs.  Although the trace filename may contain the pid, tools
958e1b
that aggregate traces or even trace globally need somewhere to record
958e1b
the pid.
958e1b
958e1b
There is a reserved field in the trace event header struct that we can
958e1b
use.
958e1b
958e1b
It is not necessary to bump the simpletrace file format version number
958e1b
because it has already been incremented for the QEMU 2.1 release cycle
958e1b
in commit "trace: [simple] Bump up log version number".
958e1b
958e1b
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
958e1b
(cherry picked from commit 26896cbf353e3017f76da8193074839b6e875250)
958e1b
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
958e1b
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
958e1b
958e1b
Conflicts:
958e1b
	trace/simple.c
958e1b
958e1b
Downstream still has a g_thread_init() call in trace/simple.c so there
958e1b
is a context conflict.  Easy to resolve.
958e1b
---
958e1b
 trace/simple.c | 8 ++++++--
958e1b
 1 file changed, 6 insertions(+), 2 deletions(-)
958e1b
958e1b
diff --git a/trace/simple.c b/trace/simple.c
958e1b
index 64e196a..479b7d2 100644
958e1b
--- a/trace/simple.c
958e1b
+++ b/trace/simple.c
958e1b
@@ -64,6 +64,7 @@ uint8_t trace_buf[TRACE_BUF_LEN];
958e1b
 static volatile gint trace_idx;
958e1b
 static unsigned int writeout_idx;
958e1b
 static volatile gint dropped_events;
958e1b
+static uint32_t trace_pid;
958e1b
 static FILE *trace_fp;
958e1b
 static char *trace_file_name;
958e1b
 
958e1b
@@ -72,7 +73,7 @@ typedef struct {
958e1b
     uint64_t event; /*   TraceEventID */
958e1b
     uint64_t timestamp_ns;
958e1b
     uint32_t length;   /*    in bytes */
958e1b
-    uint32_t reserved; /*    unused */
958e1b
+    uint32_t pid;
958e1b
     uint64_t arguments[];
958e1b
 } TraceRecord;
958e1b
 
958e1b
@@ -180,7 +181,7 @@ static gpointer writeout_thread(gpointer opaque)
958e1b
             dropped.rec.event = DROPPED_EVENT_ID,
958e1b
             dropped.rec.timestamp_ns = get_clock();
958e1b
             dropped.rec.length = sizeof(TraceRecord) + sizeof(uint64_t),
958e1b
-            dropped.rec.reserved = 0;
958e1b
+            dropped.rec.pid = trace_pid;
958e1b
             do {
958e1b
                 dropped_count = g_atomic_int_get(&dropped_events);
958e1b
             } while (!g_atomic_int_compare_and_exchange(&dropped_events,
958e1b
@@ -239,6 +240,7 @@ int trace_record_start(TraceBufferRecord *rec, TraceEventID event, size_t datasi
958e1b
     rec_off = write_to_buffer(rec_off, &event_u64, sizeof(event_u64));
958e1b
     rec_off = write_to_buffer(rec_off, &timestamp_ns, sizeof(timestamp_ns));
958e1b
     rec_off = write_to_buffer(rec_off, &rec_len, sizeof(rec_len));
958e1b
+    rec_off = write_to_buffer(rec_off, &trace_pid, sizeof(trace_pid));
958e1b
 
958e1b
     rec->tbuf_idx = idx;
958e1b
     rec->rec_off  = (idx + sizeof(TraceRecord)) % TRACE_BUF_LEN;
958e1b
@@ -413,6 +415,8 @@ bool trace_backend_init(const char *events, const char *file)
958e1b
 #endif
958e1b
     }
958e1b
 
958e1b
+    trace_pid = getpid();
958e1b
+
958e1b
 #if !GLIB_CHECK_VERSION(2, 31, 0)
958e1b
     trace_available_cond = g_cond_new();
958e1b
     trace_empty_cond = g_cond_new();
958e1b
-- 
958e1b
1.8.3.1
958e1b