summary refs log tree commit diff stats
diff options
context:
space:
mode:
-rwxr-xr-xconfigure19
-rw-r--r--docs/tracing.txt12
-rw-r--r--hw/block/xen_disk.c18
-rw-r--r--scripts/tracetool/backend/syslog.py45
-rw-r--r--stubs/trace-control.c22
-rw-r--r--trace/control-target.c34
-rw-r--r--trace/control.c28
-rw-r--r--trace/control.h3
-rw-r--r--trace/event-internal.h1
9 files changed, 159 insertions, 23 deletions
diff --git a/configure b/configure
index 4b808f9d17..5a9bda18b5 100755
--- a/configure
+++ b/configure
@@ -4192,6 +4192,18 @@ if compile_prog "" "" ; then
 fi
 
 ##########################################
+# check if we have posix_syslog
+
+posix_syslog=no
+cat > $TMPC << EOF
+#include <syslog.h>
+int main(void) { openlog("qemu", LOG_PID, LOG_DAEMON); syslog(LOG_INFO, "configure"); return 0; }
+EOF
+if compile_prog "" "" ; then
+    posix_syslog=yes
+fi
+
+##########################################
 # check if trace backend exists
 
 $python "$source_path/scripts/tracetool.py" "--backends=$trace_backends" --check-backends  > /dev/null 2> /dev/null
@@ -5468,6 +5480,13 @@ if have_backend "ftrace"; then
     feature_not_found "ftrace(trace backend)" "ftrace requires Linux"
   fi
 fi
+if have_backend "syslog"; then
+  if test "$posix_syslog" = "yes" ; then
+    echo "CONFIG_TRACE_SYSLOG=y" >> $config_host_mak
+  else
+    feature_not_found "syslog(trace backend)" "syslog not available"
+  fi
+fi
 echo "CONFIG_TRACE_FILE=$trace_file" >> $config_host_mak
 
 if test "$rdma" = "yes" ; then
diff --git a/docs/tracing.txt b/docs/tracing.txt
index 29f2f9a24d..e62444ca68 100644
--- a/docs/tracing.txt
+++ b/docs/tracing.txt
@@ -192,6 +192,18 @@ After running qemu by root user, you can get the trace:
 
 Restriction: "ftrace" backend is restricted to Linux only.
 
+=== Syslog ===
+
+The "syslog" backend sends trace events using the POSIX syslog API. The log
+is opened specifying the LOG_DAEMON facility and LOG_PID option (so events
+are tagged with the pid of the particular QEMU process that generated
+them). All events are logged at LOG_INFO level.
+
+NOTE: syslog may squash duplicate consecutive trace events and apply rate
+      limiting.
+
+Restriction: "syslog" backend is restricted to POSIX compliant OS.
+
 ==== Monitor commands ====
 
 * trace-file on|off|flush|set <path>
diff --git a/hw/block/xen_disk.c b/hw/block/xen_disk.c
index 3b8ad33fc5..342868904d 100644
--- a/hw/block/xen_disk.c
+++ b/hw/block/xen_disk.c
@@ -976,14 +976,16 @@ static int blk_connect(struct XenDevice *xendev)
         blkdev->feature_persistent = !!pers;
     }
 
