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