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