Skip to contentSkip to conversation

Tracing patches

GIT PULL Applied Stefan Hajnoczi 2 participants 5 messages Sep 5, 2016 – Sep 6, 2016

lore
Share & tools
lore
#0 lore raw

The following changes since commit e87d397e5ef66276ccc49b829527d605ca07d0ad:

Open 2.8 development tree (2016-09-05 11:38:54 +0100)

are available in the git repository at:

git://github.com/stefanha/qemu.git tags/tracing-pull-request

for you to fetch changes up to 8eb1b9db559e243043aaeac3a0aa97e1f4a403c4:

trace: Avoid implicit bool->integer conversions (2016-09-05 13:47:02 -0400)

----------------------------------------------------------------

----------------------------------------------------------------

Lluís Vilanova (2):
trace: Remove 'trace_events_dstate_init'
trace: Avoid implicit bool->integer conversions

Paul Durrant (1):
trace: add syslog tracing backend

 configure                           | 19 ++++++++++++++++
 docs/tracing.txt                    | 12 ++++++++++
 scripts/tracetool/backend/syslog.py | 45 +++++++++++++++++++++++++++++++++++++
 stubs/trace-control.c               | 22 ++++++++++++++++--
 trace/control-target.c              | 34 ++++++++++++++++++++++++++--
 trace/control.c                     | 28 ++++++++++++++---------
 trace/control.h                     |  3 +++
 trace/event-internal.h              |  1 +
 8 files changed, 149 insertions(+), 15 deletions(-)
 create mode 100644 scripts/tracetool/backend/syslog.py
Signature · 1 line
2.7.4
#1 lore raw

[Qemu-devel] [PULL 1/3] trace: add syslog tracing backend

From: Paul Durrant <[email protected]>

This patch adds a tracing backend which sends output using syslog(). The syslog backend is limited to POSIX compliant systems.

openlog() is called with facility set to LOG_DAEMON, with the LOG_PID option. Trace events are logged at level LOG_INFO.

Message-id: [email protected]

---
 configure                           | 19 ++++++++++++++++
 docs/tracing.txt                    | 12 ++++++++++
 scripts/tracetool/backend/syslog.py | 45 +++++++++++++++++++++++++++++++++++++
 trace/control.c                     |  7 ++++++
 4 files changed, 83 insertions(+)
 create mode 100644 scripts/tracetool/backend/syslog.py
configure +19 -0
index 4b808f9..5a9bda1 100755
@@ -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
docs/tracing.txt +12 -0
index 29f2f9a..e62444c 100644
@@ -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>
scripts/tracetool/backend/syslog.py new file +45 -0

45 lines not on this page · raw message

trace/control.c +7 -0
index d173c09..b179cde 100644
@@ -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"
@@ -250,6 +253,10 @@ bool trace_init_backends(void)
     }
 #endif
 
+#ifdef CONFIG_TRACE_SYSLOG
+    openlog(NULL, LOG_PID, LOG_DAEMON);
+#endif
+
     return true;
 }
 
Signature · 1 line
2.7.4
#2 lore raw

[Qemu-devel] [PULL 2/3] trace: Remove 'trace_events_dstate_init'

In reply to Stefan Hajnoczi

From: Lluís Vilanova <[email protected]>

Removes the event state array used for early initialization. Since only events with the "vcpu" property need a late initialization fixup, threats their initialization specially.

Assumes that the user won't touch the state of "vcpu" events between early and late initialization (e.g., through QMP).

Message-id: [email protected]

---
 stubs/trace-control.c  |  5 +++++
 trace/control-target.c |  9 +++++++++
 trace/control.c        | 21 ++++++++++-----------
 trace/control.h        |  3 +++
 trace/event-internal.h |  1 +
 5 files changed, 28 insertions(+), 11 deletions(-)
stubs/trace-control.c +5 -0
index fe59836..3740c38 100644
@@ -11,6 +11,11 @@
 #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;
trace/control-target.c +9 -0
index 74c029a..4ee3733 100644
@@ -13,6 +13,15 @@
 #include "translate-all.h"
 
 
+void trace_event_set_state_dynamic_init(TraceEvent *ev, bool state)
+{
+    TraceEventID id = trace_event_get_id(ev);
+    assert(trace_event_get_state_static(ev));
+    /* Ignore "vcpu" property, since no vCPUs have been created yet */
+    trace_events_enabled_count += state - trace_events_dstate[id];
+    trace_events_dstate[id] = state;
+}
+
 void trace_event_set_state_dynamic(TraceEvent *ev, bool state)
 {
     CPUState *vcpu;
trace/control.c +10 -11
index b179cde..05d85ac 100644
@@ -34,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",
@@ -145,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 {
@@ -160,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);
         }
     }
 }
@@ -284,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);
         }
     }
trace/control.h +3 -0
index 0413b28..27a16fc 100644
@@ -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);
 
trace/event-internal.h +1 -0
index 5d8fa97..074faf6 100644
@@ -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 */
Signature · 1 line
2.7.4
#3 lore raw

[Qemu-devel] [PULL 3/3] trace: Avoid implicit bool->integer conversions

In reply to Stefan Hajnoczi

From: Lluís Vilanova <[email protected]>

An explicit if/else is clearer than arithmetic assuming #true is 1, while the compiler should be able to generate just as optimal code.

Message-id: [email protected]

---
 stubs/trace-control.c  | 17 +++++++++++++++--
 trace/control-target.c | 31 ++++++++++++++++++++++++++-----
 2 files changed, 41 insertions(+), 7 deletions(-)
stubs/trace-control.c +15 -2
index 3740c38..2dfcd9f 100644
@@ -19,10 +19,23 @@ void trace_event_set_state_dynamic_init(TraceEvent *ev, bool 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,
trace/control-target.c +26 -5
index 4ee3733..72081e2 100644
@@ -16,10 +16,22 @@
 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));
-    /* Ignore "vcpu" property, since no vCPUs have been created yet */
-    trace_events_enabled_count += state - trace_events_dstate[id];
-    trace_events_dstate[id] = state;
+    /*
+     * 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)
@@ -31,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;
+            }
+        }
     }
 }
 
Signature · 1 line
2.7.4
#4 lore raw
In reply to Stefan Hajnoczi
Quoted 14 lines · Stefan Hajnoczi

The following changes since commit e87d397e5ef66276ccc49b829527d605ca07d0ad:

Open 2.8 development tree (2016-09-05 11:38:54 +0100)

are available in the git repository at:

git://github.com/stefanha/qemu.git tags/tracing-pull-request

for you to fetch changes up to 8eb1b9db559e243043aaeac3a0aa97e1f4a403c4:

trace: Avoid implicit bool->integer conversions (2016-09-05 13:47:02 -0400)

----------------------------------------------------------------

Quoted 8 lines

----------------------------------------------------------------

Lluís Vilanova (2):
trace: Remove 'trace_events_dstate_init'
trace: Avoid implicit bool->integer conversions

Paul Durrant (1):
trace: add syslog tracing backend

Applied, thanks.

-- PMM