trace_output.c 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164
  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 (ret)
  310. ret = trace_seq_puts(s, " => ");
  311. if (!ip) {
  312. if (ret)
  313. ret = trace_seq_puts(s, "??");
  314. if (ret)
  315. ret = trace_seq_puts(s, "\n");
  316. continue;
  317. }
  318. if (!ret)
  319. break;
  320. if (ret)
  321. ret = seq_print_user_ip(s, mm, ip, sym_flags);
  322. ret = trace_seq_puts(s, "\n");
  323. }
  324. if (mm)
  325. mmput(mm);
  326. return ret;
  327. }
  328. int
  329. seq_print_ip_sym(struct trace_seq *s, unsigned long ip, unsigned long sym_flags)
  330. {
  331. int ret;
  332. if (!ip)
  333. return trace_seq_printf(s, "0");
  334. if (sym_flags & TRACE_ITER_SYM_OFFSET)
  335. ret = seq_print_sym_offset(s, "%s", ip);
  336. else
  337. ret = seq_print_sym_short(s, "%s", ip);
  338. if (!ret)
  339. return 0;
  340. if (sym_flags & TRACE_ITER_SYM_ADDR)
  341. ret = trace_seq_printf(s, " <" IP_FMT ">", ip);
  342. return ret;
  343. }
  344. static int
  345. lat_print_generic(struct trace_seq *s, struct trace_entry *entry, int cpu)
  346. {
  347. int hardirq, softirq;
  348. char comm[TASK_COMM_LEN];
  349. trace_find_cmdline(entry->pid, comm);
  350. hardirq = entry->flags & TRACE_FLAG_HARDIRQ;
  351. softirq = entry->flags & TRACE_FLAG_SOFTIRQ;
  352. if (!trace_seq_printf(s, "%8.8s-%-5d %3d%c%c%c",
  353. comm, entry->pid, cpu,
  354. (entry->flags & TRACE_FLAG_IRQS_OFF) ? 'd' :
  355. (entry->flags & TRACE_FLAG_IRQS_NOSUPPORT) ?
  356. 'X' : '.',
  357. (entry->flags & TRACE_FLAG_NEED_RESCHED) ?
  358. 'N' : '.',
  359. (hardirq && softirq) ? 'H' :
  360. hardirq ? 'h' : softirq ? 's' : '.'))
  361. return 0;
  362. if (entry->preempt_count)
  363. return trace_seq_printf(s, "%x", entry->preempt_count);
  364. return trace_seq_puts(s, ".");
  365. }
  366. static unsigned long preempt_mark_thresh = 100;
  367. static int
  368. lat_print_timestamp(struct trace_seq *s, u64 abs_usecs,
  369. unsigned long rel_usecs)
  370. {
  371. return trace_seq_printf(s, " %4lldus%c: ", abs_usecs,
  372. rel_usecs > preempt_mark_thresh ? '!' :
  373. rel_usecs > 1 ? '+' : ' ');
  374. }
  375. int trace_print_context(struct trace_iterator *iter)
  376. {
  377. struct trace_seq *s = &iter->seq;
  378. struct trace_entry *entry = iter->ent;
  379. unsigned long long t = ns2usecs(iter->ts);
  380. unsigned long usec_rem = do_div(t, USEC_PER_SEC);
  381. unsigned long secs = (unsigned long)t;
  382. char comm[TASK_COMM_LEN];
  383. trace_find_cmdline(entry->pid, comm);
  384. return trace_seq_printf(s, "%16s-%-5d [%03d] %5lu.%06lu: ",
  385. comm, entry->pid, iter->cpu, secs, usec_rem);
  386. }
  387. int trace_print_lat_context(struct trace_iterator *iter)
  388. {
  389. u64 next_ts;
  390. int ret;
  391. struct trace_seq *s = &iter->seq;
  392. struct trace_entry *entry = iter->ent,
  393. *next_entry = trace_find_next_entry(iter, NULL,
  394. &next_ts);
  395. unsigned long verbose = (trace_flags & TRACE_ITER_VERBOSE);
  396. unsigned long abs_usecs = ns2usecs(iter->ts - iter->tr->time_start);
  397. unsigned long rel_usecs;
  398. if (!next_entry)
  399. next_ts = iter->ts;
  400. rel_usecs = ns2usecs(next_ts - iter->ts);
  401. if (verbose) {
  402. char comm[TASK_COMM_LEN];
  403. trace_find_cmdline(entry->pid, comm);
  404. ret = trace_seq_printf(s, "%16s %5d %3d %d %08x %08lx [%08llx]"
  405. " %ld.%03ldms (+%ld.%03ldms): ", comm,
  406. entry->pid, iter->cpu, entry->flags,
  407. entry->preempt_count, iter->idx,
  408. ns2usecs(iter->ts),
  409. abs_usecs / USEC_PER_MSEC,
  410. abs_usecs % USEC_PER_MSEC,
  411. rel_usecs / USEC_PER_MSEC,
  412. rel_usecs % USEC_PER_MSEC);
  413. } else {
  414. ret = lat_print_generic(s, entry, iter->cpu);
  415. if (ret)
  416. ret = lat_print_timestamp(s, abs_usecs, rel_usecs);
  417. }
  418. return ret;
  419. }
  420. static const char state_to_char[] = TASK_STATE_TO_CHAR_STR;
  421. static int task_state_char(unsigned long state)
  422. {
  423. int bit = state ? __ffs(state) + 1 : 0;
  424. return bit < sizeof(state_to_char) - 1 ? state_to_char[bit] : '?';
  425. }
  426. /**
  427. * ftrace_find_event - find a registered event
  428. * @type: the type of event to look for
  429. *
  430. * Returns an event of type @type otherwise NULL
  431. * Called with trace_event_read_lock() held.
  432. */
  433. struct trace_event *ftrace_find_event(int type)
  434. {
  435. struct trace_event *event;
  436. struct hlist_node *n;
  437. unsigned key;
  438. key = type & (EVENT_HASHSIZE - 1);
  439. hlist_for_each_entry(event, n, &event_hash[key], node) {
  440. if (event->type == type)
  441. return event;
  442. }
  443. return NULL;
  444. }
  445. static LIST_HEAD(ftrace_event_list);
  446. static int trace_search_list(struct list_head **list)
  447. {
  448. struct trace_event *e;
  449. int last = __TRACE_LAST_TYPE;
  450. if (list_empty(&ftrace_event_list)) {
  451. *list = &ftrace_event_list;
  452. return last + 1;
  453. }
  454. /*
  455. * We used up all possible max events,
  456. * lets see if somebody freed one.
  457. */
  458. list_for_each_entry(e, &ftrace_event_list, list) {
  459. if (e->type != last + 1)
  460. break;
  461. last++;
  462. }
  463. /* Did we used up all 65 thousand events??? */
  464. if ((last + 1) > FTRACE_MAX_EVENT)
  465. return 0;
  466. *list = &e->list;
  467. return last + 1;
  468. }
  469. void trace_event_read_lock(void)
  470. {
  471. down_read(&trace_event_mutex);
  472. }
  473. void trace_event_read_unlock(void)
  474. {
  475. up_read(&trace_event_mutex);
  476. }
  477. /**
  478. * register_ftrace_event - register output for an event type
  479. * @event: the event type to register
  480. *
  481. * Event types are stored in a hash and this hash is used to
  482. * find a way to print an event. If the @event->type is set
  483. * then it will use that type, otherwise it will assign a
  484. * type to use.
  485. *
  486. * If you assign your own type, please make sure it is added
  487. * to the trace_type enum in trace.h, to avoid collisions
  488. * with the dynamic types.
  489. *
  490. * Returns the event type number or zero on error.
  491. */
  492. int register_ftrace_event(struct trace_event *event)
  493. {
  494. unsigned key;
  495. int ret = 0;
  496. down_write(&trace_event_mutex);
  497. if (WARN_ON(!event))
  498. goto out;
  499. INIT_LIST_HEAD(&event->list);
  500. if (!event->type) {
  501. struct list_head *list = NULL;
  502. if (next_event_type > FTRACE_MAX_EVENT) {
  503. event->type = trace_search_list(&list);
  504. if (!event->type)
  505. goto out;
  506. } else {
  507. event->type = next_event_type++;
  508. list = &ftrace_event_list;
  509. }
  510. if (WARN_ON(ftrace_find_event(event->type)))
  511. goto out;
  512. list_add_tail(&event->list, list);
  513. } else if (event->type > __TRACE_LAST_TYPE) {
  514. printk(KERN_WARNING "Need to add type to trace.h\n");
  515. WARN_ON(1);
  516. goto out;
  517. } else {
  518. /* Is this event already used */
  519. if (ftrace_find_event(event->type))
  520. goto out;
  521. }
  522. if (event->trace == NULL)
  523. event->trace = trace_nop_print;
  524. if (event->raw == NULL)
  525. event->raw = trace_nop_print;
  526. if (event->hex == NULL)
  527. event->hex = trace_nop_print;
  528. if (event->binary == NULL)
  529. event->binary = trace_nop_print;
  530. key = event->type & (EVENT_HASHSIZE - 1);
  531. hlist_add_head(&event->node, &event_hash[key]);
  532. ret = event->type;
  533. out:
  534. up_write(&trace_event_mutex);
  535. return ret;
  536. }
  537. EXPORT_SYMBOL_GPL(register_ftrace_event);
  538. /**
  539. * unregister_ftrace_event - remove a no longer used event
  540. * @event: the event to remove
  541. */
  542. int unregister_ftrace_event(struct trace_event *event)
  543. {
  544. down_write(&trace_event_mutex);
  545. hlist_del(&event->node);
  546. list_del(&event->list);
  547. up_write(&trace_event_mutex);
  548. return 0;
  549. }
  550. EXPORT_SYMBOL_GPL(unregister_ftrace_event);
  551. /*
  552. * Standard events
  553. */
  554. enum print_line_t trace_nop_print(struct trace_iterator *iter, int flags)
  555. {
  556. return TRACE_TYPE_HANDLED;
  557. }
  558. /* TRACE_FN */
  559. static enum print_line_t trace_fn_trace(struct trace_iterator *iter, int flags)
  560. {
  561. struct ftrace_entry *field;
  562. struct trace_seq *s = &iter->seq;
  563. trace_assign_type(field, iter->ent);
  564. if (!seq_print_ip_sym(s, field->ip, flags))
  565. goto partial;
  566. if ((flags & TRACE_ITER_PRINT_PARENT) && field->parent_ip) {
  567. if (!trace_seq_printf(s, " <-"))
  568. goto partial;
  569. if (!seq_print_ip_sym(s,
  570. field->parent_ip,
  571. flags))
  572. goto partial;
  573. }
  574. if (!trace_seq_printf(s, "\n"))
  575. goto partial;
  576. return TRACE_TYPE_HANDLED;
  577. partial:
  578. return TRACE_TYPE_PARTIAL_LINE;
  579. }
  580. static enum print_line_t trace_fn_raw(struct trace_iterator *iter, int flags)
  581. {
  582. struct ftrace_entry *field;
  583. trace_assign_type(field, iter->ent);
  584. if (!trace_seq_printf(&iter->seq, "%lx %lx\n",
  585. field->ip,
  586. field->parent_ip))
  587. return TRACE_TYPE_PARTIAL_LINE;
  588. return TRACE_TYPE_HANDLED;
  589. }
  590. static enum print_line_t trace_fn_hex(struct trace_iterator *iter, int flags)
  591. {
  592. struct ftrace_entry *field;
  593. struct trace_seq *s = &iter->seq;
  594. trace_assign_type(field, iter->ent);
  595. SEQ_PUT_HEX_FIELD_RET(s, field->ip);
  596. SEQ_PUT_HEX_FIELD_RET(s, field->parent_ip);
  597. return TRACE_TYPE_HANDLED;
  598. }
  599. static enum print_line_t trace_fn_bin(struct trace_iterator *iter, int flags)
  600. {
  601. struct ftrace_entry *field;
  602. struct trace_seq *s = &iter->seq;
  603. trace_assign_type(field, iter->ent);
  604. SEQ_PUT_FIELD_RET(s, field->ip);
  605. SEQ_PUT_FIELD_RET(s, field->parent_ip);
  606. return TRACE_TYPE_HANDLED;
  607. }
  608. static struct trace_event trace_fn_event = {
  609. .type = TRACE_FN,
  610. .trace = trace_fn_trace,
  611. .raw = trace_fn_raw,
  612. .hex = trace_fn_hex,
  613. .binary = trace_fn_bin,
  614. };
  615. /* TRACE_CTX an TRACE_WAKE */
  616. static enum print_line_t trace_ctxwake_print(struct trace_iterator *iter,
  617. char *delim)
  618. {
  619. struct ctx_switch_entry *field;
  620. char comm[TASK_COMM_LEN];
  621. int S, T;
  622. trace_assign_type(field, iter->ent);
  623. T = task_state_char(field->next_state);
  624. S = task_state_char(field->prev_state);
  625. trace_find_cmdline(field->next_pid, comm);
  626. if (!trace_seq_printf(&iter->seq,
  627. " %5d:%3d:%c %s [%03d] %5d:%3d:%c %s\n",
  628. field->prev_pid,
  629. field->prev_prio,
  630. S, delim,
  631. field->next_cpu,
  632. field->next_pid,
  633. field->next_prio,
  634. T, comm))
  635. return TRACE_TYPE_PARTIAL_LINE;
  636. return TRACE_TYPE_HANDLED;
  637. }
  638. static enum print_line_t trace_ctx_print(struct trace_iterator *iter, int flags)
  639. {
  640. return trace_ctxwake_print(iter, "==>");
  641. }
  642. static enum print_line_t trace_wake_print(struct trace_iterator *iter,
  643. int flags)
  644. {
  645. return trace_ctxwake_print(iter, " +");
  646. }
  647. static int trace_ctxwake_raw(struct trace_iterator *iter, char S)
  648. {
  649. struct ctx_switch_entry *field;
  650. int T;
  651. trace_assign_type(field, iter->ent);
  652. if (!S)
  653. task_state_char(field->prev_state);
  654. T = task_state_char(field->next_state);
  655. if (!trace_seq_printf(&iter->seq, "%d %d %c %d %d %d %c\n",
  656. field->prev_pid,
  657. field->prev_prio,
  658. S,
  659. field->next_cpu,
  660. field->next_pid,
  661. field->next_prio,
  662. T))
  663. return TRACE_TYPE_PARTIAL_LINE;
  664. return TRACE_TYPE_HANDLED;
  665. }
  666. static enum print_line_t trace_ctx_raw(struct trace_iterator *iter, int flags)
  667. {
  668. return trace_ctxwake_raw(iter, 0);
  669. }
  670. static enum print_line_t trace_wake_raw(struct trace_iterator *iter, int flags)
  671. {
  672. return trace_ctxwake_raw(iter, '+');
  673. }
  674. static int trace_ctxwake_hex(struct trace_iterator *iter, char S)
  675. {
  676. struct ctx_switch_entry *field;
  677. struct trace_seq *s = &iter->seq;
  678. int T;
  679. trace_assign_type(field, iter->ent);
  680. if (!S)
  681. task_state_char(field->prev_state);
  682. T = task_state_char(field->next_state);
  683. SEQ_PUT_HEX_FIELD_RET(s, field->prev_pid);
  684. SEQ_PUT_HEX_FIELD_RET(s, field->prev_prio);
  685. SEQ_PUT_HEX_FIELD_RET(s, S);
  686. SEQ_PUT_HEX_FIELD_RET(s, field->next_cpu);
  687. SEQ_PUT_HEX_FIELD_RET(s, field->next_pid);
  688. SEQ_PUT_HEX_FIELD_RET(s, field->next_prio);
  689. SEQ_PUT_HEX_FIELD_RET(s, T);
  690. return TRACE_TYPE_HANDLED;
  691. }
  692. static enum print_line_t trace_ctx_hex(struct trace_iterator *iter, int flags)
  693. {
  694. return trace_ctxwake_hex(iter, 0);
  695. }
  696. static enum print_line_t trace_wake_hex(struct trace_iterator *iter, int flags)
  697. {
  698. return trace_ctxwake_hex(iter, '+');
  699. }
  700. static enum print_line_t trace_ctxwake_bin(struct trace_iterator *iter,
  701. int flags)
  702. {
  703. struct ctx_switch_entry *field;
  704. struct trace_seq *s = &iter->seq;
  705. trace_assign_type(field, iter->ent);
  706. SEQ_PUT_FIELD_RET(s, field->prev_pid);
  707. SEQ_PUT_FIELD_RET(s, field->prev_prio);
  708. SEQ_PUT_FIELD_RET(s, field->prev_state);
  709. SEQ_PUT_FIELD_RET(s, field->next_pid);
  710. SEQ_PUT_FIELD_RET(s, field->next_prio);
  711. SEQ_PUT_FIELD_RET(s, field->next_state);
  712. return TRACE_TYPE_HANDLED;
  713. }
  714. static struct trace_event trace_ctx_event = {
  715. .type = TRACE_CTX,
  716. .trace = trace_ctx_print,
  717. .raw = trace_ctx_raw,
  718. .hex = trace_ctx_hex,
  719. .binary = trace_ctxwake_bin,
  720. };
  721. static struct trace_event trace_wake_event = {
  722. .type = TRACE_WAKE,
  723. .trace = trace_wake_print,
  724. .raw = trace_wake_raw,
  725. .hex = trace_wake_hex,
  726. .binary = trace_ctxwake_bin,
  727. };
  728. /* TRACE_SPECIAL */
  729. static enum print_line_t trace_special_print(struct trace_iterator *iter,
  730. int flags)
  731. {
  732. struct special_entry *field;
  733. trace_assign_type(field, iter->ent);
  734. if (!trace_seq_printf(&iter->seq, "# %ld %ld %ld\n",
  735. field->arg1,
  736. field->arg2,
  737. field->arg3))
  738. return TRACE_TYPE_PARTIAL_LINE;
  739. return TRACE_TYPE_HANDLED;
  740. }
  741. static enum print_line_t trace_special_hex(struct trace_iterator *iter,
  742. int flags)
  743. {
  744. struct special_entry *field;
  745. struct trace_seq *s = &iter->seq;
  746. trace_assign_type(field, iter->ent);
  747. SEQ_PUT_HEX_FIELD_RET(s, field->arg1);
  748. SEQ_PUT_HEX_FIELD_RET(s, field->arg2);
  749. SEQ_PUT_HEX_FIELD_RET(s, field->arg3);
  750. return TRACE_TYPE_HANDLED;
  751. }
  752. static enum print_line_t trace_special_bin(struct trace_iterator *iter,
  753. int flags)
  754. {
  755. struct special_entry *field;
  756. struct trace_seq *s = &iter->seq;
  757. trace_assign_type(field, iter->ent);
  758. SEQ_PUT_FIELD_RET(s, field->arg1);
  759. SEQ_PUT_FIELD_RET(s, field->arg2);
  760. SEQ_PUT_FIELD_RET(s, field->arg3);
  761. return TRACE_TYPE_HANDLED;
  762. }
  763. static struct trace_event trace_special_event = {
  764. .type = TRACE_SPECIAL,
  765. .trace = trace_special_print,
  766. .raw = trace_special_print,
  767. .hex = trace_special_hex,
  768. .binary = trace_special_bin,
  769. };
  770. /* TRACE_STACK */
  771. static enum print_line_t trace_stack_print(struct trace_iterator *iter,
  772. int flags)
  773. {
  774. struct stack_entry *field;
  775. struct trace_seq *s = &iter->seq;
  776. int i;
  777. trace_assign_type(field, iter->ent);
  778. if (!trace_seq_puts(s, "\n"))
  779. goto partial;
  780. for (i = 0; i < FTRACE_STACK_ENTRIES; i++) {
  781. if (!field->caller[i] || (field->caller[i] == ULONG_MAX))
  782. break;
  783. if (!trace_seq_puts(s, " => "))
  784. goto partial;
  785. if (!seq_print_ip_sym(s, field->caller[i], flags))
  786. goto partial;
  787. if (!trace_seq_puts(s, "\n"))
  788. goto partial;
  789. }
  790. return TRACE_TYPE_HANDLED;
  791. partial:
  792. return TRACE_TYPE_PARTIAL_LINE;
  793. }
  794. static struct trace_event trace_stack_event = {
  795. .type = TRACE_STACK,
  796. .trace = trace_stack_print,
  797. .raw = trace_special_print,
  798. .hex = trace_special_hex,
  799. .binary = trace_special_bin,
  800. };
  801. /* TRACE_USER_STACK */
  802. static enum print_line_t trace_user_stack_print(struct trace_iterator *iter,
  803. int flags)
  804. {
  805. struct userstack_entry *field;
  806. struct trace_seq *s = &iter->seq;
  807. trace_assign_type(field, iter->ent);
  808. if (!trace_seq_putc(s, '\n'))
  809. goto partial;
  810. if (!seq_print_userip_objs(field, s, flags))
  811. goto partial;
  812. return TRACE_TYPE_HANDLED;
  813. partial:
  814. return TRACE_TYPE_PARTIAL_LINE;
  815. }
  816. static struct trace_event trace_user_stack_event = {
  817. .type = TRACE_USER_STACK,
  818. .trace = trace_user_stack_print,
  819. .raw = trace_special_print,
  820. .hex = trace_special_hex,
  821. .binary = trace_special_bin,
  822. };
  823. /* TRACE_BPRINT */
  824. static enum print_line_t
  825. trace_bprint_print(struct trace_iterator *iter, int flags)
  826. {
  827. struct trace_entry *entry = iter->ent;
  828. struct trace_seq *s = &iter->seq;
  829. struct bprint_entry *field;
  830. trace_assign_type(field, entry);
  831. if (!seq_print_ip_sym(s, field->ip, flags))
  832. goto partial;
  833. if (!trace_seq_puts(s, ": "))
  834. goto partial;
  835. if (!trace_seq_bprintf(s, field->fmt, field->buf))
  836. goto partial;
  837. return TRACE_TYPE_HANDLED;
  838. partial:
  839. return TRACE_TYPE_PARTIAL_LINE;
  840. }
  841. static enum print_line_t
  842. trace_bprint_raw(struct trace_iterator *iter, int flags)
  843. {
  844. struct bprint_entry *field;
  845. struct trace_seq *s = &iter->seq;
  846. trace_assign_type(field, iter->ent);
  847. if (!trace_seq_printf(s, ": %lx : ", field->ip))
  848. goto partial;
  849. if (!trace_seq_bprintf(s, field->fmt, field->buf))
  850. goto partial;
  851. return TRACE_TYPE_HANDLED;
  852. partial:
  853. return TRACE_TYPE_PARTIAL_LINE;
  854. }
  855. static struct trace_event trace_bprint_event = {
  856. .type = TRACE_BPRINT,
  857. .trace = trace_bprint_print,
  858. .raw = trace_bprint_raw,
  859. };
  860. /* TRACE_PRINT */
  861. static enum print_line_t trace_print_print(struct trace_iterator *iter,
  862. int flags)
  863. {
  864. struct print_entry *field;
  865. struct trace_seq *s = &iter->seq;
  866. trace_assign_type(field, iter->ent);
  867. if (!seq_print_ip_sym(s, field->ip, flags))
  868. goto partial;
  869. if (!trace_seq_printf(s, ": %s", field->buf))
  870. goto partial;
  871. return TRACE_TYPE_HANDLED;
  872. partial:
  873. return TRACE_TYPE_PARTIAL_LINE;
  874. }
  875. static enum print_line_t trace_print_raw(struct trace_iterator *iter, int flags)
  876. {
  877. struct print_entry *field;
  878. trace_assign_type(field, iter->ent);
  879. if (!trace_seq_printf(&iter->seq, "# %lx %s", field->ip, field->buf))
  880. goto partial;
  881. return TRACE_TYPE_HANDLED;
  882. partial:
  883. return TRACE_TYPE_PARTIAL_LINE;
  884. }
  885. static struct trace_event trace_print_event = {
  886. .type = TRACE_PRINT,
  887. .trace = trace_print_print,
  888. .raw = trace_print_raw,
  889. };
  890. static struct trace_event *events[] __initdata = {
  891. &trace_fn_event,
  892. &trace_ctx_event,
  893. &trace_wake_event,
  894. &trace_special_event,
  895. &trace_stack_event,
  896. &trace_user_stack_event,
  897. &trace_bprint_event,
  898. &trace_print_event,
  899. NULL
  900. };
  901. __init static int init_events(void)
  902. {
  903. struct trace_event *event;
  904. int i, ret;
  905. for (i = 0; events[i]; i++) {
  906. event = events[i];
  907. ret = register_ftrace_event(event);
  908. if (!ret) {
  909. printk(KERN_WARNING "event %d failed to register\n",
  910. event->type);
  911. WARN_ON_ONCE(1);
  912. }
  913. }
  914. return 0;
  915. }
  916. device_initcall(init_events);