trace_output.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900
  1. /*
  2. * trace_output.c
  3. *
  4. * Copyright (C) 2008 Red Hat Inc, Steven Rostedt <srostedt@redhat.com>
  5. *
  6. */
  7. #include <linux/module.h>
  8. #include <linux/mutex.h>
  9. #include <linux/ftrace.h>
  10. #include "trace_output.h"
  11. /* must be a power of 2 */
  12. #define EVENT_HASHSIZE 128
  13. static DEFINE_MUTEX(trace_event_mutex);
  14. static struct hlist_head event_hash[EVENT_HASHSIZE] __read_mostly;
  15. static int next_event_type = __TRACE_LAST_TYPE + 1;
  16. /**
  17. * trace_seq_printf - sequence printing of trace information
  18. * @s: trace sequence descriptor
  19. * @fmt: printf format string
  20. *
  21. * The tracer may use either sequence operations or its own
  22. * copy to user routines. To simplify formating of a trace
  23. * trace_seq_printf is used to store strings into a special
  24. * buffer (@s). Then the output may be either used by
  25. * the sequencer or pulled into another buffer.
  26. */
  27. int
  28. trace_seq_printf(struct trace_seq *s, const char *fmt, ...)
  29. {
  30. int len = (PAGE_SIZE - 1) - s->len;
  31. va_list ap;
  32. int ret;
  33. if (!len)
  34. return 0;
  35. va_start(ap, fmt);
  36. ret = vsnprintf(s->buffer + s->len, len, fmt, ap);
  37. va_end(ap);
  38. /* If we can't write it all, don't bother writing anything */
  39. if (ret >= len)
  40. return 0;
  41. s->len += ret;
  42. return len;
  43. }
  44. /**
  45. * trace_seq_puts - trace sequence printing of simple string
  46. * @s: trace sequence descriptor
  47. * @str: simple string to record
  48. *
  49. * The tracer may use either the sequence operations or its own
  50. * copy to user routines. This function records a simple string
  51. * into a special buffer (@s) for later retrieval by a sequencer
  52. * or other mechanism.
  53. */
  54. int trace_seq_puts(struct trace_seq *s, const char *str)
  55. {
  56. int len = strlen(str);
  57. if (len > ((PAGE_SIZE - 1) - s->len))
  58. return 0;
  59. memcpy(s->buffer + s->len, str, len);
  60. s->len += len;
  61. return len;
  62. }
  63. int trace_seq_putc(struct trace_seq *s, unsigned char c)
  64. {
  65. if (s->len >= (PAGE_SIZE - 1))
  66. return 0;
  67. s->buffer[s->len++] = c;
  68. return 1;
  69. }
  70. int trace_seq_putmem(struct trace_seq *s, void *mem, size_t len)
  71. {
  72. if (len > ((PAGE_SIZE - 1) - s->len))
  73. return 0;
  74. memcpy(s->buffer + s->len, mem, len);
  75. s->len += len;
  76. return len;
  77. }
  78. int trace_seq_putmem_hex(struct trace_seq *s, void *mem, size_t len)
  79. {
  80. unsigned char hex[HEX_CHARS];
  81. unsigned char *data = mem;
  82. int i, j;
  83. #ifdef __BIG_ENDIAN
  84. for (i = 0, j = 0; i < len; i++) {
  85. #else
  86. for (i = len-1, j = 0; i >= 0; i--) {
  87. #endif
  88. hex[j++] = hex_asc_hi(data[i]);
  89. hex[j++] = hex_asc_lo(data[i]);
  90. }
  91. hex[j++] = ' ';
  92. return trace_seq_putmem(s, hex, j);
  93. }
  94. int trace_seq_path(struct trace_seq *s, struct path *path)
  95. {
  96. unsigned char *p;
  97. if (s->len >= (PAGE_SIZE - 1))
  98. return 0;
  99. p = d_path(path, s->buffer + s->len, PAGE_SIZE - s->len);
  100. if (!IS_ERR(p)) {
  101. p = mangle_path(s->buffer + s->len, p, "\n");
  102. if (p) {
  103. s->len = p - s->buffer;
  104. return 1;
  105. }
  106. } else {
  107. s->buffer[s->len++] = '?';
  108. return 1;
  109. }
  110. return 0;
  111. }
  112. #ifdef CONFIG_KRETPROBES
  113. static inline const char *kretprobed(const char *name)
  114. {
  115. static const char tramp_name[] = "kretprobe_trampoline";
  116. int size = sizeof(tramp_name);
  117. if (strncmp(tramp_name, name, size) == 0)
  118. return "[unknown/kretprobe'd]";
  119. return name;
  120. }
  121. #else
  122. static inline const char *kretprobed(const char *name)
  123. {
  124. return name;
  125. }
  126. #endif /* CONFIG_KRETPROBES */
  127. static int
  128. seq_print_sym_short(struct trace_seq *s, const char *fmt, unsigned long address)
  129. {
  130. #ifdef CONFIG_KALLSYMS
  131. char str[KSYM_SYMBOL_LEN];
  132. const char *name;
  133. kallsyms_lookup(address, NULL, NULL, NULL, str);
  134. name = kretprobed(str);
  135. return trace_seq_printf(s, fmt, name);
  136. #endif
  137. return 1;
  138. }
  139. static int
  140. seq_print_sym_offset(struct trace_seq *s, const char *fmt,
  141. unsigned long address)
  142. {
  143. #ifdef CONFIG_KALLSYMS
  144. char str[KSYM_SYMBOL_LEN];
  145. const char *name;
  146. sprint_symbol(str, address);
  147. name = kretprobed(str);
  148. return trace_seq_printf(s, fmt, name);
  149. #endif
  150. return 1;
  151. }
  152. #ifndef CONFIG_64BIT
  153. # define IP_FMT "%08lx"
  154. #else
  155. # define IP_FMT "%016lx"
  156. #endif
  157. int seq_print_user_ip(struct trace_seq *s, struct mm_struct *mm,
  158. unsigned long ip, unsigned long sym_flags)
  159. {
  160. struct file *file = NULL;
  161. unsigned long vmstart = 0;
  162. int ret = 1;
  163. if (mm) {
  164. const struct vm_area_struct *vma;
  165. down_read(&mm->mmap_sem);
  166. vma = find_vma(mm, ip);
  167. if (vma) {
  168. file = vma->vm_file;
  169. vmstart = vma->vm_start;
  170. }
  171. if (file) {
  172. ret = trace_seq_path(s, &file->f_path);
  173. if (ret)
  174. ret = trace_seq_printf(s, "[+0x%lx]",
  175. ip - vmstart);
  176. }
  177. up_read(&mm->mmap_sem);
  178. }
  179. if (ret && ((sym_flags & TRACE_ITER_SYM_ADDR) || !file))
  180. ret = trace_seq_printf(s, " <" IP_FMT ">", ip);
  181. return ret;
  182. }
  183. int
  184. seq_print_userip_objs(const struct userstack_entry *entry, struct trace_seq *s,
  185. unsigned long sym_flags)
  186. {
  187. struct mm_struct *mm = NULL;
  188. int ret = 1;
  189. unsigned int i;
  190. if (trace_flags & TRACE_ITER_SYM_USEROBJ) {
  191. struct task_struct *task;
  192. /*
  193. * we do the lookup on the thread group leader,
  194. * since individual threads might have already quit!
  195. */
  196. rcu_read_lock();
  197. task = find_task_by_vpid(entry->ent.tgid);
  198. if (task)
  199. mm = get_task_mm(task);
  200. rcu_read_unlock();
  201. }
  202. for (i = 0; i < FTRACE_STACK_ENTRIES; i++) {
  203. unsigned long ip = entry->caller[i];
  204. if (ip == ULONG_MAX || !ret)
  205. break;
  206. if (i && ret)
  207. ret = trace_seq_puts(s, " <- ");
  208. if (!ip) {
  209. if (ret)
  210. ret = trace_seq_puts(s, "??");
  211. continue;
  212. }
  213. if (!ret)
  214. break;
  215. if (ret)
  216. ret = seq_print_user_ip(s, mm, ip, sym_flags);
  217. }
  218. if (mm)
  219. mmput(mm);
  220. return ret;
  221. }
  222. int
  223. seq_print_ip_sym(struct trace_seq *s, unsigned long ip, unsigned long sym_flags)
  224. {
  225. int ret;
  226. if (!ip)
  227. return trace_seq_printf(s, "0");
  228. if (sym_flags & TRACE_ITER_SYM_OFFSET)
  229. ret = seq_print_sym_offset(s, "%s", ip);
  230. else
  231. ret = seq_print_sym_short(s, "%s", ip);
  232. if (!ret)
  233. return 0;
  234. if (sym_flags & TRACE_ITER_SYM_ADDR)
  235. ret = trace_seq_printf(s, " <" IP_FMT ">", ip);
  236. return ret;
  237. }
  238. static int
  239. lat_print_generic(struct trace_seq *s, struct trace_entry *entry, int cpu)
  240. {
  241. int hardirq, softirq;
  242. char *comm;
  243. comm = trace_find_cmdline(entry->pid);
  244. hardirq = entry->flags & TRACE_FLAG_HARDIRQ;
  245. softirq = entry->flags & TRACE_FLAG_SOFTIRQ;
  246. if (!trace_seq_printf(s, "%8.8s-%-5d %3d%c%c%c",
  247. comm, entry->pid, cpu,
  248. (entry->flags & TRACE_FLAG_IRQS_OFF) ? 'd' :
  249. (entry->flags & TRACE_FLAG_IRQS_NOSUPPORT) ?
  250. 'X' : '.',
  251. (entry->flags & TRACE_FLAG_NEED_RESCHED) ?
  252. 'N' : '.',
  253. (hardirq && softirq) ? 'H' :
  254. hardirq ? 'h' : softirq ? 's' : '.'))
  255. return 0;
  256. if (entry->preempt_count)
  257. return trace_seq_printf(s, "%x", entry->preempt_count);
  258. return trace_seq_puts(s, ".");
  259. }
  260. static unsigned long preempt_mark_thresh = 100;
  261. static int
  262. lat_print_timestamp(struct trace_seq *s, u64 abs_usecs,
  263. unsigned long rel_usecs)
  264. {
  265. return trace_seq_printf(s, " %4lldus%c: ", abs_usecs,
  266. rel_usecs > preempt_mark_thresh ? '!' :
  267. rel_usecs > 1 ? '+' : ' ');
  268. }
  269. int trace_print_context(struct trace_iterator *iter)
  270. {
  271. struct trace_seq *s = &iter->seq;
  272. struct trace_entry *entry = iter->ent;
  273. char *comm = trace_find_cmdline(entry->pid);
  274. unsigned long long t = ns2usecs(iter->ts);
  275. unsigned long usec_rem = do_div(t, USEC_PER_SEC);
  276. unsigned long secs = (unsigned long)t;
  277. return trace_seq_printf(s, "%16s-%-5d [%03d] %5lu.%06lu: ",
  278. comm, entry->pid, entry->cpu, secs, usec_rem);
  279. }
  280. int trace_print_lat_context(struct trace_iterator *iter)
  281. {
  282. u64 next_ts;
  283. int ret;
  284. struct trace_seq *s = &iter->seq;
  285. struct trace_entry *entry = iter->ent,
  286. *next_entry = trace_find_next_entry(iter, NULL,
  287. &next_ts);
  288. unsigned long verbose = (trace_flags & TRACE_ITER_VERBOSE);
  289. unsigned long abs_usecs = ns2usecs(iter->ts - iter->tr->time_start);
  290. unsigned long rel_usecs;
  291. if (!next_entry)
  292. next_ts = iter->ts;
  293. rel_usecs = ns2usecs(next_ts - iter->ts);
  294. if (verbose) {
  295. char *comm = trace_find_cmdline(entry->pid);
  296. ret = trace_seq_printf(s, "%16s %5d %3d %d %08x %08lx [%08lx]"
  297. " %ld.%03ldms (+%ld.%03ldms): ", comm,
  298. entry->pid, entry->cpu, entry->flags,
  299. entry->preempt_count, iter->idx,
  300. ns2usecs(iter->ts),
  301. abs_usecs / USEC_PER_MSEC,
  302. abs_usecs % USEC_PER_MSEC,
  303. rel_usecs / USEC_PER_MSEC,
  304. rel_usecs % USEC_PER_MSEC);
  305. } else {
  306. ret = lat_print_generic(s, entry, entry->cpu);
  307. if (ret)
  308. ret = lat_print_timestamp(s, abs_usecs, rel_usecs);
  309. }
  310. return ret;
  311. }
  312. static const char state_to_char[] = TASK_STATE_TO_CHAR_STR;
  313. static int task_state_char(unsigned long state)
  314. {
  315. int bit = state ? __ffs(state) + 1 : 0;
  316. return bit < sizeof(state_to_char) - 1 ? state_to_char[bit] : '?';
  317. }
  318. /**
  319. * ftrace_find_event - find a registered event
  320. * @type: the type of event to look for
  321. *
  322. * Returns an event of type @type otherwise NULL
  323. */
  324. struct trace_event *ftrace_find_event(int type)
  325. {
  326. struct trace_event *event;
  327. struct hlist_node *n;
  328. unsigned key;
  329. key = type & (EVENT_HASHSIZE - 1);
  330. hlist_for_each_entry_rcu(event, n, &event_hash[key], node) {
  331. if (event->type == type)
  332. return event;
  333. }
  334. return NULL;
  335. }
  336. /**
  337. * register_ftrace_event - register output for an event type
  338. * @event: the event type to register
  339. *
  340. * Event types are stored in a hash and this hash is used to
  341. * find a way to print an event. If the @event->type is set
  342. * then it will use that type, otherwise it will assign a
  343. * type to use.
  344. *
  345. * If you assign your own type, please make sure it is added
  346. * to the trace_type enum in trace.h, to avoid collisions
  347. * with the dynamic types.
  348. *
  349. * Returns the event type number or zero on error.
  350. */
  351. int register_ftrace_event(struct trace_event *event)
  352. {
  353. unsigned key;
  354. int ret = 0;
  355. mutex_lock(&trace_event_mutex);
  356. if (!event->type)
  357. event->type = next_event_type++;
  358. else if (event->type > __TRACE_LAST_TYPE) {
  359. printk(KERN_WARNING "Need to add type to trace.h\n");
  360. WARN_ON(1);
  361. }
  362. if (ftrace_find_event(event->type))
  363. goto out;
  364. key = event->type & (EVENT_HASHSIZE - 1);
  365. hlist_add_head_rcu(&event->node, &event_hash[key]);
  366. ret = event->type;
  367. out:
  368. mutex_unlock(&trace_event_mutex);
  369. return ret;
  370. }
  371. /**
  372. * unregister_ftrace_event - remove a no longer used event
  373. * @event: the event to remove
  374. */
  375. int unregister_ftrace_event(struct trace_event *event)
  376. {
  377. mutex_lock(&trace_event_mutex);
  378. hlist_del(&event->node);
  379. mutex_unlock(&trace_event_mutex);
  380. return 0;
  381. }
  382. /*
  383. * Standard events
  384. */
  385. int trace_nop_print(struct trace_iterator *iter, int flags)
  386. {
  387. return TRACE_TYPE_HANDLED;
  388. }
  389. /* TRACE_FN */
  390. static int trace_fn_latency(struct trace_iterator *iter, int flags)
  391. {
  392. struct ftrace_entry *field;
  393. struct trace_seq *s = &iter->seq;
  394. trace_assign_type(field, iter->ent);
  395. if (!seq_print_ip_sym(s, field->ip, flags))
  396. goto partial;
  397. if (!trace_seq_puts(s, " ("))
  398. goto partial;
  399. if (!seq_print_ip_sym(s, field->parent_ip, flags))
  400. goto partial;
  401. if (!trace_seq_puts(s, ")\n"))
  402. goto partial;
  403. return TRACE_TYPE_HANDLED;
  404. partial:
  405. return TRACE_TYPE_PARTIAL_LINE;
  406. }
  407. static int trace_fn_trace(struct trace_iterator *iter, int flags)
  408. {
  409. struct ftrace_entry *field;
  410. struct trace_seq *s = &iter->seq;
  411. trace_assign_type(field, iter->ent);
  412. if (!seq_print_ip_sym(s, field->ip, flags))
  413. goto partial;
  414. if ((flags & TRACE_ITER_PRINT_PARENT) && field->parent_ip) {
  415. if (!trace_seq_printf(s, " <-"))
  416. goto partial;
  417. if (!seq_print_ip_sym(s,
  418. field->parent_ip,
  419. flags))
  420. goto partial;
  421. }
  422. if (!trace_seq_printf(s, "\n"))
  423. goto partial;
  424. return TRACE_TYPE_HANDLED;
  425. partial:
  426. return TRACE_TYPE_PARTIAL_LINE;
  427. }
  428. static int trace_fn_raw(struct trace_iterator *iter, int flags)
  429. {
  430. struct ftrace_entry *field;
  431. trace_assign_type(field, iter->ent);
  432. if (!trace_seq_printf(&iter->seq, "%lx %lx\n",
  433. field->ip,
  434. field->parent_ip))
  435. return TRACE_TYPE_PARTIAL_LINE;
  436. return TRACE_TYPE_HANDLED;
  437. }
  438. static int trace_fn_hex(struct trace_iterator *iter, int flags)
  439. {
  440. struct ftrace_entry *field;
  441. struct trace_seq *s = &iter->seq;
  442. trace_assign_type(field, iter->ent);
  443. SEQ_PUT_HEX_FIELD_RET(s, field->ip);
  444. SEQ_PUT_HEX_FIELD_RET(s, field->parent_ip);
  445. return TRACE_TYPE_HANDLED;
  446. }
  447. static int trace_fn_bin(struct trace_iterator *iter, int flags)
  448. {
  449. struct ftrace_entry *field;
  450. struct trace_seq *s = &iter->seq;
  451. trace_assign_type(field, iter->ent);
  452. SEQ_PUT_FIELD_RET(s, field->ip);
  453. SEQ_PUT_FIELD_RET(s, field->parent_ip);
  454. return TRACE_TYPE_HANDLED;
  455. }
  456. static struct trace_event trace_fn_event = {
  457. .type = TRACE_FN,
  458. .trace = trace_fn_trace,
  459. .latency_trace = trace_fn_latency,
  460. .raw = trace_fn_raw,
  461. .hex = trace_fn_hex,
  462. .binary = trace_fn_bin,
  463. };
  464. /* TRACE_CTX an TRACE_WAKE */
  465. static int trace_ctxwake_print(struct trace_iterator *iter, char *delim)
  466. {
  467. struct ctx_switch_entry *field;
  468. char *comm;
  469. int S, T;
  470. trace_assign_type(field, iter->ent);
  471. T = task_state_char(field->next_state);
  472. S = task_state_char(field->prev_state);
  473. comm = trace_find_cmdline(field->next_pid);
  474. if (!trace_seq_printf(&iter->seq,
  475. " %5d:%3d:%c %s [%03d] %5d:%3d:%c %s\n",
  476. field->prev_pid,
  477. field->prev_prio,
  478. S, delim,
  479. field->next_cpu,
  480. field->next_pid,
  481. field->next_prio,
  482. T, comm))
  483. return TRACE_TYPE_PARTIAL_LINE;
  484. return TRACE_TYPE_HANDLED;
  485. }
  486. static int trace_ctx_print(struct trace_iterator *iter, int flags)
  487. {
  488. return trace_ctxwake_print(iter, "==>");
  489. }
  490. static int trace_wake_print(struct trace_iterator *iter, int flags)
  491. {
  492. return trace_ctxwake_print(iter, " +");
  493. }
  494. static int trace_ctxwake_raw(struct trace_iterator *iter, char S)
  495. {
  496. struct ctx_switch_entry *field;
  497. int T;
  498. trace_assign_type(field, iter->ent);
  499. if (!S)
  500. task_state_char(field->prev_state);
  501. T = task_state_char(field->next_state);
  502. if (!trace_seq_printf(&iter->seq, "%d %d %c %d %d %d %c\n",
  503. field->prev_pid,
  504. field->prev_prio,
  505. S,
  506. field->next_cpu,
  507. field->next_pid,
  508. field->next_prio,
  509. T))
  510. return TRACE_TYPE_PARTIAL_LINE;
  511. return TRACE_TYPE_HANDLED;
  512. }
  513. static int trace_ctx_raw(struct trace_iterator *iter, int flags)
  514. {
  515. return trace_ctxwake_raw(iter, 0);
  516. }
  517. static int trace_wake_raw(struct trace_iterator *iter, int flags)
  518. {
  519. return trace_ctxwake_raw(iter, '+');
  520. }
  521. static int trace_ctxwake_hex(struct trace_iterator *iter, char S)
  522. {
  523. struct ctx_switch_entry *field;
  524. struct trace_seq *s = &iter->seq;
  525. int T;
  526. trace_assign_type(field, iter->ent);
  527. if (!S)
  528. task_state_char(field->prev_state);
  529. T = task_state_char(field->next_state);
  530. SEQ_PUT_HEX_FIELD_RET(s, field->prev_pid);
  531. SEQ_PUT_HEX_FIELD_RET(s, field->prev_prio);
  532. SEQ_PUT_HEX_FIELD_RET(s, S);
  533. SEQ_PUT_HEX_FIELD_RET(s, field->next_cpu);
  534. SEQ_PUT_HEX_FIELD_RET(s, field->next_pid);
  535. SEQ_PUT_HEX_FIELD_RET(s, field->next_prio);
  536. SEQ_PUT_HEX_FIELD_RET(s, T);
  537. return TRACE_TYPE_HANDLED;
  538. }
  539. static int trace_ctx_hex(struct trace_iterator *iter, int flags)
  540. {
  541. return trace_ctxwake_hex(iter, 0);
  542. }
  543. static int trace_wake_hex(struct trace_iterator *iter, int flags)
  544. {
  545. return trace_ctxwake_hex(iter, '+');
  546. }
  547. static int trace_ctxwake_bin(struct trace_iterator *iter, int flags)
  548. {
  549. struct ctx_switch_entry *field;
  550. struct trace_seq *s = &iter->seq;
  551. trace_assign_type(field, iter->ent);
  552. SEQ_PUT_FIELD_RET(s, field->prev_pid);
  553. SEQ_PUT_FIELD_RET(s, field->prev_prio);
  554. SEQ_PUT_FIELD_RET(s, field->prev_state);
  555. SEQ_PUT_FIELD_RET(s, field->next_pid);
  556. SEQ_PUT_FIELD_RET(s, field->next_prio);
  557. SEQ_PUT_FIELD_RET(s, field->next_state);
  558. return TRACE_TYPE_HANDLED;
  559. }
  560. static struct trace_event trace_ctx_event = {
  561. .type = TRACE_CTX,
  562. .trace = trace_ctx_print,
  563. .latency_trace = trace_ctx_print,
  564. .raw = trace_ctx_raw,
  565. .hex = trace_ctx_hex,
  566. .binary = trace_ctxwake_bin,
  567. };
  568. static struct trace_event trace_wake_event = {
  569. .type = TRACE_WAKE,
  570. .trace = trace_wake_print,
  571. .latency_trace = trace_wake_print,
  572. .raw = trace_wake_raw,
  573. .hex = trace_wake_hex,
  574. .binary = trace_ctxwake_bin,
  575. };
  576. /* TRACE_SPECIAL */
  577. static int trace_special_print(struct trace_iterator *iter, int flags)
  578. {
  579. struct special_entry *field;
  580. trace_assign_type(field, iter->ent);
  581. if (!trace_seq_printf(&iter->seq, "# %ld %ld %ld\n",
  582. field->arg1,
  583. field->arg2,
  584. field->arg3))
  585. return TRACE_TYPE_PARTIAL_LINE;
  586. return TRACE_TYPE_HANDLED;
  587. }
  588. static int trace_special_hex(struct trace_iterator *iter, int flags)
  589. {
  590. struct special_entry *field;
  591. struct trace_seq *s = &iter->seq;
  592. trace_assign_type(field, iter->ent);
  593. SEQ_PUT_HEX_FIELD_RET(s, field->arg1);
  594. SEQ_PUT_HEX_FIELD_RET(s, field->arg2);
  595. SEQ_PUT_HEX_FIELD_RET(s, field->arg3);
  596. return TRACE_TYPE_HANDLED;
  597. }
  598. static int trace_special_bin(struct trace_iterator *iter, int flags)
  599. {
  600. struct special_entry *field;
  601. struct trace_seq *s = &iter->seq;
  602. trace_assign_type(field, iter->ent);
  603. SEQ_PUT_FIELD_RET(s, field->arg1);
  604. SEQ_PUT_FIELD_RET(s, field->arg2);
  605. SEQ_PUT_FIELD_RET(s, field->arg3);
  606. return TRACE_TYPE_HANDLED;
  607. }
  608. static struct trace_event trace_special_event = {
  609. .type = TRACE_SPECIAL,
  610. .trace = trace_special_print,
  611. .latency_trace = trace_special_print,
  612. .raw = trace_special_print,
  613. .hex = trace_special_hex,
  614. .binary = trace_special_bin,
  615. };
  616. /* TRACE_STACK */
  617. static int trace_stack_print(struct trace_iterator *iter, int flags)
  618. {
  619. struct stack_entry *field;
  620. struct trace_seq *s = &iter->seq;
  621. int i;
  622. trace_assign_type(field, iter->ent);
  623. for (i = 0; i < FTRACE_STACK_ENTRIES; i++) {
  624. if (i) {
  625. if (!trace_seq_puts(s, " <= "))
  626. goto partial;
  627. if (!seq_print_ip_sym(s, field->caller[i], flags))
  628. goto partial;
  629. }
  630. if (!trace_seq_puts(s, "\n"))
  631. goto partial;
  632. }
  633. return TRACE_TYPE_HANDLED;
  634. partial:
  635. return TRACE_TYPE_PARTIAL_LINE;
  636. }
  637. static struct trace_event trace_stack_event = {
  638. .type = TRACE_STACK,
  639. .trace = trace_stack_print,
  640. .latency_trace = trace_stack_print,
  641. .raw = trace_special_print,
  642. .hex = trace_special_hex,
  643. .binary = trace_special_bin,
  644. };
  645. /* TRACE_USER_STACK */
  646. static int trace_user_stack_print(struct trace_iterator *iter, int flags)
  647. {
  648. struct userstack_entry *field;
  649. struct trace_seq *s = &iter->seq;
  650. trace_assign_type(field, iter->ent);
  651. if (!seq_print_userip_objs(field, s, flags))
  652. goto partial;
  653. if (!trace_seq_putc(s, '\n'))
  654. goto partial;
  655. return TRACE_TYPE_HANDLED;
  656. partial:
  657. return TRACE_TYPE_PARTIAL_LINE;
  658. }
  659. static struct trace_event trace_user_stack_event = {
  660. .type = TRACE_USER_STACK,
  661. .trace = trace_user_stack_print,
  662. .latency_trace = trace_user_stack_print,
  663. .raw = trace_special_print,
  664. .hex = trace_special_hex,
  665. .binary = trace_special_bin,
  666. };
  667. /* TRACE_PRINT */
  668. static int trace_print_print(struct trace_iterator *iter, int flags)
  669. {
  670. struct print_entry *field;
  671. struct trace_seq *s = &iter->seq;
  672. trace_assign_type(field, iter->ent);
  673. if (!seq_print_ip_sym(s, field->ip, flags))
  674. goto partial;
  675. if (!trace_seq_printf(s, ": %s", field->buf))
  676. goto partial;
  677. return TRACE_TYPE_HANDLED;
  678. partial:
  679. return TRACE_TYPE_PARTIAL_LINE;
  680. }
  681. static int trace_print_raw(struct trace_iterator *iter, int flags)
  682. {
  683. struct print_entry *field;
  684. trace_assign_type(field, iter->ent);
  685. if (!trace_seq_printf(&iter->seq, "# %lx %s", field->ip, field->buf))
  686. goto partial;
  687. return TRACE_TYPE_HANDLED;
  688. partial:
  689. return TRACE_TYPE_PARTIAL_LINE;
  690. }
  691. static struct trace_event trace_print_event = {
  692. .type = TRACE_PRINT,
  693. .trace = trace_print_print,
  694. .latency_trace = trace_print_print,
  695. .raw = trace_print_raw,
  696. .hex = trace_nop_print,
  697. .binary = trace_nop_print,
  698. };
  699. static struct trace_event *events[] __initdata = {
  700. &trace_fn_event,
  701. &trace_ctx_event,
  702. &trace_wake_event,
  703. &trace_special_event,
  704. &trace_stack_event,
  705. &trace_user_stack_event,
  706. &trace_print_event,
  707. NULL
  708. };
  709. __init static int init_events(void)
  710. {
  711. struct trace_event *event;
  712. int i, ret;
  713. for (i = 0; events[i]; i++) {
  714. event = events[i];
  715. ret = register_ftrace_event(event);
  716. if (!ret) {
  717. printk(KERN_WARNING "event %d failed to register\n",
  718. event->type);
  719. WARN_ON_ONCE(1);
  720. }
  721. }
  722. return 0;
  723. }
  724. device_initcall(init_events);