trace_output.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829
  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 const char state_to_char[] = TASK_STATE_TO_CHAR_STR;
  239. static int task_state_char(unsigned long state)
  240. {
  241. int bit = state ? __ffs(state) + 1 : 0;
  242. return bit < sizeof(state_to_char) - 1 ? state_to_char[bit] : '?';
  243. }
  244. /**
  245. * ftrace_find_event - find a registered event
  246. * @type: the type of event to look for
  247. *
  248. * Returns an event of type @type otherwise NULL
  249. */
  250. struct trace_event *ftrace_find_event(int type)
  251. {
  252. struct trace_event *event;
  253. struct hlist_node *n;
  254. unsigned key;
  255. key = type & (EVENT_HASHSIZE - 1);
  256. hlist_for_each_entry_rcu(event, n, &event_hash[key], node) {
  257. if (event->type == type)
  258. return event;
  259. }
  260. return NULL;
  261. }
  262. /**
  263. * register_ftrace_event - register output for an event type
  264. * @event: the event type to register
  265. *
  266. * Event types are stored in a hash and this hash is used to
  267. * find a way to print an event. If the @event->type is set
  268. * then it will use that type, otherwise it will assign a
  269. * type to use.
  270. *
  271. * If you assign your own type, please make sure it is added
  272. * to the trace_type enum in trace.h, to avoid collisions
  273. * with the dynamic types.
  274. *
  275. * Returns the event type number or zero on error.
  276. */
  277. int register_ftrace_event(struct trace_event *event)
  278. {
  279. unsigned key;
  280. int ret = 0;
  281. mutex_lock(&trace_event_mutex);
  282. if (!event->type)
  283. event->type = next_event_type++;
  284. else if (event->type > __TRACE_LAST_TYPE) {
  285. printk(KERN_WARNING "Need to add type to trace.h\n");
  286. WARN_ON(1);
  287. }
  288. if (ftrace_find_event(event->type))
  289. goto out;
  290. key = event->type & (EVENT_HASHSIZE - 1);
  291. hlist_add_head_rcu(&event->node, &event_hash[key]);
  292. ret = event->type;
  293. out:
  294. mutex_unlock(&trace_event_mutex);
  295. return ret;
  296. }
  297. /**
  298. * unregister_ftrace_event - remove a no longer used event
  299. * @event: the event to remove
  300. */
  301. int unregister_ftrace_event(struct trace_event *event)
  302. {
  303. mutex_lock(&trace_event_mutex);
  304. hlist_del(&event->node);
  305. mutex_unlock(&trace_event_mutex);
  306. return 0;
  307. }
  308. /*
  309. * Standard events
  310. */
  311. int
  312. trace_nop_print(struct trace_seq *s, struct trace_entry *entry, int flags)
  313. {
  314. return 0;
  315. }
  316. /* TRACE_FN */
  317. static int
  318. trace_fn_latency(struct trace_seq *s, struct trace_entry *entry, int flags)
  319. {
  320. struct ftrace_entry *field;
  321. trace_assign_type(field, entry);
  322. if (!seq_print_ip_sym(s, field->ip, flags))
  323. goto partial;
  324. if (!trace_seq_puts(s, " ("))
  325. goto partial;
  326. if (!seq_print_ip_sym(s, field->parent_ip, flags))
  327. goto partial;
  328. if (!trace_seq_puts(s, ")\n"))
  329. goto partial;
  330. return 0;
  331. partial:
  332. return TRACE_TYPE_PARTIAL_LINE;
  333. }
  334. static int
  335. trace_fn_trace(struct trace_seq *s, struct trace_entry *entry, int flags)
  336. {
  337. struct ftrace_entry *field;
  338. trace_assign_type(field, entry);
  339. if (!seq_print_ip_sym(s, field->ip, flags))
  340. goto partial;
  341. if ((flags & TRACE_ITER_PRINT_PARENT) && field->parent_ip) {
  342. if (!trace_seq_printf(s, " <-"))
  343. goto partial;
  344. if (!seq_print_ip_sym(s,
  345. field->parent_ip,
  346. flags))
  347. goto partial;
  348. }
  349. if (!trace_seq_printf(s, "\n"))
  350. goto partial;
  351. return 0;
  352. partial:
  353. return TRACE_TYPE_PARTIAL_LINE;
  354. }
  355. static int
  356. trace_fn_raw(struct trace_seq *s, struct trace_entry *entry, int flags)
  357. {
  358. struct ftrace_entry *field;
  359. trace_assign_type(field, entry);
  360. if (!trace_seq_printf(s, "%x %x\n",
  361. field->ip,
  362. field->parent_ip))
  363. return TRACE_TYPE_PARTIAL_LINE;
  364. return 0;
  365. }
  366. static int
  367. trace_fn_hex(struct trace_seq *s, struct trace_entry *entry, int flags)
  368. {
  369. struct ftrace_entry *field;
  370. trace_assign_type(field, entry);
  371. SEQ_PUT_HEX_FIELD_RET(s, field->ip);
  372. SEQ_PUT_HEX_FIELD_RET(s, field->parent_ip);
  373. return 0;
  374. }
  375. static int
  376. trace_fn_bin(struct trace_seq *s, struct trace_entry *entry, int flags)
  377. {
  378. struct ftrace_entry *field;
  379. trace_assign_type(field, entry);
  380. SEQ_PUT_FIELD_RET(s, field->ip);
  381. SEQ_PUT_FIELD_RET(s, field->parent_ip);
  382. return 0;
  383. }
  384. static struct trace_event trace_fn_event = {
  385. .type = TRACE_FN,
  386. .trace = trace_fn_trace,
  387. .latency_trace = trace_fn_latency,
  388. .raw = trace_fn_raw,
  389. .hex = trace_fn_hex,
  390. .binary = trace_fn_bin,
  391. };
  392. /* TRACE_CTX an TRACE_WAKE */
  393. static int
  394. trace_ctxwake_print(struct trace_seq *s, struct trace_entry *entry, int flags,
  395. char *delim)
  396. {
  397. struct ctx_switch_entry *field;
  398. char *comm;
  399. int S, T;
  400. trace_assign_type(field, entry);
  401. T = task_state_char(field->next_state);
  402. S = task_state_char(field->prev_state);
  403. comm = trace_find_cmdline(field->next_pid);
  404. if (!trace_seq_printf(s, " %5d:%3d:%c %s [%03d] %5d:%3d:%c %s\n",
  405. field->prev_pid,
  406. field->prev_prio,
  407. S, delim,
  408. field->next_cpu,
  409. field->next_pid,
  410. field->next_prio,
  411. T, comm))
  412. return TRACE_TYPE_PARTIAL_LINE;
  413. return 0;
  414. }
  415. static int
  416. trace_ctx_print(struct trace_seq *s, struct trace_entry *entry, int flags)
  417. {
  418. return trace_ctxwake_print(s, entry, flags, "==>");
  419. }
  420. static int
  421. trace_wake_print(struct trace_seq *s, struct trace_entry *entry, int flags)
  422. {
  423. return trace_ctxwake_print(s, entry, flags, " +");
  424. }
  425. static int
  426. trace_ctxwake_raw(struct trace_seq *s, struct trace_entry *entry, int flags,
  427. char S)
  428. {
  429. struct ctx_switch_entry *field;
  430. int T;
  431. trace_assign_type(field, entry);
  432. if (!S)
  433. task_state_char(field->prev_state);
  434. T = task_state_char(field->next_state);
  435. if (!trace_seq_printf(s, "%d %d %c %d %d %d %c\n",
  436. field->prev_pid,
  437. field->prev_prio,
  438. S,
  439. field->next_cpu,
  440. field->next_pid,
  441. field->next_prio,
  442. T))
  443. return TRACE_TYPE_PARTIAL_LINE;
  444. return 0;
  445. }
  446. static int
  447. trace_ctx_raw(struct trace_seq *s, struct trace_entry *entry, int flags)
  448. {
  449. return trace_ctxwake_raw(s, entry, flags, 0);
  450. }
  451. static int
  452. trace_wake_raw(struct trace_seq *s, struct trace_entry *entry, int flags)
  453. {
  454. return trace_ctxwake_raw(s, entry, flags, '+');
  455. }
  456. static int
  457. trace_ctxwake_hex(struct trace_seq *s, struct trace_entry *entry, int flags,
  458. char S)
  459. {
  460. struct ctx_switch_entry *field;
  461. int T;
  462. trace_assign_type(field, entry);
  463. if (!S)
  464. task_state_char(field->prev_state);
  465. T = task_state_char(field->next_state);
  466. SEQ_PUT_HEX_FIELD_RET(s, field->prev_pid);
  467. SEQ_PUT_HEX_FIELD_RET(s, field->prev_prio);
  468. SEQ_PUT_HEX_FIELD_RET(s, S);
  469. SEQ_PUT_HEX_FIELD_RET(s, field->next_cpu);
  470. SEQ_PUT_HEX_FIELD_RET(s, field->next_pid);
  471. SEQ_PUT_HEX_FIELD_RET(s, field->next_prio);
  472. SEQ_PUT_HEX_FIELD_RET(s, T);
  473. return 0;
  474. }
  475. static int
  476. trace_ctx_hex(struct trace_seq *s, struct trace_entry *entry, int flags)
  477. {
  478. return trace_ctxwake_hex(s, entry, flags, 0);
  479. }
  480. static int
  481. trace_wake_hex(struct trace_seq *s, struct trace_entry *entry, int flags)
  482. {
  483. return trace_ctxwake_hex(s, entry, flags, '+');
  484. }
  485. static int
  486. trace_ctxwake_bin(struct trace_seq *s, struct trace_entry *entry, int flags)
  487. {
  488. struct ctx_switch_entry *field;
  489. trace_assign_type(field, entry);
  490. SEQ_PUT_FIELD_RET(s, field->prev_pid);
  491. SEQ_PUT_FIELD_RET(s, field->prev_prio);
  492. SEQ_PUT_FIELD_RET(s, field->prev_state);
  493. SEQ_PUT_FIELD_RET(s, field->next_pid);
  494. SEQ_PUT_FIELD_RET(s, field->next_prio);
  495. SEQ_PUT_FIELD_RET(s, field->next_state);
  496. return 0;
  497. }
  498. static struct trace_event trace_ctx_event = {
  499. .type = TRACE_CTX,
  500. .trace = trace_ctx_print,
  501. .latency_trace = trace_ctx_print,
  502. .raw = trace_ctx_raw,
  503. .hex = trace_ctx_hex,
  504. .binary = trace_ctxwake_bin,
  505. };
  506. static struct trace_event trace_wake_event = {
  507. .type = TRACE_WAKE,
  508. .trace = trace_wake_print,
  509. .latency_trace = trace_wake_print,
  510. .raw = trace_wake_raw,
  511. .hex = trace_wake_hex,
  512. .binary = trace_ctxwake_bin,
  513. };
  514. /* TRACE_SPECIAL */
  515. static int
  516. trace_special_print(struct trace_seq *s, struct trace_entry *entry, int flags)
  517. {
  518. struct special_entry *field;
  519. trace_assign_type(field, entry);
  520. if (!trace_seq_printf(s, "# %ld %ld %ld\n",
  521. field->arg1,
  522. field->arg2,
  523. field->arg3))
  524. return TRACE_TYPE_PARTIAL_LINE;
  525. return 0;
  526. }
  527. static int
  528. trace_special_hex(struct trace_seq *s, struct trace_entry *entry, int flags)
  529. {
  530. struct special_entry *field;
  531. trace_assign_type(field, entry);
  532. SEQ_PUT_HEX_FIELD_RET(s, field->arg1);
  533. SEQ_PUT_HEX_FIELD_RET(s, field->arg2);
  534. SEQ_PUT_HEX_FIELD_RET(s, field->arg3);
  535. return 0;
  536. }
  537. static int
  538. trace_special_bin(struct trace_seq *s, struct trace_entry *entry, int flags)
  539. {
  540. struct special_entry *field;
  541. trace_assign_type(field, entry);
  542. SEQ_PUT_FIELD_RET(s, field->arg1);
  543. SEQ_PUT_FIELD_RET(s, field->arg2);
  544. SEQ_PUT_FIELD_RET(s, field->arg3);
  545. return 0;
  546. }
  547. static struct trace_event trace_special_event = {
  548. .type = TRACE_SPECIAL,
  549. .trace = trace_special_print,
  550. .latency_trace = trace_special_print,
  551. .raw = trace_special_print,
  552. .hex = trace_special_hex,
  553. .binary = trace_special_bin,
  554. };
  555. /* TRACE_STACK */
  556. static int
  557. trace_stack_print(struct trace_seq *s, struct trace_entry *entry, int flags)
  558. {
  559. struct stack_entry *field;
  560. int i;
  561. trace_assign_type(field, entry);
  562. for (i = 0; i < FTRACE_STACK_ENTRIES; i++) {
  563. if (i) {
  564. if (!trace_seq_puts(s, " <= "))
  565. goto partial;
  566. if (!seq_print_ip_sym(s, field->caller[i], flags))
  567. goto partial;
  568. }
  569. if (!trace_seq_puts(s, "\n"))
  570. goto partial;
  571. }
  572. return 0;
  573. partial:
  574. return TRACE_TYPE_PARTIAL_LINE;
  575. }
  576. static struct trace_event trace_stack_event = {
  577. .type = TRACE_STACK,
  578. .trace = trace_stack_print,
  579. .latency_trace = trace_stack_print,
  580. .raw = trace_special_print,
  581. .hex = trace_special_hex,
  582. .binary = trace_special_bin,
  583. };
  584. /* TRACE_USER_STACK */
  585. static int
  586. trace_user_stack_print(struct trace_seq *s, struct trace_entry *entry,
  587. int flags)
  588. {
  589. struct userstack_entry *field;
  590. trace_assign_type(field, entry);
  591. if (!seq_print_userip_objs(field, s, flags))
  592. goto partial;
  593. if (!trace_seq_putc(s, '\n'))
  594. goto partial;
  595. return 0;
  596. partial:
  597. return TRACE_TYPE_PARTIAL_LINE;
  598. }
  599. static struct trace_event trace_user_stack_event = {
  600. .type = TRACE_USER_STACK,
  601. .trace = trace_user_stack_print,
  602. .latency_trace = trace_user_stack_print,
  603. .raw = trace_special_print,
  604. .hex = trace_special_hex,
  605. .binary = trace_special_bin,
  606. };
  607. /* TRACE_PRINT */
  608. static int
  609. trace_print_print(struct trace_seq *s, struct trace_entry *entry, int flags)
  610. {
  611. struct print_entry *field;
  612. trace_assign_type(field, entry);
  613. if (!seq_print_ip_sym(s, field->ip, flags))
  614. goto partial;
  615. if (!trace_seq_printf(s, ": %s", field->buf))
  616. goto partial;
  617. return 0;
  618. partial:
  619. return TRACE_TYPE_PARTIAL_LINE;
  620. }
  621. static int
  622. trace_print_raw(struct trace_seq *s, struct trace_entry *entry, int flags)
  623. {
  624. struct print_entry *field;
  625. trace_assign_type(field, entry);
  626. if (!trace_seq_printf(s, "# %lx %s", field->ip, field->buf))
  627. goto partial;
  628. return 0;
  629. partial:
  630. return TRACE_TYPE_PARTIAL_LINE;
  631. }
  632. static struct trace_event trace_print_event = {
  633. .type = TRACE_PRINT,
  634. .trace = trace_print_print,
  635. .latency_trace = trace_print_print,
  636. .raw = trace_print_raw,
  637. .hex = trace_nop_print,
  638. .binary = trace_nop_print,
  639. };
  640. static struct trace_event *events[] __initdata = {
  641. &trace_fn_event,
  642. &trace_ctx_event,
  643. &trace_wake_event,
  644. &trace_special_event,
  645. &trace_stack_event,
  646. &trace_user_stack_event,
  647. &trace_print_event,
  648. NULL
  649. };
  650. __init static int init_events(void)
  651. {
  652. struct trace_event *event;
  653. int i, ret;
  654. for (i = 0; events[i]; i++) {
  655. event = events[i];
  656. ret = register_ftrace_event(event);
  657. if (!ret) {
  658. printk(KERN_WARNING "event %d failed to register\n",
  659. event->type);
  660. WARN_ON_ONCE(1);
  661. }
  662. }
  663. return 0;
  664. }
  665. device_initcall(init_events);