Skip to contentSkip to conversation

simpletrace: Inline runtime state check

PATCH In review Jan Kiszka 2 participants 2 messages Oct 19, 2010

lore
Share & tools
lore

Jan Kiszka

author
#0 lore raw

PATCH 1/1 simpletrace: Inline runtime state check

Instead of preparing all traced args, jumping into the common trace function, even collecting a timestamp, do the check if a particular tracepoint is enabled inline. Also, mark the enabled case unlikely to motivate the compiler to push the trace code out of the fastpath.

---
 simpletrace.c |    4 ----
 tracetool     |    7 +++++--
 2 files changed, 5 insertions(+), 6 deletions(-)
simpletrace.c +0 -4
index deb1e07..224e4ab 100644
@@ -148,10 +148,6 @@ static void trace(TraceEventID event, uint64_t x1, uint64_t x2, uint64_t x3,
      */
     clock_gettime(CLOCK_MONOTONIC, &ts);
 
-    if (!trace_list[event].state) {
-        return;
-    }
-
     rec->event = event;
     rec->timestamp_ns = ts.tv_sec * 1000000000LL + ts.tv_nsec;
     rec->x1 = x1;
tracetool +5 -2
index 7010858..9532409 100755
@@ -146,6 +146,8 @@ linetoh_begin_simple()
 {
     cat <<EOF
 #include "simpletrace.h"
+
+extern TraceEvent trace_list[];
 EOF
 
     simple_event_num=0
@@ -179,7 +181,9 @@ linetoh_simple()
     cat <<EOF
 static inline void trace_$name($args)
 {
-    trace$argc($trace_args);
+    if (unlikely(trace_list[$simple_event_num].state)) {
+        trace$argc($trace_args);
+    }
 }
 EOF
 
@@ -190,7 +194,6 @@ linetoh_end_simple()
 {
     cat <<EOF
 #define NR_TRACE_EVENTS $simple_event_num
-extern TraceEvent trace_list[NR_TRACE_EVENTS];
 EOF
 }
 
Signature · 1 line
1.7.1
Acked-by on v1 1/1
#1 lore raw
Quoted 10 lines · Jan Kiszka

Instead of preparing all traced args, jumping into the common trace function, even collecting a timestamp, do the check if a particular tracepoint is enabled inline. Also, mark the enabled case unlikely to motivate the compiler to push the trace code out of the fastpath.

---
 simpletrace.c |    4 ----
 tracetool     |    7 +++++--
 2 files changed, 5 insertions(+), 6 deletions(-)