aboutsummaryrefslogtreecommitdiffstats
path: root/kernel
diff options
context:
space:
mode:
authorSteven Rostedt <srostedt@redhat.com>2009-03-05 21:35:29 -0500
committerSteven Rostedt <srostedt@redhat.com>2009-03-05 21:46:44 -0500
commit770cb24345c0f6e0d47bd2b94aa6d67bea6f8b54 (patch)
treeec76651c686c02249c1455446801cf2b9d823879 /kernel
parent33b0c229e3abeae00493ed1d6f0b07191977a0a2 (diff)
tracing: add format files for ftrace default entries
Impact: allow user apps to read binary format of basic ftrace entries Currently, only defined raw events export their formats so a binary reader can parse them. There's no reason that the default ftrace entries can't export their formats. This patch adds a subsystem called "ftrace" in the events directory that includes the ftrace entries for basic ftrace recorded items. These only have three files in the events directory: type : printf available_types : printf format : format for the event entry For example: # cat /debug/tracing/events/ftrace/wakeup/format name: wakeup ID: 3 format: field:unsigned char type; offset:0; size:1; field:unsigned char flags; offset:1; size:1; field:unsigned char preempt_count; offset:2; size:1; field:int pid; offset:4; size:4; field:int tgid; offset:8; size:4; field:unsigned int prev_pid; offset:12; size:4; field:unsigned char prev_prio; offset:16; size:1; field:unsigned char prev_state; offset:17; size:1; field:unsigned int next_pid; offset:20; size:4; field:unsigned char next_prio; offset:24; size:1; field:unsigned char next_state; offset:25; size:1; field:unsigned int next_cpu; offset:28; size:4; print fmt: "%u:%u:%u ==+ %u:%u:%u [%03u]" Signed-off-by: Steven Rostedt <srostedt@redhat.com>
Diffstat (limited to 'kernel')
-rw-r--r--kernel/trace/Makefile1
-rw-r--r--kernel/trace/trace_event_types.h165
-rw-r--r--kernel/trace/trace_events.c12
-rw-r--r--kernel/trace/trace_export.c81
-rw-r--r--kernel/trace/trace_format.h2
5 files changed, 255 insertions, 6 deletions
diff --git a/kernel/trace/Makefile b/kernel/trace/Makefile
index c931fe0560cb..f44736c7574a 100644
--- a/kernel/trace/Makefile
+++ b/kernel/trace/Makefile
@@ -41,5 +41,6 @@ obj-$(CONFIG_WORKQUEUE_TRACER) += trace_workqueue.o
41obj-$(CONFIG_BLK_DEV_IO_TRACE) += blktrace.o 41obj-$(CONFIG_BLK_DEV_IO_TRACE) += blktrace.o
42obj-$(CONFIG_EVENT_TRACER) += trace_events.o 42obj-$(CONFIG_EVENT_TRACER) += trace_events.o
43obj-$(CONFIG_EVENT_TRACER) += events.o 43obj-$(CONFIG_EVENT_TRACER) += events.o
44obj-$(CONFIG_EVENT_TRACER) += trace_export.o
44 45
45libftrace-y := ftrace.o 46libftrace-y := ftrace.o
diff --git a/kernel/trace/trace_event_types.h b/kernel/trace/trace_event_types.h
new file mode 100644
index 000000000000..fb4eba166433
--- /dev/null
+++ b/kernel/trace/trace_event_types.h
@@ -0,0 +1,165 @@
1#undef TRACE_SYSTEM
2#define TRACE_SYSTEM ftrace
3
4/*
5 * We cheat and use the proto type field as the ID
6 * and args as the entry type (minus 'struct')
7 */
8TRACE_EVENT_FORMAT(function, TRACE_FN, ftrace_entry, ignore,
9 TRACE_STRUCT(
10 TRACE_FIELD(unsigned long, ip, ip)
11 TRACE_FIELD(unsigned long, parent_ip, parent_ip)
12 ),
13 TPRAWFMT(" %lx <-- %lx")
14);
15
16TRACE_EVENT_FORMAT(funcgraph_entry, TRACE_GRAPH_ENT,
17 ftrace_graph_ent_entry, ignore,
18 TRACE_STRUCT(
19 TRACE_FIELD(unsigned long, graph_ent.func, func)
20 TRACE_FIELD(int, graph_ent.depth, depth)
21 ),
22 TPRAWFMT("--> %lx (%d)")
23);
24
25TRACE_EVENT_FORMAT(funcgraph_exit, TRACE_GRAPH_RET,
26 ftrace_graph_ret_entry, ignore,
27 TRACE_STRUCT(
28 TRACE_FIELD(unsigned long, ret.func, func)
29 TRACE_FIELD(int, ret.depth, depth)
30 ),
31 TPRAWFMT("<-- %lx (%d)")
32);
33
34TRACE_EVENT_FORMAT(wakeup, TRACE_WAKE, ctx_switch_entry, ignore,
35 TRACE_STRUCT(
36 TRACE_FIELD(unsigned int, prev_pid, prev_pid)
37 TRACE_FIELD(unsigned char, prev_prio, prev_prio)
38 TRACE_FIELD(unsigned char, prev_state, prev_state)
39 TRACE_FIELD(unsigned int, next_pid, next_pid)
40 TRACE_FIELD(unsigned char, next_prio, next_prio)
41 TRACE_FIELD(unsigned char, next_state, next_state)
42 TRACE_FIELD(unsigned int, next_cpu, next_cpu)
43 ),
44 TPRAWFMT("%u:%u:%u ==+ %u:%u:%u [%03u]")
45);
46
47TRACE_EVENT_FORMAT(context_switch, TRACE_CTX, ctx_switch_entry, ignore,
48 TRACE_STRUCT(
49 TRACE_FIELD(unsigned int, prev_pid, prev_pid)
50 TRACE_FIELD(unsigned char, prev_prio, prev_prio)
51 TRACE_FIELD(unsigned char, prev_state, prev_state)
52 TRACE_FIELD(unsigned int, next_pid, next_pid)
53 TRACE_FIELD(unsigned char, next_prio, next_prio)
54 TRACE_FIELD(unsigned char, next_state, next_state)
55 TRACE_FIELD(unsigned int, next_cpu, next_cpu)
56 ),
57 TPRAWFMT("%u:%u:%u ==+ %u:%u:%u [%03u]")
58);
59
60TRACE_EVENT_FORMAT(special, TRACE_SPECIAL, special_entry, ignore,
61 TRACE_STRUCT(
62 TRACE_FIELD(unsigned long, arg1, arg1)
63 TRACE_FIELD(unsigned long, arg2, arg2)
64 TRACE_FIELD(unsigned long, arg3, arg3)
65 ),
66 TPRAWFMT("(%08lx) (%08lx) (%08lx)")
67);
68
69/*
70 * Stack-trace entry:
71 */
72
73/* #define FTRACE_STACK_ENTRIES 8 */
74
75TRACE_EVENT_FORMAT(kernel_stack, TRACE_STACK, stack_entry, ignore,
76 TRACE_STRUCT(
77 TRACE_FIELD(unsigned long, caller[0], stack0)
78 TRACE_FIELD(unsigned long, caller[1], stack1)
79 TRACE_FIELD(unsigned long, caller[2], stack2)
80 TRACE_FIELD(unsigned long, caller[3], stack3)
81 TRACE_FIELD(unsigned long, caller[4], stack4)
82 TRACE_FIELD(unsigned long, caller[5], stack5)
83 TRACE_FIELD(unsigned long, caller[6], stack6)
84 TRACE_FIELD(unsigned long, caller[7], stack7)
85 ),
86 TPRAWFMT("\t=> (%08lx)\n\t=> (%08lx)\n\t=> (%08lx)\n\t=> (%08lx)\n"
87 "\t=> (%08lx)\n\t=> (%08lx)\n\t=> (%08lx)\n\t=> (%08lx)\n")
88);
89
90TRACE_EVENT_FORMAT(user_stack, TRACE_USER_STACK, userstack_entry, ignore,
91 TRACE_STRUCT(
92 TRACE_FIELD(unsigned long, caller[0], stack0)
93 TRACE_FIELD(unsigned long, caller[1], stack1)
94 TRACE_FIELD(unsigned long, caller[2], stack2)
95 TRACE_FIELD(unsigned long, caller[3], stack3)
96 TRACE_FIELD(unsigned long, caller[4], stack4)
97 TRACE_FIELD(unsigned long, caller[5], stack5)
98 TRACE_FIELD(unsigned long, caller[6], stack6)
99 TRACE_FIELD(unsigned long, caller[7], stack7)
100 ),
101 TPRAWFMT("\t=> (%08lx)\n\t=> (%08lx)\n\t=> (%08lx)\n\t=> (%08lx)\n"
102 "\t=> (%08lx)\n\t=> (%08lx)\n\t=> (%08lx)\n\t=> (%08lx)\n")
103);
104
105TRACE_EVENT_FORMAT(print, TRACE_PRINT, print_entry, ignore,
106 TRACE_STRUCT(
107 TRACE_FIELD(unsigned long, ip, ip)
108 TRACE_FIELD(unsigned int, depth, depth)
109 TRACE_FIELD_ZERO_CHAR(buf)
110 ),
111 TPRAWFMT("%08lx (%d) %s")
112);
113
114TRACE_EVENT_FORMAT(branch, TRACE_BRANCH, trace_branch, ignore,
115 TRACE_STRUCT(
116 TRACE_FIELD(unsigned int, line, line)
117 TRACE_FIELD_SPECIAL(char func[TRACE_FUNC_SIZE+1], func, func)
118 TRACE_FIELD_SPECIAL(char file[TRACE_FUNC_SIZE+1], file, file)
119 TRACE_FIELD(char, correct, correct)
120 ),
121 TPRAWFMT("%u:%s:%s (%u)")
122);
123
124TRACE_EVENT_FORMAT(hw_branch, TRACE_HW_BRANCHES, hw_branch_entry, ignore,
125 TRACE_STRUCT(
126 TRACE_FIELD(u64, from, from)
127 TRACE_FIELD(u64, to, to)
128 ),
129 TPRAWFMT("from: %llx to: %llx")
130);
131
132TRACE_EVENT_FORMAT(power, TRACE_POWER, trace_power, ignore,
133 TRACE_STRUCT(
134 TRACE_FIELD(ktime_t, state_data.stamp, stamp)
135 TRACE_FIELD(ktime_t, state_data.end, end)
136 TRACE_FIELD(int, state_data.type, type)
137 TRACE_FIELD(int, state_data.state, state)
138 ),
139 TPRAWFMT("%llx->%llx type:%u state:%u")
140);
141
142TRACE_EVENT_FORMAT(kmem_alloc, TRACE_KMEM_ALLOC, kmemtrace_alloc_entry, ignore,
143 TRACE_STRUCT(
144 TRACE_FIELD(enum kmemtrace_type_id, type_id, type_id)
145 TRACE_FIELD(unsigned long, call_site, call_site)
146 TRACE_FIELD(const void *, ptr, ptr)
147 TRACE_FIELD(size_t, bytes_req, bytes_req)
148 TRACE_FIELD(size_t, bytes_alloc, bytes_alloc)
149 TRACE_FIELD(gfp_t, gfp_flags, gfp_flags)
150 TRACE_FIELD(int, node, node)
151 ),
152 TPRAWFMT("type:%u call_site:%lx ptr:%p req:%lu alloc:%lu"
153 " flags:%x node:%d")
154);
155
156TRACE_EVENT_FORMAT(kmem_free, TRACE_KMEM_FREE, kmemtrace_free_entry, ignore,
157 TRACE_STRUCT(
158 TRACE_FIELD(enum kmemtrace_type_id, type_id, type_id)
159 TRACE_FIELD(unsigned long, call_site, call_site)
160 TRACE_FIELD(const void *, ptr, ptr)
161 ),
162 TPRAWFMT("type:%u call_site:%lx ptr:%p")
163);
164
165#undef TRACE_SYSTEM
diff --git a/kernel/trace/trace_events.c b/kernel/trace/trace_events.c
index 210e71ff82db..4488d90e75ef 100644
--- a/kernel/trace/trace_events.c
+++ b/kernel/trace/trace_events.c
@@ -656,11 +656,13 @@ event_create_dir(struct ftrace_event_call *call, struct dentry *d_events)
656 return -1; 656 return -1;
657 } 657 }
658 658
659 entry = debugfs_create_file("enable", 0644, call->dir, call, 659 if (call->regfunc) {
660 &ftrace_enable_fops); 660 entry = debugfs_create_file("enable", 0644, call->dir, call,
661 if (!entry) 661 &ftrace_enable_fops);
662 pr_warning("Could not create debugfs " 662 if (!entry)
663 "'%s/enable' entry\n", call->name); 663 pr_warning("Could not create debugfs "
664 "'%s/enable' entry\n", call->name);
665 }
664 666
665 /* Only let type be writable, if we can change it */ 667 /* Only let type be writable, if we can change it */
666 entry = debugfs_create_file("type", 668 entry = debugfs_create_file("type",
diff --git a/kernel/trace/trace_export.c b/kernel/trace/trace_export.c
new file mode 100644
index 000000000000..0fb7be73e31c
--- /dev/null
+++ b/kernel/trace/trace_export.c
@@ -0,0 +1,81 @@
1/*
2 * trace_export.c - export basic ftrace utilities to user space
3 *
4 * Copyright (C) 2009 Steven Rostedt <srostedt@redhat.com>
5 */
6#include <linux/stringify.h>
7#include <linux/kallsyms.h>
8#include <linux/seq_file.h>
9#include <linux/debugfs.h>
10#include <linux/uaccess.h>
11#include <linux/ftrace.h>
12#include <linux/module.h>
13#include <linux/init.h>
14#include <linux/fs.h>
15
16#include "trace_output.h"
17
18#include "trace_format.h"
19
20#undef TRACE_FIELD_ZERO_CHAR
21#define TRACE_FIELD_ZERO_CHAR(item) \
22 ret = trace_seq_printf(s, "\tfield: char " #item ";\t" \
23 "offset:%lu;\tsize:0;\n", \
24 offsetof(typeof(field), item)); \
25 if (!ret) \
26 return 0;
27
28
29#undef TPRAWFMT
30#define TPRAWFMT(args...) args
31
32#undef TRACE_EVENT_FORMAT
33#define TRACE_EVENT_FORMAT(call, proto, args, fmt, tstruct, tpfmt) \
34static int \
35ftrace_format_##call(struct trace_seq *s) \
36{ \
37 struct args field; \
38 int ret; \
39 \
40 tstruct; \
41 \
42 trace_seq_printf(s, "\nprint fmt: \"%s\"\n", tpfmt); \
43 \
44 return ret; \
45}
46
47#include "trace_event_types.h"
48
49#undef TRACE_ZERO_CHAR
50#define TRACE_ZERO_CHAR(arg)
51
52#undef TRACE_FIELD
53#define TRACE_FIELD(type, item, assign)\
54 entry->item = assign;
55
56#undef TRACE_FIELD
57#define TRACE_FIELD(type, item, assign)\
58 entry->item = assign;
59
60#undef TPCMD
61#define TPCMD(cmd...) cmd
62
63#undef TRACE_ENTRY
64#define TRACE_ENTRY entry
65
66#undef TRACE_FIELD_SPECIAL
67#define TRACE_FIELD_SPECIAL(type_item, item, cmd) \
68 cmd;
69
70#undef TRACE_EVENT_FORMAT
71#define TRACE_EVENT_FORMAT(call, proto, args, fmt, tstruct, tpfmt) \
72 \
73static struct ftrace_event_call __used \
74__attribute__((__aligned__(4))) \
75__attribute__((section("_ftrace_events"))) event_##call = { \
76 .name = #call, \
77 .id = proto, \
78 .system = __stringify(TRACE_SYSTEM), \
79 .show_format = ftrace_format_##call, \
80}
81#include "trace_event_types.h"
diff --git a/kernel/trace/trace_format.h b/kernel/trace/trace_format.h
index 53a6b1357116..03f9a4c165ca 100644
--- a/kernel/trace/trace_format.h
+++ b/kernel/trace/trace_format.h
@@ -40,7 +40,7 @@
40 40
41#undef TRACE_EVENT_FORMAT 41#undef TRACE_EVENT_FORMAT
42#define TRACE_EVENT_FORMAT(call, proto, args, fmt, tstruct, tpfmt) \ 42#define TRACE_EVENT_FORMAT(call, proto, args, fmt, tstruct, tpfmt) \
43int \ 43static int \
44ftrace_format_##call(struct trace_seq *s) \ 44ftrace_format_##call(struct trace_seq *s) \
45{ \ 45{ \
46 struct ftrace_raw_##call field; \ 46 struct ftrace_raw_##call field; \