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