Commit | Line | Data |
---|---|---|
f0868d1e SR |
1 | /* |
2 | * trace_output.c | |
3 | * | |
4 | * Copyright (C) 2008 Red Hat Inc, Steven Rostedt <srostedt@redhat.com> | |
5 | * | |
6 | */ | |
7 | ||
8 | #include <linux/module.h> | |
9 | #include <linux/mutex.h> | |
10 | #include <linux/ftrace.h> | |
11 | ||
12 | #include "trace_output.h" | |
13 | ||
14 | /* must be a power of 2 */ | |
15 | #define EVENT_HASHSIZE 128 | |
16 | ||
52f6ad6d | 17 | DECLARE_RWSEM(trace_event_sem); |
be74b73a | 18 | |
f0868d1e SR |
19 | static struct hlist_head event_hash[EVENT_HASHSIZE] __read_mostly; |
20 | ||
21 | static int next_event_type = __TRACE_LAST_TYPE + 1; | |
22 | ||
09ae7234 SRRH |
23 | enum print_line_t trace_print_bputs_msg_only(struct trace_iterator *iter) |
24 | { | |
25 | struct trace_seq *s = &iter->seq; | |
26 | struct trace_entry *entry = iter->ent; | |
27 | struct bputs_entry *field; | |
09ae7234 SRRH |
28 | |
29 | trace_assign_type(field, entry); | |
30 | ||
19a7fe20 | 31 | trace_seq_puts(s, field->str); |
09ae7234 | 32 | |
19a7fe20 | 33 | return trace_handle_return(s); |
09ae7234 SRRH |
34 | } |
35 | ||
5ef841f6 SR |
36 | enum print_line_t trace_print_bprintk_msg_only(struct trace_iterator *iter) |
37 | { | |
38 | struct trace_seq *s = &iter->seq; | |
39 | struct trace_entry *entry = iter->ent; | |
40 | struct bprint_entry *field; | |
5ef841f6 SR |
41 | |
42 | trace_assign_type(field, entry); | |
43 | ||
19a7fe20 | 44 | trace_seq_bprintf(s, field->fmt, field->buf); |
5ef841f6 | 45 | |
19a7fe20 | 46 | return trace_handle_return(s); |
5ef841f6 SR |
47 | } |
48 | ||
49 | enum print_line_t trace_print_printk_msg_only(struct trace_iterator *iter) | |
50 | { | |
51 | struct trace_seq *s = &iter->seq; | |
52 | struct trace_entry *entry = iter->ent; | |
53 | struct print_entry *field; | |
5ef841f6 SR |
54 | |
55 | trace_assign_type(field, entry); | |
56 | ||
19a7fe20 | 57 | trace_seq_puts(s, field->buf); |
5ef841f6 | 58 | |
19a7fe20 | 59 | return trace_handle_return(s); |
5ef841f6 SR |
60 | } |
61 | ||
be74b73a SR |
62 | const char * |
63 | ftrace_print_flags_seq(struct trace_seq *p, const char *delim, | |
64 | unsigned long flags, | |
65 | const struct trace_print_flags *flag_array) | |
66 | { | |
67 | unsigned long mask; | |
68 | const char *str; | |
7b039cb4 | 69 | const char *ret = trace_seq_buffer_ptr(p); |
e404b321 | 70 | int i, first = 1; |
be74b73a | 71 | |
be74b73a SR |
72 | for (i = 0; flag_array[i].name && flags; i++) { |
73 | ||
74 | mask = flag_array[i].mask; | |
75 | if ((flags & mask) != mask) | |
76 | continue; | |
77 | ||
78 | str = flag_array[i].name; | |
79 | flags &= ~mask; | |
e404b321 | 80 | if (!first && delim) |
be74b73a | 81 | trace_seq_puts(p, delim); |
e404b321 AV |
82 | else |
83 | first = 0; | |
be74b73a SR |
84 | trace_seq_puts(p, str); |
85 | } | |
86 | ||
87 | /* check for left over flags */ | |
88 | if (flags) { | |
5b349261 | 89 | if (!first && delim) |
be74b73a SR |
90 | trace_seq_puts(p, delim); |
91 | trace_seq_printf(p, "0x%lx", flags); | |
92 | } | |
93 | ||
94 | trace_seq_putc(p, 0); | |
95 | ||
56d8bd3f | 96 | return ret; |
be74b73a | 97 | } |
ec081ddc | 98 | EXPORT_SYMBOL(ftrace_print_flags_seq); |
be74b73a | 99 | |
0f4fc29d SR |
100 | const char * |
101 | ftrace_print_symbols_seq(struct trace_seq *p, unsigned long val, | |
102 | const struct trace_print_flags *symbol_array) | |
103 | { | |
104 | int i; | |
7b039cb4 | 105 | const char *ret = trace_seq_buffer_ptr(p); |
0f4fc29d SR |
106 | |
107 | for (i = 0; symbol_array[i].name; i++) { | |
108 | ||
109 | if (val != symbol_array[i].mask) | |
110 | continue; | |
111 | ||
112 | trace_seq_puts(p, symbol_array[i].name); | |
113 | break; | |
114 | } | |
115 | ||
7b039cb4 | 116 | if (ret == (const char *)(trace_seq_buffer_ptr(p))) |
0f4fc29d SR |
117 | trace_seq_printf(p, "0x%lx", val); |
118 | ||
119 | trace_seq_putc(p, 0); | |
120 | ||
56d8bd3f | 121 | return ret; |
0f4fc29d | 122 | } |
ec081ddc | 123 | EXPORT_SYMBOL(ftrace_print_symbols_seq); |
0f4fc29d | 124 | |
2fc1b6f0 | 125 | #if BITS_PER_LONG == 32 |
126 | const char * | |
127 | ftrace_print_symbols_seq_u64(struct trace_seq *p, unsigned long long val, | |
128 | const struct trace_print_flags_u64 *symbol_array) | |
129 | { | |
130 | int i; | |
7b039cb4 | 131 | const char *ret = trace_seq_buffer_ptr(p); |
2fc1b6f0 | 132 | |
133 | for (i = 0; symbol_array[i].name; i++) { | |
134 | ||
135 | if (val != symbol_array[i].mask) | |
136 | continue; | |
137 | ||
138 | trace_seq_puts(p, symbol_array[i].name); | |
139 | break; | |
140 | } | |
141 | ||
7b039cb4 | 142 | if (ret == (const char *)(trace_seq_buffer_ptr(p))) |
2fc1b6f0 | 143 | trace_seq_printf(p, "0x%llx", val); |
144 | ||
145 | trace_seq_putc(p, 0); | |
146 | ||
147 | return ret; | |
148 | } | |
149 | EXPORT_SYMBOL(ftrace_print_symbols_seq_u64); | |
150 | #endif | |
151 | ||
4449bf92 SRRH |
152 | const char * |
153 | ftrace_print_bitmask_seq(struct trace_seq *p, void *bitmask_ptr, | |
154 | unsigned int bitmask_size) | |
155 | { | |
7b039cb4 | 156 | const char *ret = trace_seq_buffer_ptr(p); |
4449bf92 SRRH |
157 | |
158 | trace_seq_bitmask(p, bitmask_ptr, bitmask_size * 8); | |
159 | trace_seq_putc(p, 0); | |
160 | ||
161 | return ret; | |
162 | } | |
163 | EXPORT_SYMBOL_GPL(ftrace_print_bitmask_seq); | |
164 | ||
5a2e3995 KT |
165 | const char * |
166 | ftrace_print_hex_seq(struct trace_seq *p, const unsigned char *buf, int buf_len) | |
167 | { | |
168 | int i; | |
7b039cb4 | 169 | const char *ret = trace_seq_buffer_ptr(p); |
5a2e3995 KT |
170 | |
171 | for (i = 0; i < buf_len; i++) | |
172 | trace_seq_printf(p, "%s%2.2x", i == 0 ? "" : " ", buf[i]); | |
173 | ||
174 | trace_seq_putc(p, 0); | |
175 | ||
176 | return ret; | |
177 | } | |
178 | EXPORT_SYMBOL(ftrace_print_hex_seq); | |
179 | ||
f71130de LZ |
180 | int ftrace_raw_output_prep(struct trace_iterator *iter, |
181 | struct trace_event *trace_event) | |
182 | { | |
183 | struct ftrace_event_call *event; | |
184 | struct trace_seq *s = &iter->seq; | |
185 | struct trace_seq *p = &iter->tmp_seq; | |
186 | struct trace_entry *entry; | |
f71130de LZ |
187 | |
188 | event = container_of(trace_event, struct ftrace_event_call, event); | |
189 | entry = iter->ent; | |
190 | ||
191 | if (entry->type != event->event.type) { | |
192 | WARN_ON_ONCE(1); | |
193 | return TRACE_TYPE_UNHANDLED; | |
194 | } | |
195 | ||
196 | trace_seq_init(p); | |
19a7fe20 SRRH |
197 | trace_seq_printf(s, "%s: ", ftrace_event_name(event)); |
198 | ||
8e2e095c | 199 | return trace_handle_return(s); |
f71130de LZ |
200 | } |
201 | EXPORT_SYMBOL(ftrace_raw_output_prep); | |
202 | ||
1d6bae96 SR |
203 | static int ftrace_output_raw(struct trace_iterator *iter, char *name, |
204 | char *fmt, va_list ap) | |
205 | { | |
206 | struct trace_seq *s = &iter->seq; | |
1d6bae96 | 207 | |
19a7fe20 SRRH |
208 | trace_seq_printf(s, "%s: ", name); |
209 | trace_seq_vprintf(s, fmt, ap); | |
1d6bae96 | 210 | |
19a7fe20 | 211 | return trace_handle_return(s); |
1d6bae96 SR |
212 | } |
213 | ||
214 | int ftrace_output_call(struct trace_iterator *iter, char *name, char *fmt, ...) | |
215 | { | |
216 | va_list ap; | |
217 | int ret; | |
218 | ||
219 | va_start(ap, fmt); | |
220 | ret = ftrace_output_raw(iter, name, fmt, ap); | |
221 | va_end(ap); | |
222 | ||
223 | return ret; | |
224 | } | |
225 | EXPORT_SYMBOL_GPL(ftrace_output_call); | |
226 | ||
f0868d1e SR |
227 | #ifdef CONFIG_KRETPROBES |
228 | static inline const char *kretprobed(const char *name) | |
229 | { | |
230 | static const char tramp_name[] = "kretprobe_trampoline"; | |
231 | int size = sizeof(tramp_name); | |
232 | ||
233 | if (strncmp(tramp_name, name, size) == 0) | |
234 | return "[unknown/kretprobe'd]"; | |
235 | return name; | |
236 | } | |
237 | #else | |
238 | static inline const char *kretprobed(const char *name) | |
239 | { | |
240 | return name; | |
241 | } | |
242 | #endif /* CONFIG_KRETPROBES */ | |
243 | ||
19a7fe20 | 244 | static void |
f0868d1e SR |
245 | seq_print_sym_short(struct trace_seq *s, const char *fmt, unsigned long address) |
246 | { | |
247 | #ifdef CONFIG_KALLSYMS | |
248 | char str[KSYM_SYMBOL_LEN]; | |
249 | const char *name; | |
250 | ||
251 | kallsyms_lookup(address, NULL, NULL, NULL, str); | |
252 | ||
253 | name = kretprobed(str); | |
254 | ||
19a7fe20 | 255 | trace_seq_printf(s, fmt, name); |
f0868d1e | 256 | #endif |
f0868d1e SR |
257 | } |
258 | ||
19a7fe20 | 259 | static void |
f0868d1e SR |
260 | seq_print_sym_offset(struct trace_seq *s, const char *fmt, |
261 | unsigned long address) | |
262 | { | |
263 | #ifdef CONFIG_KALLSYMS | |
264 | char str[KSYM_SYMBOL_LEN]; | |
265 | const char *name; | |
266 | ||
267 | sprint_symbol(str, address); | |
268 | name = kretprobed(str); | |
269 | ||
19a7fe20 | 270 | trace_seq_printf(s, fmt, name); |
f0868d1e | 271 | #endif |
f0868d1e SR |
272 | } |
273 | ||
274 | #ifndef CONFIG_64BIT | |
275 | # define IP_FMT "%08lx" | |
276 | #else | |
277 | # define IP_FMT "%016lx" | |
278 | #endif | |
279 | ||
280 | int seq_print_user_ip(struct trace_seq *s, struct mm_struct *mm, | |
281 | unsigned long ip, unsigned long sym_flags) | |
282 | { | |
283 | struct file *file = NULL; | |
284 | unsigned long vmstart = 0; | |
285 | int ret = 1; | |
286 | ||
d184b31c JB |
287 | if (s->full) |
288 | return 0; | |
289 | ||
f0868d1e SR |
290 | if (mm) { |
291 | const struct vm_area_struct *vma; | |
292 | ||
293 | down_read(&mm->mmap_sem); | |
294 | vma = find_vma(mm, ip); | |
295 | if (vma) { | |
296 | file = vma->vm_file; | |
297 | vmstart = vma->vm_start; | |
298 | } | |
299 | if (file) { | |
300 | ret = trace_seq_path(s, &file->f_path); | |
301 | if (ret) | |
19a7fe20 SRRH |
302 | trace_seq_printf(s, "[+0x%lx]", |
303 | ip - vmstart); | |
f0868d1e SR |
304 | } |
305 | up_read(&mm->mmap_sem); | |
306 | } | |
307 | if (ret && ((sym_flags & TRACE_ITER_SYM_ADDR) || !file)) | |
19a7fe20 SRRH |
308 | trace_seq_printf(s, " <" IP_FMT ">", ip); |
309 | return !trace_seq_has_overflowed(s); | |
f0868d1e SR |
310 | } |
311 | ||
312 | int | |
313 | seq_print_userip_objs(const struct userstack_entry *entry, struct trace_seq *s, | |
314 | unsigned long sym_flags) | |
315 | { | |
316 | struct mm_struct *mm = NULL; | |
f0868d1e SR |
317 | unsigned int i; |
318 | ||
319 | if (trace_flags & TRACE_ITER_SYM_USEROBJ) { | |
320 | struct task_struct *task; | |
321 | /* | |
322 | * we do the lookup on the thread group leader, | |
323 | * since individual threads might have already quit! | |
324 | */ | |
325 | rcu_read_lock(); | |
48659d31 | 326 | task = find_task_by_vpid(entry->tgid); |
f0868d1e SR |
327 | if (task) |
328 | mm = get_task_mm(task); | |
329 | rcu_read_unlock(); | |
330 | } | |
331 | ||
332 | for (i = 0; i < FTRACE_STACK_ENTRIES; i++) { | |
333 | unsigned long ip = entry->caller[i]; | |
334 | ||
19a7fe20 | 335 | if (ip == ULONG_MAX || trace_seq_has_overflowed(s)) |
f0868d1e | 336 | break; |
19a7fe20 SRRH |
337 | |
338 | trace_seq_puts(s, " => "); | |
339 | ||
f0868d1e | 340 | if (!ip) { |
19a7fe20 SRRH |
341 | trace_seq_puts(s, "??"); |
342 | trace_seq_putc(s, '\n'); | |
f0868d1e SR |
343 | continue; |
344 | } | |
19a7fe20 SRRH |
345 | |
346 | seq_print_user_ip(s, mm, ip, sym_flags); | |
347 | trace_seq_putc(s, '\n'); | |
f0868d1e SR |
348 | } |
349 | ||
350 | if (mm) | |
351 | mmput(mm); | |
19a7fe20 SRRH |
352 | |
353 | return !trace_seq_has_overflowed(s); | |
f0868d1e SR |
354 | } |
355 | ||
356 | int | |
357 | seq_print_ip_sym(struct trace_seq *s, unsigned long ip, unsigned long sym_flags) | |
358 | { | |
19a7fe20 SRRH |
359 | if (!ip) { |
360 | trace_seq_putc(s, '0'); | |
361 | goto out; | |
362 | } | |
f0868d1e SR |
363 | |
364 | if (sym_flags & TRACE_ITER_SYM_OFFSET) | |
19a7fe20 | 365 | seq_print_sym_offset(s, "%s", ip); |
f0868d1e | 366 | else |
19a7fe20 | 367 | seq_print_sym_short(s, "%s", ip); |
f0868d1e SR |
368 | |
369 | if (sym_flags & TRACE_ITER_SYM_ADDR) | |
19a7fe20 SRRH |
370 | trace_seq_printf(s, " <" IP_FMT ">", ip); |
371 | ||
372 | out: | |
373 | return !trace_seq_has_overflowed(s); | |
f0868d1e SR |
374 | } |
375 | ||
f81c972d SR |
376 | /** |
377 | * trace_print_lat_fmt - print the irq, preempt and lockdep fields | |
378 | * @s: trace seq struct to write to | |
379 | * @entry: The trace entry field from the ring buffer | |
380 | * | |
381 | * Prints the generic fields of irqs off, in hard or softirq, preempt | |
e6e1e259 | 382 | * count. |
f81c972d SR |
383 | */ |
384 | int trace_print_lat_fmt(struct trace_seq *s, struct trace_entry *entry) | |
c4a8e8be | 385 | { |
10da37a6 DS |
386 | char hardsoft_irq; |
387 | char need_resched; | |
388 | char irqs_off; | |
389 | int hardirq; | |
390 | int softirq; | |
c4a8e8be | 391 | |
c4a8e8be FW |
392 | hardirq = entry->flags & TRACE_FLAG_HARDIRQ; |
393 | softirq = entry->flags & TRACE_FLAG_SOFTIRQ; | |
d9793bd8 | 394 | |
10da37a6 DS |
395 | irqs_off = |
396 | (entry->flags & TRACE_FLAG_IRQS_OFF) ? 'd' : | |
397 | (entry->flags & TRACE_FLAG_IRQS_NOSUPPORT) ? 'X' : | |
398 | '.'; | |
e5137b50 PZ |
399 | |
400 | switch (entry->flags & (TRACE_FLAG_NEED_RESCHED | | |
401 | TRACE_FLAG_PREEMPT_RESCHED)) { | |
402 | case TRACE_FLAG_NEED_RESCHED | TRACE_FLAG_PREEMPT_RESCHED: | |
403 | need_resched = 'N'; | |
404 | break; | |
405 | case TRACE_FLAG_NEED_RESCHED: | |
406 | need_resched = 'n'; | |
407 | break; | |
408 | case TRACE_FLAG_PREEMPT_RESCHED: | |
409 | need_resched = 'p'; | |
410 | break; | |
411 | default: | |
412 | need_resched = '.'; | |
413 | break; | |
414 | } | |
415 | ||
10da37a6 DS |
416 | hardsoft_irq = |
417 | (hardirq && softirq) ? 'H' : | |
418 | hardirq ? 'h' : | |
419 | softirq ? 's' : | |
420 | '.'; | |
421 | ||
19a7fe20 SRRH |
422 | trace_seq_printf(s, "%c%c%c", |
423 | irqs_off, need_resched, hardsoft_irq); | |
c4a8e8be | 424 | |
829b876d | 425 | if (entry->preempt_count) |
19a7fe20 | 426 | trace_seq_printf(s, "%x", entry->preempt_count); |
637e7e86 | 427 | else |
19a7fe20 | 428 | trace_seq_putc(s, '.'); |
829b876d | 429 | |
19a7fe20 | 430 | return !trace_seq_has_overflowed(s); |
c4a8e8be FW |
431 | } |
432 | ||
f81c972d SR |
433 | static int |
434 | lat_print_generic(struct trace_seq *s, struct trace_entry *entry, int cpu) | |
435 | { | |
436 | char comm[TASK_COMM_LEN]; | |
437 | ||
438 | trace_find_cmdline(entry->pid, comm); | |
439 | ||
19a7fe20 SRRH |
440 | trace_seq_printf(s, "%8.8s-%-5d %3d", |
441 | comm, entry->pid, cpu); | |
f81c972d SR |
442 | |
443 | return trace_print_lat_fmt(s, entry); | |
444 | } | |
445 | ||
8be0709f | 446 | static unsigned long preempt_mark_thresh_us = 100; |
c4a8e8be | 447 | |
d9793bd8 | 448 | static int |
8be0709f | 449 | lat_print_timestamp(struct trace_iterator *iter, u64 next_ts) |
c4a8e8be | 450 | { |
8be0709f DS |
451 | unsigned long verbose = trace_flags & TRACE_ITER_VERBOSE; |
452 | unsigned long in_ns = iter->iter_flags & TRACE_FILE_TIME_IN_NS; | |
12883efb | 453 | unsigned long long abs_ts = iter->ts - iter->trace_buffer->time_start; |
8be0709f DS |
454 | unsigned long long rel_ts = next_ts - iter->ts; |
455 | struct trace_seq *s = &iter->seq; | |
456 | ||
457 | if (in_ns) { | |
458 | abs_ts = ns2usecs(abs_ts); | |
459 | rel_ts = ns2usecs(rel_ts); | |
460 | } | |
461 | ||
462 | if (verbose && in_ns) { | |
463 | unsigned long abs_usec = do_div(abs_ts, USEC_PER_MSEC); | |
464 | unsigned long abs_msec = (unsigned long)abs_ts; | |
465 | unsigned long rel_usec = do_div(rel_ts, USEC_PER_MSEC); | |
466 | unsigned long rel_msec = (unsigned long)rel_ts; | |
467 | ||
19a7fe20 SRRH |
468 | trace_seq_printf( |
469 | s, "[%08llx] %ld.%03ldms (+%ld.%03ldms): ", | |
470 | ns2usecs(iter->ts), | |
471 | abs_msec, abs_usec, | |
472 | rel_msec, rel_usec); | |
473 | ||
8be0709f | 474 | } else if (verbose && !in_ns) { |
19a7fe20 SRRH |
475 | trace_seq_printf( |
476 | s, "[%016llx] %lld (+%lld): ", | |
477 | iter->ts, abs_ts, rel_ts); | |
478 | ||
8be0709f | 479 | } else if (!verbose && in_ns) { |
19a7fe20 SRRH |
480 | trace_seq_printf( |
481 | s, " %4lldus%c: ", | |
482 | abs_ts, | |
483 | rel_ts > preempt_mark_thresh_us ? '!' : | |
484 | rel_ts > 1 ? '+' : ' '); | |
485 | ||
8be0709f | 486 | } else { /* !verbose && !in_ns */ |
19a7fe20 | 487 | trace_seq_printf(s, " %4lld: ", abs_ts); |
8be0709f | 488 | } |
19a7fe20 SRRH |
489 | |
490 | return !trace_seq_has_overflowed(s); | |
c4a8e8be FW |
491 | } |
492 | ||
493 | int trace_print_context(struct trace_iterator *iter) | |
494 | { | |
495 | struct trace_seq *s = &iter->seq; | |
496 | struct trace_entry *entry = iter->ent; | |
8be0709f DS |
497 | unsigned long long t; |
498 | unsigned long secs, usec_rem; | |
4ca53085 SR |
499 | char comm[TASK_COMM_LEN]; |
500 | ||
501 | trace_find_cmdline(entry->pid, comm); | |
c4a8e8be | 502 | |
19a7fe20 | 503 | trace_seq_printf(s, "%16s-%-5d [%03d] ", |
77271ce4 | 504 | comm, entry->pid, iter->cpu); |
77271ce4 | 505 | |
19a7fe20 SRRH |
506 | if (trace_flags & TRACE_ITER_IRQ_INFO) |
507 | trace_print_lat_fmt(s, entry); | |
77271ce4 | 508 | |
8be0709f DS |
509 | if (iter->iter_flags & TRACE_FILE_TIME_IN_NS) { |
510 | t = ns2usecs(iter->ts); | |
511 | usec_rem = do_div(t, USEC_PER_SEC); | |
512 | secs = (unsigned long)t; | |
19a7fe20 | 513 | trace_seq_printf(s, " %5lu.%06lu: ", secs, usec_rem); |
8be0709f | 514 | } else |
19a7fe20 SRRH |
515 | trace_seq_printf(s, " %12llu: ", iter->ts); |
516 | ||
517 | return !trace_seq_has_overflowed(s); | |
c4a8e8be FW |
518 | } |
519 | ||
520 | int trace_print_lat_context(struct trace_iterator *iter) | |
521 | { | |
522 | u64 next_ts; | |
db4c75cb SR |
523 | /* trace_find_next_entry will reset ent_size */ |
524 | int ent_size = iter->ent_size; | |
c4a8e8be FW |
525 | struct trace_seq *s = &iter->seq; |
526 | struct trace_entry *entry = iter->ent, | |
527 | *next_entry = trace_find_next_entry(iter, NULL, | |
528 | &next_ts); | |
529 | unsigned long verbose = (trace_flags & TRACE_ITER_VERBOSE); | |
c4a8e8be | 530 | |
db4c75cb SR |
531 | /* Restore the original ent_size */ |
532 | iter->ent_size = ent_size; | |
533 | ||
c4a8e8be FW |
534 | if (!next_entry) |
535 | next_ts = iter->ts; | |
c4a8e8be FW |
536 | |
537 | if (verbose) { | |
4ca53085 SR |
538 | char comm[TASK_COMM_LEN]; |
539 | ||
540 | trace_find_cmdline(entry->pid, comm); | |
541 | ||
19a7fe20 SRRH |
542 | trace_seq_printf( |
543 | s, "%16s %5d %3d %d %08x %08lx ", | |
544 | comm, entry->pid, iter->cpu, entry->flags, | |
545 | entry->preempt_count, iter->idx); | |
c4a8e8be | 546 | } else { |
19a7fe20 | 547 | lat_print_generic(s, entry, iter->cpu); |
c4a8e8be FW |
548 | } |
549 | ||
19a7fe20 | 550 | lat_print_timestamp(iter, next_ts); |
8be0709f | 551 | |
19a7fe20 | 552 | return !trace_seq_has_overflowed(s); |
c4a8e8be FW |
553 | } |
554 | ||
f633cef0 SR |
555 | static const char state_to_char[] = TASK_STATE_TO_CHAR_STR; |
556 | ||
557 | static int task_state_char(unsigned long state) | |
558 | { | |
559 | int bit = state ? __ffs(state) + 1 : 0; | |
560 | ||
561 | return bit < sizeof(state_to_char) - 1 ? state_to_char[bit] : '?'; | |
562 | } | |
563 | ||
f0868d1e SR |
564 | /** |
565 | * ftrace_find_event - find a registered event | |
566 | * @type: the type of event to look for | |
567 | * | |
568 | * Returns an event of type @type otherwise NULL | |
4f535968 | 569 | * Called with trace_event_read_lock() held. |
f0868d1e SR |
570 | */ |
571 | struct trace_event *ftrace_find_event(int type) | |
572 | { | |
573 | struct trace_event *event; | |
f0868d1e SR |
574 | unsigned key; |
575 | ||
576 | key = type & (EVENT_HASHSIZE - 1); | |
577 | ||
b67bfe0d | 578 | hlist_for_each_entry(event, &event_hash[key], node) { |
f0868d1e SR |
579 | if (event->type == type) |
580 | return event; | |
581 | } | |
582 | ||
583 | return NULL; | |
584 | } | |
585 | ||
060fa5c8 SR |
586 | static LIST_HEAD(ftrace_event_list); |
587 | ||
588 | static int trace_search_list(struct list_head **list) | |
589 | { | |
590 | struct trace_event *e; | |
591 | int last = __TRACE_LAST_TYPE; | |
592 | ||
593 | if (list_empty(&ftrace_event_list)) { | |
594 | *list = &ftrace_event_list; | |
595 | return last + 1; | |
596 | } | |
597 | ||
598 | /* | |
599 | * We used up all possible max events, | |
600 | * lets see if somebody freed one. | |
601 | */ | |
602 | list_for_each_entry(e, &ftrace_event_list, list) { | |
603 | if (e->type != last + 1) | |
604 | break; | |
605 | last++; | |
606 | } | |
607 | ||
608 | /* Did we used up all 65 thousand events??? */ | |
609 | if ((last + 1) > FTRACE_MAX_EVENT) | |
610 | return 0; | |
611 | ||
612 | *list = &e->list; | |
613 | return last + 1; | |
614 | } | |
615 | ||
4f535968 LJ |
616 | void trace_event_read_lock(void) |
617 | { | |
52f6ad6d | 618 | down_read(&trace_event_sem); |
4f535968 LJ |
619 | } |
620 | ||
621 | void trace_event_read_unlock(void) | |
622 | { | |
52f6ad6d | 623 | up_read(&trace_event_sem); |
4f535968 LJ |
624 | } |
625 | ||
f0868d1e SR |
626 | /** |
627 | * register_ftrace_event - register output for an event type | |
628 | * @event: the event type to register | |
629 | * | |
630 | * Event types are stored in a hash and this hash is used to | |
631 | * find a way to print an event. If the @event->type is set | |
632 | * then it will use that type, otherwise it will assign a | |
633 | * type to use. | |
634 | * | |
635 | * If you assign your own type, please make sure it is added | |
636 | * to the trace_type enum in trace.h, to avoid collisions | |
637 | * with the dynamic types. | |
638 | * | |
639 | * Returns the event type number or zero on error. | |
640 | */ | |
641 | int register_ftrace_event(struct trace_event *event) | |
642 | { | |
643 | unsigned key; | |
644 | int ret = 0; | |
645 | ||
52f6ad6d | 646 | down_write(&trace_event_sem); |
f0868d1e | 647 | |
060fa5c8 | 648 | if (WARN_ON(!event)) |
28bea271 | 649 | goto out; |
28bea271 | 650 | |
a9a57763 SR |
651 | if (WARN_ON(!event->funcs)) |
652 | goto out; | |
653 | ||
060fa5c8 SR |
654 | INIT_LIST_HEAD(&event->list); |
655 | ||
656 | if (!event->type) { | |
48dd0fed | 657 | struct list_head *list = NULL; |
060fa5c8 SR |
658 | |
659 | if (next_event_type > FTRACE_MAX_EVENT) { | |
660 | ||
661 | event->type = trace_search_list(&list); | |
662 | if (!event->type) | |
663 | goto out; | |
664 | ||
665 | } else { | |
666 | ||
667 | event->type = next_event_type++; | |
668 | list = &ftrace_event_list; | |
669 | } | |
670 | ||
671 | if (WARN_ON(ftrace_find_event(event->type))) | |
672 | goto out; | |
673 | ||
674 | list_add_tail(&event->list, list); | |
675 | ||
676 | } else if (event->type > __TRACE_LAST_TYPE) { | |
f0868d1e SR |
677 | printk(KERN_WARNING "Need to add type to trace.h\n"); |
678 | WARN_ON(1); | |
f0868d1e | 679 | goto out; |
060fa5c8 SR |
680 | } else { |
681 | /* Is this event already used */ | |
682 | if (ftrace_find_event(event->type)) | |
683 | goto out; | |
684 | } | |
f0868d1e | 685 | |
a9a57763 SR |
686 | if (event->funcs->trace == NULL) |
687 | event->funcs->trace = trace_nop_print; | |
688 | if (event->funcs->raw == NULL) | |
689 | event->funcs->raw = trace_nop_print; | |
690 | if (event->funcs->hex == NULL) | |
691 | event->funcs->hex = trace_nop_print; | |
692 | if (event->funcs->binary == NULL) | |
693 | event->funcs->binary = trace_nop_print; | |
268ccda0 | 694 | |
f0868d1e SR |
695 | key = event->type & (EVENT_HASHSIZE - 1); |
696 | ||
4f535968 | 697 | hlist_add_head(&event->node, &event_hash[key]); |
f0868d1e SR |
698 | |
699 | ret = event->type; | |
700 | out: | |
52f6ad6d | 701 | up_write(&trace_event_sem); |
f0868d1e SR |
702 | |
703 | return ret; | |
704 | } | |
17c873ec | 705 | EXPORT_SYMBOL_GPL(register_ftrace_event); |
f0868d1e | 706 | |
110bf2b7 | 707 | /* |
52f6ad6d | 708 | * Used by module code with the trace_event_sem held for write. |
110bf2b7 SR |
709 | */ |
710 | int __unregister_ftrace_event(struct trace_event *event) | |
711 | { | |
712 | hlist_del(&event->node); | |
713 | list_del(&event->list); | |
714 | return 0; | |
715 | } | |
716 | ||
f0868d1e SR |
717 | /** |
718 | * unregister_ftrace_event - remove a no longer used event | |
719 | * @event: the event to remove | |
720 | */ | |
721 | int unregister_ftrace_event(struct trace_event *event) | |
722 | { | |
52f6ad6d | 723 | down_write(&trace_event_sem); |
110bf2b7 | 724 | __unregister_ftrace_event(event); |
52f6ad6d | 725 | up_write(&trace_event_sem); |
f0868d1e SR |
726 | |
727 | return 0; | |
728 | } | |
17c873ec | 729 | EXPORT_SYMBOL_GPL(unregister_ftrace_event); |
f633cef0 SR |
730 | |
731 | /* | |
732 | * Standard events | |
733 | */ | |
734 | ||
a9a57763 SR |
735 | enum print_line_t trace_nop_print(struct trace_iterator *iter, int flags, |
736 | struct trace_event *event) | |
f633cef0 | 737 | { |
19a7fe20 | 738 | trace_seq_printf(&iter->seq, "type: %d\n", iter->ent->type); |
ee5e51f5 | 739 | |
19a7fe20 | 740 | return trace_handle_return(&iter->seq); |
f633cef0 SR |
741 | } |
742 | ||
743 | /* TRACE_FN */ | |
a9a57763 SR |
744 | static enum print_line_t trace_fn_trace(struct trace_iterator *iter, int flags, |
745 | struct trace_event *event) | |
f633cef0 SR |
746 | { |
747 | struct ftrace_entry *field; | |
2c9b238e | 748 | struct trace_seq *s = &iter->seq; |
f633cef0 | 749 | |
2c9b238e | 750 | trace_assign_type(field, iter->ent); |
f633cef0 | 751 | |
19a7fe20 | 752 | seq_print_ip_sym(s, field->ip, flags); |
f633cef0 SR |
753 | |
754 | if ((flags & TRACE_ITER_PRINT_PARENT) && field->parent_ip) { | |
19a7fe20 SRRH |
755 | trace_seq_puts(s, " <-"); |
756 | seq_print_ip_sym(s, field->parent_ip, flags); | |
f633cef0 | 757 | } |
f633cef0 | 758 | |
19a7fe20 | 759 | trace_seq_putc(s, '\n'); |
f633cef0 | 760 | |
19a7fe20 | 761 | return trace_handle_return(s); |
f633cef0 SR |
762 | } |
763 | ||
a9a57763 SR |
764 | static enum print_line_t trace_fn_raw(struct trace_iterator *iter, int flags, |
765 | struct trace_event *event) | |
f633cef0 SR |
766 | { |
767 | struct ftrace_entry *field; | |
768 | ||
2c9b238e | 769 | trace_assign_type(field, iter->ent); |
f633cef0 | 770 | |
19a7fe20 SRRH |
771 | trace_seq_printf(&iter->seq, "%lx %lx\n", |
772 | field->ip, | |
773 | field->parent_ip); | |
f633cef0 | 774 | |
19a7fe20 | 775 | return trace_handle_return(&iter->seq); |
f633cef0 SR |
776 | } |
777 | ||
a9a57763 SR |
778 | static enum print_line_t trace_fn_hex(struct trace_iterator *iter, int flags, |
779 | struct trace_event *event) | |
f633cef0 SR |
780 | { |
781 | struct ftrace_entry *field; | |
2c9b238e | 782 | struct trace_seq *s = &iter->seq; |
f633cef0 | 783 | |
2c9b238e | 784 | trace_assign_type(field, iter->ent); |
f633cef0 | 785 | |
19a7fe20 SRRH |
786 | SEQ_PUT_HEX_FIELD(s, field->ip); |
787 | SEQ_PUT_HEX_FIELD(s, field->parent_ip); | |
f633cef0 | 788 | |
19a7fe20 | 789 | return trace_handle_return(s); |
f633cef0 SR |
790 | } |
791 | ||
a9a57763 SR |
792 | static enum print_line_t trace_fn_bin(struct trace_iterator *iter, int flags, |
793 | struct trace_event *event) | |
f633cef0 SR |
794 | { |
795 | struct ftrace_entry *field; | |
2c9b238e | 796 | struct trace_seq *s = &iter->seq; |
f633cef0 | 797 | |
2c9b238e | 798 | trace_assign_type(field, iter->ent); |
f633cef0 | 799 | |
19a7fe20 SRRH |
800 | SEQ_PUT_FIELD(s, field->ip); |
801 | SEQ_PUT_FIELD(s, field->parent_ip); | |
f633cef0 | 802 | |
19a7fe20 | 803 | return trace_handle_return(s); |
f633cef0 SR |
804 | } |
805 | ||
a9a57763 | 806 | static struct trace_event_functions trace_fn_funcs = { |
f633cef0 | 807 | .trace = trace_fn_trace, |
f633cef0 SR |
808 | .raw = trace_fn_raw, |
809 | .hex = trace_fn_hex, | |
810 | .binary = trace_fn_bin, | |
811 | }; | |
812 | ||
a9a57763 SR |
813 | static struct trace_event trace_fn_event = { |
814 | .type = TRACE_FN, | |
815 | .funcs = &trace_fn_funcs, | |
816 | }; | |
817 | ||
f633cef0 | 818 | /* TRACE_CTX an TRACE_WAKE */ |
ae7462b4 ACM |
819 | static enum print_line_t trace_ctxwake_print(struct trace_iterator *iter, |
820 | char *delim) | |
f633cef0 SR |
821 | { |
822 | struct ctx_switch_entry *field; | |
4ca53085 | 823 | char comm[TASK_COMM_LEN]; |
f633cef0 SR |
824 | int S, T; |
825 | ||
4ca53085 | 826 | |
2c9b238e | 827 | trace_assign_type(field, iter->ent); |
f633cef0 SR |
828 | |
829 | T = task_state_char(field->next_state); | |
830 | S = task_state_char(field->prev_state); | |
4ca53085 | 831 | trace_find_cmdline(field->next_pid, comm); |
19a7fe20 SRRH |
832 | trace_seq_printf(&iter->seq, |
833 | " %5d:%3d:%c %s [%03d] %5d:%3d:%c %s\n", | |
834 | field->prev_pid, | |
835 | field->prev_prio, | |
836 | S, delim, | |
837 | field->next_cpu, | |
838 | field->next_pid, | |
839 | field->next_prio, | |
840 | T, comm); | |
841 | ||
842 | return trace_handle_return(&iter->seq); | |
f633cef0 SR |
843 | } |
844 | ||
a9a57763 SR |
845 | static enum print_line_t trace_ctx_print(struct trace_iterator *iter, int flags, |
846 | struct trace_event *event) | |
f633cef0 | 847 | { |
2c9b238e | 848 | return trace_ctxwake_print(iter, "==>"); |
f633cef0 SR |
849 | } |
850 | ||
ae7462b4 | 851 | static enum print_line_t trace_wake_print(struct trace_iterator *iter, |
a9a57763 | 852 | int flags, struct trace_event *event) |
f633cef0 | 853 | { |
2c9b238e | 854 | return trace_ctxwake_print(iter, " +"); |
f633cef0 SR |
855 | } |
856 | ||
2c9b238e | 857 | static int trace_ctxwake_raw(struct trace_iterator *iter, char S) |
f633cef0 SR |
858 | { |
859 | struct ctx_switch_entry *field; | |
860 | int T; | |
861 | ||
2c9b238e | 862 | trace_assign_type(field, iter->ent); |
f633cef0 SR |
863 | |
864 | if (!S) | |
b0f56f1a | 865 | S = task_state_char(field->prev_state); |
f633cef0 | 866 | T = task_state_char(field->next_state); |
19a7fe20 SRRH |
867 | trace_seq_printf(&iter->seq, "%d %d %c %d %d %d %c\n", |
868 | field->prev_pid, | |
869 | field->prev_prio, | |
870 | S, | |
871 | field->next_cpu, | |
872 | field->next_pid, | |
873 | field->next_prio, | |
874 | T); | |
875 | ||
876 | return trace_handle_return(&iter->seq); | |
f633cef0 SR |
877 | } |
878 | ||
a9a57763 SR |
879 | static enum print_line_t trace_ctx_raw(struct trace_iterator *iter, int flags, |
880 | struct trace_event *event) | |
f633cef0 | 881 | { |
2c9b238e | 882 | return trace_ctxwake_raw(iter, 0); |
f633cef0 SR |
883 | } |
884 | ||
a9a57763 SR |
885 | static enum print_line_t trace_wake_raw(struct trace_iterator *iter, int flags, |
886 | struct trace_event *event) | |
f633cef0 | 887 | { |
2c9b238e | 888 | return trace_ctxwake_raw(iter, '+'); |
f633cef0 SR |
889 | } |
890 | ||
891 | ||
2c9b238e | 892 | static int trace_ctxwake_hex(struct trace_iterator *iter, char S) |
f633cef0 SR |
893 | { |
894 | struct ctx_switch_entry *field; | |
2c9b238e | 895 | struct trace_seq *s = &iter->seq; |
f633cef0 SR |
896 | int T; |
897 | ||
2c9b238e | 898 | trace_assign_type(field, iter->ent); |
f633cef0 SR |
899 | |
900 | if (!S) | |
b0f56f1a | 901 | S = task_state_char(field->prev_state); |
f633cef0 SR |
902 | T = task_state_char(field->next_state); |
903 | ||
19a7fe20 SRRH |
904 | SEQ_PUT_HEX_FIELD(s, field->prev_pid); |
905 | SEQ_PUT_HEX_FIELD(s, field->prev_prio); | |
906 | SEQ_PUT_HEX_FIELD(s, S); | |
907 | SEQ_PUT_HEX_FIELD(s, field->next_cpu); | |
908 | SEQ_PUT_HEX_FIELD(s, field->next_pid); | |
909 | SEQ_PUT_HEX_FIELD(s, field->next_prio); | |
910 | SEQ_PUT_HEX_FIELD(s, T); | |
f633cef0 | 911 | |
19a7fe20 | 912 | return trace_handle_return(s); |
f633cef0 SR |
913 | } |
914 | ||
a9a57763 SR |
915 | static enum print_line_t trace_ctx_hex(struct trace_iterator *iter, int flags, |
916 | struct trace_event *event) | |
f633cef0 | 917 | { |
2c9b238e | 918 | return trace_ctxwake_hex(iter, 0); |
f633cef0 SR |
919 | } |
920 | ||
a9a57763 SR |
921 | static enum print_line_t trace_wake_hex(struct trace_iterator *iter, int flags, |
922 | struct trace_event *event) | |
f633cef0 | 923 | { |
2c9b238e | 924 | return trace_ctxwake_hex(iter, '+'); |
f633cef0 SR |
925 | } |
926 | ||
ae7462b4 | 927 | static enum print_line_t trace_ctxwake_bin(struct trace_iterator *iter, |
a9a57763 | 928 | int flags, struct trace_event *event) |
f633cef0 SR |
929 | { |
930 | struct ctx_switch_entry *field; | |
2c9b238e | 931 | struct trace_seq *s = &iter->seq; |
f633cef0 | 932 | |
2c9b238e | 933 | trace_assign_type(field, iter->ent); |
f633cef0 | 934 | |
19a7fe20 SRRH |
935 | SEQ_PUT_FIELD(s, field->prev_pid); |
936 | SEQ_PUT_FIELD(s, field->prev_prio); | |
937 | SEQ_PUT_FIELD(s, field->prev_state); | |
938 | SEQ_PUT_FIELD(s, field->next_cpu); | |
939 | SEQ_PUT_FIELD(s, field->next_pid); | |
940 | SEQ_PUT_FIELD(s, field->next_prio); | |
941 | SEQ_PUT_FIELD(s, field->next_state); | |
f633cef0 | 942 | |
19a7fe20 | 943 | return trace_handle_return(s); |
f633cef0 SR |
944 | } |
945 | ||
a9a57763 | 946 | static struct trace_event_functions trace_ctx_funcs = { |
f633cef0 | 947 | .trace = trace_ctx_print, |
f633cef0 SR |
948 | .raw = trace_ctx_raw, |
949 | .hex = trace_ctx_hex, | |
950 | .binary = trace_ctxwake_bin, | |
951 | }; | |
952 | ||
a9a57763 SR |
953 | static struct trace_event trace_ctx_event = { |
954 | .type = TRACE_CTX, | |
955 | .funcs = &trace_ctx_funcs, | |
956 | }; | |
957 | ||
958 | static struct trace_event_functions trace_wake_funcs = { | |
f633cef0 | 959 | .trace = trace_wake_print, |
f633cef0 SR |
960 | .raw = trace_wake_raw, |
961 | .hex = trace_wake_hex, | |
962 | .binary = trace_ctxwake_bin, | |
963 | }; | |
964 | ||
a9a57763 SR |
965 | static struct trace_event trace_wake_event = { |
966 | .type = TRACE_WAKE, | |
967 | .funcs = &trace_wake_funcs, | |
968 | }; | |
969 | ||
f633cef0 SR |
970 | /* TRACE_STACK */ |
971 | ||
ae7462b4 | 972 | static enum print_line_t trace_stack_print(struct trace_iterator *iter, |
a9a57763 | 973 | int flags, struct trace_event *event) |
f633cef0 SR |
974 | { |
975 | struct stack_entry *field; | |
2c9b238e | 976 | struct trace_seq *s = &iter->seq; |
4a9bd3f1 SR |
977 | unsigned long *p; |
978 | unsigned long *end; | |
f633cef0 | 979 | |
2c9b238e | 980 | trace_assign_type(field, iter->ent); |
4a9bd3f1 | 981 | end = (unsigned long *)((long)iter->ent + iter->ent_size); |
f633cef0 | 982 | |
19a7fe20 | 983 | trace_seq_puts(s, "<stack trace>\n"); |
4a9bd3f1 SR |
984 | |
985 | for (p = field->caller; p && *p != ULONG_MAX && p < end; p++) { | |
f633cef0 | 986 | |
19a7fe20 SRRH |
987 | if (trace_seq_has_overflowed(s)) |
988 | break; | |
f633cef0 | 989 | |
19a7fe20 SRRH |
990 | trace_seq_puts(s, " => "); |
991 | seq_print_ip_sym(s, *p, flags); | |
992 | trace_seq_putc(s, '\n'); | |
993 | } | |
f633cef0 | 994 | |
19a7fe20 | 995 | return trace_handle_return(s); |
f633cef0 SR |
996 | } |
997 | ||
a9a57763 | 998 | static struct trace_event_functions trace_stack_funcs = { |
f633cef0 | 999 | .trace = trace_stack_print, |
f633cef0 SR |
1000 | }; |
1001 | ||
a9a57763 SR |
1002 | static struct trace_event trace_stack_event = { |
1003 | .type = TRACE_STACK, | |
1004 | .funcs = &trace_stack_funcs, | |
1005 | }; | |
1006 | ||
f633cef0 | 1007 | /* TRACE_USER_STACK */ |
ae7462b4 | 1008 | static enum print_line_t trace_user_stack_print(struct trace_iterator *iter, |
a9a57763 | 1009 | int flags, struct trace_event *event) |
f633cef0 SR |
1010 | { |
1011 | struct userstack_entry *field; | |
2c9b238e | 1012 | struct trace_seq *s = &iter->seq; |
f633cef0 | 1013 | |
2c9b238e | 1014 | trace_assign_type(field, iter->ent); |
f633cef0 | 1015 | |
19a7fe20 SRRH |
1016 | trace_seq_puts(s, "<user stack trace>\n"); |
1017 | seq_print_userip_objs(field, s, flags); | |
f633cef0 | 1018 | |
19a7fe20 | 1019 | return trace_handle_return(s); |
f633cef0 SR |
1020 | } |
1021 | ||
a9a57763 | 1022 | static struct trace_event_functions trace_user_stack_funcs = { |
f633cef0 | 1023 | .trace = trace_user_stack_print, |
f633cef0 SR |
1024 | }; |
1025 | ||
a9a57763 SR |
1026 | static struct trace_event trace_user_stack_event = { |
1027 | .type = TRACE_USER_STACK, | |
1028 | .funcs = &trace_user_stack_funcs, | |
1029 | }; | |
1030 | ||
09ae7234 SRRH |
1031 | /* TRACE_BPUTS */ |
1032 | static enum print_line_t | |
1033 | trace_bputs_print(struct trace_iterator *iter, int flags, | |
1034 | struct trace_event *event) | |
1035 | { | |
1036 | struct trace_entry *entry = iter->ent; | |
1037 | struct trace_seq *s = &iter->seq; | |
1038 | struct bputs_entry *field; | |
1039 | ||
1040 | trace_assign_type(field, entry); | |
1041 | ||
19a7fe20 SRRH |
1042 | seq_print_ip_sym(s, field->ip, flags); |
1043 | trace_seq_puts(s, ": "); | |
1044 | trace_seq_puts(s, field->str); | |
09ae7234 | 1045 | |
19a7fe20 | 1046 | return trace_handle_return(s); |
09ae7234 SRRH |
1047 | } |
1048 | ||
1049 | ||
1050 | static enum print_line_t | |
1051 | trace_bputs_raw(struct trace_iterator *iter, int flags, | |
1052 | struct trace_event *event) | |
1053 | { | |
1054 | struct bputs_entry *field; | |
1055 | struct trace_seq *s = &iter->seq; | |
1056 | ||
1057 | trace_assign_type(field, iter->ent); | |
1058 | ||
19a7fe20 SRRH |
1059 | trace_seq_printf(s, ": %lx : ", field->ip); |
1060 | trace_seq_puts(s, field->str); | |
09ae7234 | 1061 | |
19a7fe20 | 1062 | return trace_handle_return(s); |
09ae7234 SRRH |
1063 | } |
1064 | ||
1065 | static struct trace_event_functions trace_bputs_funcs = { | |
1066 | .trace = trace_bputs_print, | |
1067 | .raw = trace_bputs_raw, | |
1068 | }; | |
1069 | ||
1070 | static struct trace_event trace_bputs_event = { | |
1071 | .type = TRACE_BPUTS, | |
1072 | .funcs = &trace_bputs_funcs, | |
1073 | }; | |
1074 | ||
48ead020 | 1075 | /* TRACE_BPRINT */ |
1427cdf0 | 1076 | static enum print_line_t |
a9a57763 SR |
1077 | trace_bprint_print(struct trace_iterator *iter, int flags, |
1078 | struct trace_event *event) | |
1427cdf0 LJ |
1079 | { |
1080 | struct trace_entry *entry = iter->ent; | |
1081 | struct trace_seq *s = &iter->seq; | |
48ead020 | 1082 | struct bprint_entry *field; |
1427cdf0 LJ |
1083 | |
1084 | trace_assign_type(field, entry); | |
1085 | ||
19a7fe20 SRRH |
1086 | seq_print_ip_sym(s, field->ip, flags); |
1087 | trace_seq_puts(s, ": "); | |
1088 | trace_seq_bprintf(s, field->fmt, field->buf); | |
1427cdf0 | 1089 | |
19a7fe20 | 1090 | return trace_handle_return(s); |
1427cdf0 LJ |
1091 | } |
1092 | ||
769b0441 | 1093 | |
48ead020 | 1094 | static enum print_line_t |
a9a57763 SR |
1095 | trace_bprint_raw(struct trace_iterator *iter, int flags, |
1096 | struct trace_event *event) | |
1427cdf0 | 1097 | { |
48ead020 | 1098 | struct bprint_entry *field; |
1427cdf0 | 1099 | struct trace_seq *s = &iter->seq; |
1427cdf0 | 1100 | |
769b0441 | 1101 | trace_assign_type(field, iter->ent); |
1427cdf0 | 1102 | |
19a7fe20 SRRH |
1103 | trace_seq_printf(s, ": %lx : ", field->ip); |
1104 | trace_seq_bprintf(s, field->fmt, field->buf); | |
1427cdf0 | 1105 | |
19a7fe20 | 1106 | return trace_handle_return(s); |
1427cdf0 LJ |
1107 | } |
1108 | ||
a9a57763 SR |
1109 | static struct trace_event_functions trace_bprint_funcs = { |
1110 | .trace = trace_bprint_print, | |
1111 | .raw = trace_bprint_raw, | |
1112 | }; | |
769b0441 | 1113 | |
48ead020 FW |
1114 | static struct trace_event trace_bprint_event = { |
1115 | .type = TRACE_BPRINT, | |
a9a57763 | 1116 | .funcs = &trace_bprint_funcs, |
48ead020 FW |
1117 | }; |
1118 | ||
1119 | /* TRACE_PRINT */ | |
1120 | static enum print_line_t trace_print_print(struct trace_iterator *iter, | |
a9a57763 | 1121 | int flags, struct trace_event *event) |
48ead020 FW |
1122 | { |
1123 | struct print_entry *field; | |
1124 | struct trace_seq *s = &iter->seq; | |
1125 | ||
1126 | trace_assign_type(field, iter->ent); | |
1127 | ||
19a7fe20 SRRH |
1128 | seq_print_ip_sym(s, field->ip, flags); |
1129 | trace_seq_printf(s, ": %s", field->buf); | |
48ead020 | 1130 | |
19a7fe20 | 1131 | return trace_handle_return(s); |
48ead020 FW |
1132 | } |
1133 | ||
a9a57763 SR |
1134 | static enum print_line_t trace_print_raw(struct trace_iterator *iter, int flags, |
1135 | struct trace_event *event) | |
48ead020 FW |
1136 | { |
1137 | struct print_entry *field; | |
1138 | ||
1139 | trace_assign_type(field, iter->ent); | |
1140 | ||
19a7fe20 | 1141 | trace_seq_printf(&iter->seq, "# %lx %s", field->ip, field->buf); |
48ead020 | 1142 | |
19a7fe20 | 1143 | return trace_handle_return(&iter->seq); |
48ead020 FW |
1144 | } |
1145 | ||
a9a57763 | 1146 | static struct trace_event_functions trace_print_funcs = { |
769b0441 FW |
1147 | .trace = trace_print_print, |
1148 | .raw = trace_print_raw, | |
1427cdf0 LJ |
1149 | }; |
1150 | ||
a9a57763 SR |
1151 | static struct trace_event trace_print_event = { |
1152 | .type = TRACE_PRINT, | |
1153 | .funcs = &trace_print_funcs, | |
1154 | }; | |
1155 | ||
48ead020 | 1156 | |
f633cef0 SR |
1157 | static struct trace_event *events[] __initdata = { |
1158 | &trace_fn_event, | |
1159 | &trace_ctx_event, | |
1160 | &trace_wake_event, | |
f633cef0 SR |
1161 | &trace_stack_event, |
1162 | &trace_user_stack_event, | |
09ae7234 | 1163 | &trace_bputs_event, |
48ead020 | 1164 | &trace_bprint_event, |
f633cef0 SR |
1165 | &trace_print_event, |
1166 | NULL | |
1167 | }; | |
1168 | ||
1169 | __init static int init_events(void) | |
1170 | { | |
1171 | struct trace_event *event; | |
1172 | int i, ret; | |
1173 | ||
1174 | for (i = 0; events[i]; i++) { | |
1175 | event = events[i]; | |
1176 | ||
1177 | ret = register_ftrace_event(event); | |
1178 | if (!ret) { | |
1179 | printk(KERN_WARNING "event %d failed to register\n", | |
1180 | event->type); | |
1181 | WARN_ON_ONCE(1); | |
1182 | } | |
1183 | } | |
1184 | ||
1185 | return 0; | |
1186 | } | |
7374e827 | 1187 | early_initcall(init_events); |