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