trace_output.c 23 KB

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