-    blkdev->protocol = BLKIF_PROTOCOL_NATIVE;
-    if (blkdev->xendev.protocol) {
-        if (strcmp(blkdev->xendev.protocol, XEN_IO_PROTO_ABI_X86_32) == 0) {
-            blkdev->protocol = BLKIF_PROTOCOL_X86_32;
-        }
-        if (strcmp(blkdev->xendev.protocol, XEN_IO_PROTO_ABI_X86_64) == 0) {
-            blkdev->protocol = BLKIF_PROTOCOL_X86_64;
-        }
+    if (!blkdev->xendev.protocol) {
+        blkdev->protocol = BLKIF_PROTOCOL_NATIVE;
+    } else if (strcmp(blkdev->xendev.protocol, XEN_IO_PROTO_ABI_NATIVE) == 0) {
+        blkdev->protocol = BLKIF_PROTOCOL_NATIVE;
+    } else if (strcmp(blkdev->xendev.protocol, XEN_IO_PROTO_ABI_X86_32) == 0) {
+        blkdev->protocol = BLKIF_PROTOCOL_X86_32;
+    } else if (strcmp(blkdev->xendev.protocol, XEN_IO_PROTO_ABI_X86_64) == 0) {
+        blkdev->protocol = BLKIF_PROTOCOL_X86_64;
+    } else {
+        blkdev->protocol = BLKIF_PROTOCOL_NATIVE;
     }
 
     blkdev->sring = xengnttab_map_grant_ref(blkdev->xendev.gnttabdev,
diff --git a/scripts/tracetool/backend/syslog.py b/scripts/tracetool/backend/syslog.py
new file mode 100644
index 0000000000..89019bc759
--- /dev/null
+++ b/scripts/tracetool/backend/syslog.py
@@ -0,0 +1,45 @@
+#!/usr/bin/env python
+# -*- coding: utf-8 -*-
+
+"""
+Syslog built-in backend.
+"""
+
+__author__     = "Paul Durrant <paul.durrant@citrix.com>"
+__copyright__  = "Copyright 2016, Citrix Systems Inc."
+__license__    = "GPL version 2 or (at your option) any later version"
+
+__maintainer__ = "Stefan Hajnoczi"
+__email__      = "stefanha@redhat.com"
+
+
+from tracetool import out
+
+
+PUBLIC = True
+
+
+def generate_h_begin(events):
+    out('#include <syslog.h>',
+        '#include "trace/control.h"',
+        '')
+
+
+def generate_h(event):
+    argnames = ", ".join(event.args.names())
+    if len(event.args) > 0:
+        argnames = ", " + argnames
+
+    if "vcpu" in event.properties:
+        # already checked on the generic format code
+        cond = "true"
+    else:
+        cond = "trace_event_get_state(%s)" % ("TRACE_" + event.name.upper())
+
+    out('        if (%(cond)s) {',
+        '            syslog(LOG_INFO, "%(name)s " %(fmt)s %(argnames)s);',
+        '        }',
+        cond=cond,
+        name=event.name,
+        fmt=event.fmt.rstrip("\n"),
+        argnames=argnames)
diff --git a/stubs/trace-control.c b/stubs/trace-control.c
index fe59836fce..2dfcd9fb2b 100644
--- a/stubs/trace-control.c
+++ b/stubs/trace-control.c
@@ -11,13 +11,31 @@
 #include "trace/control.h"
 
 
+void trace_event_set_state_dynamic_init(TraceEvent *ev, bool state)
+{
+    trace_event_set_state_dynamic(ev, state);
+}
+
 void trace_event_set_state_dynamic(TraceEvent *ev, bool state)
 {
     TraceEventID id;
+    bool state_pre;
     assert(trace_event_get_state_static(ev));
     id = trace_event_get_id(ev);
-    trace_events_enabled_count += state - trace_events_dstate[id];
-    trace_events_dstate[id] = state;
+    /*
+     * We ignore the "vcpu" property here, since there's no target code. Then
+     * dstate can only be 1 or 0.
+     */
+    state_pre = trace_events_dstate[id];
+    if (state_pre != state) {
+        if (state) {
+            trace_events_enabled_count++;
+            trace_events_dstate[id] = 1;
+        } else {
+            trace_events_enabled_count--;
+            trace_events_dstate[id] = 0;
+        }
+    }
 }
 
 void trace_event_set_vcpu_state_dynamic(CPUState *vcpu,
diff --git a/trace/control-target.c b/trace/control-target.c
index 74c029accc..72081e2a34 100644
--- a/trace/control-target.c
+++ b/trace/control-target.c
@@ -13,6 +13,27 @@
 #include "translate-all.h"
 
 
+void trace_event_set_state_dynamic_init(TraceEvent *ev, bool state)
+{
+    TraceEventID id = trace_event_get_id(ev);
+    bool state_pre;
+    assert(trace_event_get_state_static(ev));
+    /*
+     * We ignore the "vcpu" property here, since no vCPUs have been created
+     * yet. Then dstate can only be 1 or 0.
+     */
+    state_pre = trace_events_dstate[id];
+    if (state_pre != state) {
+        if (state) {
+            trace_events_enabled_count++;
+            trace_events_dstate[id] = 1;
+        } else {
+            trace_events_enabled_count--;
+            trace_events_dstate[id] = 0;
+        }
+    }
+}
+
 void trace_event_set_state_dynamic(TraceEvent *ev, bool state)
 {
     CPUState *vcpu;
@@ -22,9 +43,18 @@ void trace_event_set_state_dynamic(TraceEvent *ev, bool state)
             trace_event_set_vcpu_state_dynamic(vcpu, ev, state);
         }
     } else {
+        /* Without the "vcpu" property, dstate can only be 1 or 0 */
         TraceEventID id = trace_event_get_id(ev);
-        trace_events_enabled_count += state - trace_events_dstate[id];
-        trace_events_dstate[id] = state;
+        bool state_pre = trace_events_dstate[id];
+        if (state_pre != state) {
+            if (state) {
+                trace_events_enabled_count++;
+                trace_events_dstate[id] = 1;
+            } else {
+                trace_events_enabled_count--;
+                trace_events_dstate[id] = 0;
+            }
+        }
     }
 }
 
diff --git a/trace/control.c b/trace/control.c
index d173c09f44..05d85accbd 100644
--- a/trace/control.c
+++ b/trace/control.c
@@ -19,6 +19,9 @@
 #ifdef CONFIG_TRACE_LOG
 #include "qemu/log.h"
 #endif
+#ifdef CONFIG_TRACE_SYSLOG
+#include <syslog.h>
+#endif
 #include "qapi/error.h"
 #include "qemu/error-report.h"
 #include "qemu/config-file.h"
@@ -31,8 +34,6 @@ int trace_events_enabled_count;
  * - true : Integral counting the number of vCPUs that have this event enabled.
  */
 uint16_t trace_events_dstate[TRACE_EVENT_COUNT];
-/* Marks events for late vCPU state init */
-static bool trace_events_dstate_init[TRACE_EVENT_COUNT];
 
 QemuOptsList qemu_trace_opts = {
     .name = "trace",
@@ -142,10 +143,7 @@ static void do_trace_enable_events(const char *line_buf)
         TraceEvent *ev = NULL;
         while ((ev = trace_event_pattern(line_ptr, ev)) != NULL) {
             if (trace_event_get_state_static(ev)) {
-                /* start tracing */
-                trace_event_set_state_dynamic(ev, enable);
-                /* mark for late vCPU init */
-                trace_events_dstate_init[ev->id] = true;
+                trace_event_set_state_dynamic_init(ev, enable);
             }
         }
     } else {
@@ -157,10 +155,7 @@ static void do_trace_enable_events(const char *line_buf)
             error_report("WARNING: trace event '%s' is not traceable",
                          line_ptr);
         } else {
-            /* start tracing */
-            trace_event_set_state_dynamic(ev, enable);
-            /* mark for late vCPU init */
-            trace_events_dstate_init[ev->id] = true;
+            trace_event_set_state_dynamic_init(ev, enable);
         }
     }
 }
