trace_output.c 24 KB

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