tracing: add TRACE_FIELD_SPECIAL to record complex entries
authorSteven Rostedt <srostedt@redhat.com>
Mon, 2 Mar 2009 15:53:15 +0000 (10:53 -0500)
committerSteven Rostedt <srostedt@redhat.com>
Mon, 2 Mar 2009 15:53:15 +0000 (10:53 -0500)
Tom Zanussi pointed out that the simple TRACE_FIELD was not enough to
record trace data that required memcpy. This patch addresses this issue
by adding a TRACE_FIELD_SPECIAL. The format is similar to TRACE_FIELD
but looks like so:

  TRACE_FIELD_SPECIAL(type_item, item, cmd)

What TRACE_FIELD gave was:

  TRACE_FIELD(type, item, assign)

The TRACE_FIELD would be used in declaring a structure:

  struct {
type item;
  };

And later assign it via:

  entry->item = assign;

What TRACE_FIELD_SPECIAL gives us is:

In the declaration of the structure:

  struct {
type_item;
  };

And the assignment:

  cmd;

This change log will explain the one example used in the patch:

 TRACE_EVENT_FORMAT(sched_switch,
TPPROTO(struct rq *rq, struct task_struct *prev,
struct task_struct *next),
TPARGS(rq, prev, next),
TPFMT("task %s:%d ==> %s:%d",
      prev->comm, prev->pid, next->comm, next->pid),
TRACE_STRUCT(
TRACE_FIELD(pid_t, prev_pid, prev->pid)
TRACE_FIELD(int, prev_prio, prev->prio)
TRACE_FIELD_SPECIAL(char next_comm[TASK_COMM_LEN],
    next_comm,
    TPCMD(memcpy(TRACE_ENTRY->next_comm,
 next->comm,
 TASK_COMM_LEN)))
TRACE_FIELD(pid_t, next_pid, next->pid)
TRACE_FIELD(int, next_prio, next->prio)
),
TPRAWFMT("prev %d:%d ==> next %s:%d:%d")
);

 The struct will be create as:

  struct {
pid_t prev_pid;
int prev_prio;
char next_comm[TASK_COMM_LEN];
pid_t next_pid;
int next_prio;
  };

Note the TRACE_ENTRY in the cmd part of TRACE_SPECIAL. TRACE_ENTRY will
be set by the tracer to point to the structure inside the trace buffer.

  entry->prev_pid = prev->pid;
  entry->prev_prio = prev->prio;
  memcpy(entry->next_comm, next->comm, TASK_COMM_LEN);
  entry->next_pid = next->pid;
  entry->next_prio = next->prio

Reported-by: Tom Zanussi <tzanussi@gmail.com>
Signed-off-by: Steven Rostedt <srostedt@redhat.com>
include/trace/sched_event_types.h
kernel/trace/trace_events_stage_1.h
kernel/trace/trace_events_stage_2.h
kernel/trace/trace_events_stage_3.h

index ba059c10b58aac30735ccbfeeb706375ab179f40..a6de5c1601a0cbc62e83e0d61f8f185a321d9c48 100644 (file)
@@ -71,10 +71,15 @@ TRACE_EVENT_FORMAT(sched_switch,
        TRACE_STRUCT(
                TRACE_FIELD(pid_t, prev_pid, prev->pid)
                TRACE_FIELD(int, prev_prio, prev->prio)
+               TRACE_FIELD_SPECIAL(char next_comm[TASK_COMM_LEN],
+                                   next_comm,
+                                   TPCMD(memcpy(TRACE_ENTRY->next_comm,
+                                                next->comm,
+                                                TASK_COMM_LEN)))
                TRACE_FIELD(pid_t, next_pid, next->pid)
                TRACE_FIELD(int, next_prio, next->prio)
        ),
-       TPRAWFMT("prev %d:%d ==> next %d:%d")
+       TPRAWFMT("prev %d:%d ==> next %s:%d:%d")
        );
 
 TRACE_EVENT_FORMAT(sched_migrate_task,
index fd3bf9382d37307c3f8f7ae92b179b86ee7e0009..3830a731424c01a49a1edd01eb62b9fcb3a20c69 100644 (file)
@@ -30,5 +30,7 @@
 
 #define TRACE_FIELD(type, item, assign) \
        type item;
+#define TRACE_FIELD_SPECIAL(type_item, item, cmd) \
+       type_item;
 
 #include <trace/trace_event_types.h>
index 3eaaef5f19e1645252dd231a044ae7709ff7801c..dc79fe3a2ecb45fa3dedb2b620300f3c28da207f 100644 (file)
 #define TRACE_FIELD(type, item, assign) \
        field->item,
 
+#undef TRACE_FIELD_SPECIAL
+#define TRACE_FIELD_SPECIAL(type_item, item, cmd) \
+       field->item,
+
 
 #undef TPRAWFMT
 #define TPRAWFMT(args...)      args
index 7a161c49deb4755dfe1480b0606bb97076f6f48c..2ab65e958223f6de80dfb254415c9fcc14cde8eb 100644 (file)
@@ -147,6 +147,20 @@ __attribute__((section("_ftrace_events"))) event_##call = {                \
 #define TRACE_FIELD(type, item, assign)\
        entry->item = assign;
 
+#undef TRACE_FIELD
+#define TRACE_FIELD(type, item, assign)\
+       entry->item = assign;
+
+#undef TPCMD
+#define TPCMD(cmd...)  cmd
+
+#undef TRACE_ENTRY
+#define TRACE_ENTRY    entry
+
+#undef TRACE_FIELD_SPECIAL
+#define TRACE_FIELD_SPECIAL(type_item, item, cmd) \
+       cmd;
+
 #undef TRACE_EVENT_FORMAT
 #define TRACE_EVENT_FORMAT(call, proto, args, fmt, tstruct, tpfmt)     \
 _TRACE_FORMAT(call, PARAMS(proto), PARAMS(args), PARAMS(fmt))          \