@@ -250,6 +245,10 @@ bool trace_init_backends(void)
     }
 #endif
 
+#ifdef CONFIG_TRACE_SYSLOG
+    openlog(NULL, LOG_PID, LOG_DAEMON);
+#endif
+
     return true;
 }
 
@@ -277,7 +276,14 @@ void trace_init_vcpu_events(void)
     while ((ev = trace_event_pattern("*", ev)) != NULL) {
         if (trace_event_is_vcpu(ev) &&
             trace_event_get_state_static(ev) &&
-            trace_events_dstate_init[ev->id]) {
+            trace_event_get_state_dynamic(ev)) {
+            TraceEventID id = trace_event_get_id(ev);
+            /* check preconditions */
+            assert(trace_events_dstate[id] == 1);
+            /* disable early-init state ... */
+            trace_events_dstate[id] = 0;
+            trace_events_enabled_count--;
+            /* ... and properly re-enable */
             trace_event_set_state_dynamic(ev, true);
         }
     }
diff --git a/trace/control.h b/trace/control.h
index 0413b28769..27a16fc955 100644
--- a/trace/control.h
+++ b/trace/control.h
@@ -274,6 +274,9 @@ char *trace_opt_parse(const char *optarg);
  *
  * Re-synchronize initial event state with vCPUs (which can be created after
  * trace_init_events()).
+ *
+ * Precondition: event states won't be changed between trace_enable_events() and
+ * trace_init_vcpu_events() (e.g., through QMP).
  */
 void trace_init_vcpu_events(void);
 
diff --git a/trace/event-internal.h b/trace/event-internal.h
index 5d8fa97ca5..074faf6862 100644
--- a/trace/event-internal.h
+++ b/trace/event-internal.h
@@ -29,5 +29,6 @@ typedef struct TraceEvent {
     const bool sstate;
 } TraceEvent;
 
+void trace_event_set_state_dynamic_init(TraceEvent *ev, bool state);
 
 #endif /* TRACE__EVENT_INTERNAL_H */