trace_output.c 23 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094
  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. 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. * Called with trace_event_read_lock() held.
  380. */
  381. struct trace_event *ftrace_find_event(int type)
  382. {
  383. struct trace_event *event;
  384. struct hlist_node *n;
  385. unsigned key;
  386. key = type & (EVENT_HASHSIZE - 1);
  387. hlist_for_each_entry(event, n, &event_hash[key], node) {
  388. if (event->type == type)
  389. return event;
  390. }
  391. return NULL;
  392. }
  393. static LIST_HEAD(ftrace_event_list);
  394. static int trace_search_list(struct list_head **list)
  395. {
  396. struct trace_event *e;
  397. int last = __TRACE_LAST_TYPE;
  398. if (list_empty(&ftrace_event_list)) {
  399. *list = &ftrace_event_list;
  400. return last + 1;
  401. }
  402. /*
  403. * We used up all possible max events,
  404. * lets see if somebody freed one.
  405. */
  406. list_for_each_entry(e, &ftrace_event_list, list) {
  407. if (e->type != last + 1)
  408. break;
  409. last++;
  410. }
  411. /* Did we used up all 65 thousand events??? */
  412. if ((last + 1) > FTRACE_MAX_EVENT)
  413. return 0;
  414. *list = &e->list;
  415. return last + 1;
  416. }
  417. void trace_event_read_lock(void)
  418. {
  419. down_read(&trace_event_mutex);
  420. }
  421. void trace_event_read_unlock(void)
  422. {
  423. up_read(&trace_event_mutex);
  424. }
  425. /**
  426. * register_ftrace_event - register output for an event type
  427. * @event: the event type to register
  428. *
  429. * Event types are stored in a hash and this hash is used to
  430. * find a way to print an event. If the @event->type is set
  431. * then it will use that type, otherwise it will assign a
  432. * type to use.
  433. *
  434. * If you assign your own type, please make sure it is added
  435. * to the trace_type enum in trace.h, to avoid collisions
  436. * with the dynamic types.
  437. *
  438. * Returns the event type number or zero on error.
  439. */
  440. int register_ftrace_event(struct trace_event *event)
  441. {
  442. unsigned key;
  443. int ret = 0;
  444. down_write(&trace_event_mutex);
  445. if (WARN_ON(!event))
  446. goto out;
  447. INIT_LIST_HEAD(&event->list);
  448. if (!event->type) {
  449. struct list_head *list = NULL;
  450. if (next_event_type > FTRACE_MAX_EVENT) {
  451. event->type = trace_search_list(&list);
  452. if (!event->type)
  453. goto out;
  454. } else {
  455. event->type = next_event_type++;
  456. list = &ftrace_event_list;
  457. }
  458. if (WARN_ON(ftrace_find_event(event->type)))
  459. goto out;
  460. list_add_tail(&event->list, list);
  461. } else if (event->type > __TRACE_LAST_TYPE) {
  462. printk(KERN_WARNING "Need to add type to trace.h\n");
  463. WARN_ON(1);
  464. goto out;
  465. } else {
  466. /* Is this event already used */
  467. if (ftrace_find_event(event->type))
  468. goto out;
  469. }
  470. if (event->trace == NULL)
  471. event->trace = trace_nop_print;
  472. if (event->raw == NULL)
  473. event->raw = trace_nop_print;
  474. if (event->hex == NULL)
  475. event->hex = trace_nop_print;
  476. if (event->binary == NULL)
  477. event->binary = trace_nop_print;
  478. key = event->type & (EVENT_HASHSIZE - 1);
  479. hlist_add_head(&event->node, &event_hash[key]);
  480. ret = event->type;
  481. out:
  482. up_write(&trace_event_mutex);
  483. return ret;
  484. }
  485. EXPORT_SYMBOL_GPL(register_ftrace_event);
  486. /**
  487. * unregister_ftrace_event - remove a no longer used event
  488. * @event: the event to remove
  489. */
  490. int unregister_ftrace_event(struct trace_event *event)
  491. {
  492. down_write(&trace_event_mutex);
  493. hlist_del(&event->node);
  494. list_del(&event->list);
  495. up_write(&trace_event_mutex);
  496. return 0;
  497. }
  498. EXPORT_SYMBOL_GPL(unregister_ftrace_event);
  499. /*
  500. * Standard events
  501. */
  502. enum print_line_t trace_nop_print(struct trace_iterator *iter, int flags)
  503. {
  504. return TRACE_TYPE_HANDLED;
  505. }
  506. /* TRACE_FN */
  507. static enum print_line_t trace_fn_trace(struct trace_iterator *iter, int flags)
  508. {
  509. struct ftrace_entry *field;
  510. struct trace_seq *s = &iter->seq;
  511. trace_assign_type(field, iter->ent);
  512. if (!seq_print_ip_sym(s, field->ip, flags))
  513. goto partial;
  514. if ((flags & TRACE_ITER_PRINT_PARENT) && field->parent_ip) {
  515. if (!trace_seq_printf(s, " <-"))
  516. goto partial;
  517. if (!seq_print_ip_sym(s,
  518. field->parent_ip,
  519. flags))
  520. goto partial;
  521. }
  522. if (!trace_seq_printf(s, "\n"))
  523. goto partial;
  524. return TRACE_TYPE_HANDLED;
  525. partial:
  526. return TRACE_TYPE_PARTIAL_LINE;
  527. }
  528. static enum print_line_t trace_fn_raw(struct trace_iterator *iter, int flags)
  529. {
  530. struct ftrace_entry *field;
  531. trace_assign_type(field, iter->ent);
  532. if (!trace_seq_printf(&iter->seq, "%lx %lx\n",
  533. field->ip,
  534. field->parent_ip))
  535. return TRACE_TYPE_PARTIAL_LINE;
  536. return TRACE_TYPE_HANDLED;
  537. }
  538. static enum print_line_t trace_fn_hex(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_HEX_FIELD_RET(s, field->ip);
  544. SEQ_PUT_HEX_FIELD_RET(s, field->parent_ip);
  545. return TRACE_TYPE_HANDLED;
  546. }
  547. static enum print_line_t trace_fn_bin(struct trace_iterator *iter, int flags)
  548. {
  549. struct ftrace_entry *field;
  550. struct trace_seq *s = &iter->seq;
  551. trace_assign_type(field, iter->ent);
  552. SEQ_PUT_FIELD_RET(s, field->ip);
  553. SEQ_PUT_FIELD_RET(s, field->parent_ip);
  554. return TRACE_TYPE_HANDLED;
  555. }
  556. static struct trace_event trace_fn_event = {
  557. .type = TRACE_FN,
  558. .trace = trace_fn_trace,
  559. .raw = trace_fn_raw,
  560. .hex = trace_fn_hex,
  561. .binary = trace_fn_bin,
  562. };
  563. /* TRACE_CTX an TRACE_WAKE */
  564. static enum print_line_t trace_ctxwake_print(struct trace_iterator *iter,
  565. char *delim)
  566. {
  567. struct ctx_switch_entry *field;
  568. char comm[TASK_COMM_LEN];
  569. int S, T;
  570. trace_assign_type(field, iter->ent);
  571. T = task_state_char(field->next_state);
  572. S = task_state_char(field->prev_state);
  573. trace_find_cmdline(field->next_pid, comm);
  574. if (!trace_seq_printf(&iter->seq,
  575. " %5d:%3d:%c %s [%03d] %5d:%3d:%c %s\n",
  576. field->prev_pid,
  577. field->prev_prio,
  578. S, delim,
  579. field->next_cpu,
  580. field->next_pid,
  581. field->next_prio,
  582. T, comm))
  583. return TRACE_TYPE_PARTIAL_LINE;
  584. return TRACE_TYPE_HANDLED;
  585. }
  586. static enum print_line_t trace_ctx_print(struct trace_iterator *iter, int flags)
  587. {
  588. return trace_ctxwake_print(iter, "==>");
  589. }
  590. static enum print_line_t trace_wake_print(struct trace_iterator *iter,
  591. int flags)
  592. {
  593. return trace_ctxwake_print(iter, " +");
  594. }
  595. static int trace_ctxwake_raw(struct trace_iterator *iter, char S)
  596. {
  597. struct ctx_switch_entry *field;
  598. int T;
  599. trace_assign_type(field, iter->ent);
  600. if (!S)
  601. task_state_char(field->prev_state);
  602. T = task_state_char(field->next_state);
  603. if (!trace_seq_printf(&iter->seq, "%d %d %c %d %d %d %c\n",
  604. field->prev_pid,
  605. field->prev_prio,
  606. S,
  607. field->next_cpu,
  608. field->next_pid,
  609. field->next_prio,
  610. T))
  611. return TRACE_TYPE_PARTIAL_LINE;
  612. return TRACE_TYPE_HANDLED;
  613. }
  614. static enum print_line_t trace_ctx_raw(struct trace_iterator *iter, int flags)
  615. {
  616. return trace_ctxwake_raw(iter, 0);
  617. }
  618. static enum print_line_t trace_wake_raw(struct trace_iterator *iter, int flags)
  619. {
  620. return trace_ctxwake_raw(iter, '+');
  621. }
  622. static int trace_ctxwake_hex(struct trace_iterator *iter, char S)
  623. {
  624. struct ctx_switch_entry *field;
  625. struct trace_seq *s = &iter->seq;
  626. int T;
  627. trace_assign_type(field, iter->ent);
  628. if (!S)
  629. task_state_char(field->prev_state);
  630. T = task_state_char(field->next_state);
  631. SEQ_PUT_HEX_FIELD_RET(s, field->prev_pid);
  632. SEQ_PUT_HEX_FIELD_RET(s, field->prev_prio);
  633. SEQ_PUT_HEX_FIELD_RET(s, S);
  634. SEQ_PUT_HEX_FIELD_RET(s, field->next_cpu);
  635. SEQ_PUT_HEX_FIELD_RET(s, field->next_pid);
  636. SEQ_PUT_HEX_FIELD_RET(s, field->next_prio);
  637. SEQ_PUT_HEX_FIELD_RET(s, T);
  638. return TRACE_TYPE_HANDLED;
  639. }
  640. static enum print_line_t trace_ctx_hex(struct trace_iterator *iter, int flags)
  641. {
  642. return trace_ctxwake_hex(iter, 0);
  643. }
  644. static enum print_line_t trace_wake_hex(struct trace_iterator *iter, int flags)
  645. {
  646. return trace_ctxwake_hex(iter, '+');
  647. }
  648. static enum print_line_t trace_ctxwake_bin(struct trace_iterator *iter,
  649. int flags)
  650. {
  651. struct ctx_switch_entry *field;
  652. struct trace_seq *s = &iter->seq;
  653. trace_assign_type(field, iter->ent);
  654. SEQ_PUT_FIELD_RET(s, field->prev_pid);
  655. SEQ_PUT_FIELD_RET(s, field->prev_prio);
  656. SEQ_PUT_FIELD_RET(s, field->prev_state);
  657. SEQ_PUT_FIELD_RET(s, field->next_pid);
  658. SEQ_PUT_FIELD_RET(s, field->next_prio);
  659. SEQ_PUT_FIELD_RET(s, field->next_state);
  660. return TRACE_TYPE_HANDLED;
  661. }
  662. static struct trace_event trace_ctx_event = {
  663. .type = TRACE_CTX,
  664. .trace = trace_ctx_print,
  665. .raw = trace_ctx_raw,
  666. .hex = trace_ctx_hex,
  667. .binary = trace_ctxwake_bin,
  668. };
  669. static struct trace_event trace_wake_event = {
  670. .type = TRACE_WAKE,
  671. .trace = trace_wake_print,
  672. .raw = trace_wake_raw,
  673. .hex = trace_wake_hex,
  674. .binary = trace_ctxwake_bin,
  675. };
  676. /* TRACE_SPECIAL */
  677. static enum print_line_t trace_special_print(struct trace_iterator *iter,
  678. int flags)
  679. {
  680. struct special_entry *field;
  681. trace_assign_type(field, iter->ent);
  682. if (!trace_seq_printf(&iter->seq, "# %ld %ld %ld\n",
  683. field->arg1,
  684. field->arg2,
  685. field->arg3))
  686. return TRACE_TYPE_PARTIAL_LINE;
  687. return TRACE_TYPE_HANDLED;
  688. }
  689. static enum print_line_t trace_special_hex(struct trace_iterator *iter,
  690. int flags)
  691. {
  692. struct special_entry *field;
  693. struct trace_seq *s = &iter->seq;
  694. trace_assign_type(field, iter->ent);
  695. SEQ_PUT_HEX_FIELD_RET(s, field->arg1);
  696. SEQ_PUT_HEX_FIELD_RET(s, field->arg2);
  697. SEQ_PUT_HEX_FIELD_RET(s, field->arg3);
  698. return TRACE_TYPE_HANDLED;
  699. }
  700. static enum print_line_t trace_special_bin(struct trace_iterator *iter,
  701. int flags)
  702. {
  703. struct special_entry *field;
  704. struct trace_seq *s = &iter->seq;
  705. trace_assign_type(field, iter->ent);
  706. SEQ_PUT_FIELD_RET(s, field->arg1);
  707. SEQ_PUT_FIELD_RET(s, field->arg2);
  708. SEQ_PUT_FIELD_RET(s, field->arg3);
  709. return TRACE_TYPE_HANDLED;
  710. }
  711. static struct trace_event trace_special_event = {
  712. .type = TRACE_SPECIAL,
  713. .trace = trace_special_print,
  714. .raw = trace_special_print,
  715. .hex = trace_special_hex,
  716. .binary = trace_special_bin,
  717. };
  718. /* TRACE_STACK */
  719. static enum print_line_t trace_stack_print(struct trace_iterator *iter,
  720. int flags)
  721. {
  722. struct stack_entry *field;
  723. struct trace_seq *s = &iter->seq;
  724. int i;
  725. trace_assign_type(field, iter->ent);
  726. for (i = 0; i < FTRACE_STACK_ENTRIES; i++) {
  727. if (!field->caller[i])
  728. break;
  729. if (i) {
  730. if (!trace_seq_puts(s, " <= "))
  731. goto partial;
  732. if (!seq_print_ip_sym(s, field->caller[i], flags))
  733. goto partial;
  734. }
  735. if (!trace_seq_puts(s, "\n"))
  736. goto partial;
  737. }
  738. return TRACE_TYPE_HANDLED;
  739. partial:
  740. return TRACE_TYPE_PARTIAL_LINE;
  741. }
  742. static struct trace_event trace_stack_event = {
  743. .type = TRACE_STACK,
  744. .trace = trace_stack_print,
  745. .raw = trace_special_print,
  746. .hex = trace_special_hex,
  747. .binary = trace_special_bin,
  748. };
  749. /* TRACE_USER_STACK */
  750. static enum print_line_t trace_user_stack_print(struct trace_iterator *iter,
  751. int flags)
  752. {
  753. struct userstack_entry *field;
  754. struct trace_seq *s = &iter->seq;
  755. trace_assign_type(field, iter->ent);
  756. if (!seq_print_userip_objs(field, s, flags))
  757. goto partial;
  758. if (!trace_seq_putc(s, '\n'))
  759. goto partial;
  760. return TRACE_TYPE_HANDLED;
  761. partial:
  762. return TRACE_TYPE_PARTIAL_LINE;
  763. }
  764. static struct trace_event trace_user_stack_event = {
  765. .type = TRACE_USER_STACK,
  766. .trace = trace_user_stack_print,
  767. .raw = trace_special_print,
  768. .hex = trace_special_hex,
  769. .binary = trace_special_bin,
  770. };
  771. /* TRACE_BPRINT */
  772. static enum print_line_t
  773. trace_bprint_print(struct trace_iterator *iter, int flags)
  774. {
  775. struct trace_entry *entry = iter->ent;
  776. struct trace_seq *s = &iter->seq;
  777. struct bprint_entry *field;
  778. trace_assign_type(field, entry);
  779. if (!seq_print_ip_sym(s, field->ip, flags))
  780. goto partial;
  781. if (!trace_seq_puts(s, ": "))
  782. goto partial;
  783. if (!trace_seq_bprintf(s, field->fmt, field->buf))
  784. goto partial;
  785. return TRACE_TYPE_HANDLED;
  786. partial:
  787. return TRACE_TYPE_PARTIAL_LINE;
  788. }
  789. static enum print_line_t
  790. trace_bprint_raw(struct trace_iterator *iter, int flags)
  791. {
  792. struct bprint_entry *field;
  793. struct trace_seq *s = &iter->seq;
  794. trace_assign_type(field, iter->ent);
  795. if (!trace_seq_printf(s, ": %lx : ", field->ip))
  796. goto partial;
  797. if (!trace_seq_bprintf(s, field->fmt, field->buf))
  798. goto partial;
  799. return TRACE_TYPE_HANDLED;
  800. partial:
  801. return TRACE_TYPE_PARTIAL_LINE;
  802. }
  803. static struct trace_event trace_bprint_event = {
  804. .type = TRACE_BPRINT,
  805. .trace = trace_bprint_print,
  806. .raw = trace_bprint_raw,
  807. };
  808. /* TRACE_PRINT */
  809. static enum print_line_t trace_print_print(struct trace_iterator *iter,
  810. int flags)
  811. {
  812. struct print_entry *field;
  813. struct trace_seq *s = &iter->seq;
  814. trace_assign_type(field, iter->ent);
  815. if (!seq_print_ip_sym(s, field->ip, flags))
  816. goto partial;
  817. if (!trace_seq_printf(s, ": %s", field->buf))
  818. goto partial;
  819. return TRACE_TYPE_HANDLED;
  820. partial:
  821. return TRACE_TYPE_PARTIAL_LINE;
  822. }
  823. static enum print_line_t trace_print_raw(struct trace_iterator *iter, int flags)
  824. {
  825. struct print_entry *field;
  826. trace_assign_type(field, iter->ent);
  827. if (!trace_seq_printf(&iter->seq, "# %lx %s", field->ip, field->buf))
  828. goto partial;
  829. return TRACE_TYPE_HANDLED;
  830. partial:
  831. return TRACE_TYPE_PARTIAL_LINE;
  832. }
  833. static struct trace_event trace_print_event = {
  834. .type = TRACE_PRINT,
  835. .trace = trace_print_print,
  836. .raw = trace_print_raw,
  837. };
  838. static struct trace_event *events[] __initdata = {
  839. &trace_fn_event,
  840. &trace_ctx_event,
  841. &trace_wake_event,
  842. &trace_special_event,
  843. &trace_stack_event,
  844. &trace_user_stack_event,
  845. &trace_bprint_event,
  846. &trace_print_event,
  847. NULL
  848. };
  849. __init static int init_events(void)
  850. {
  851. struct trace_event *event;
  852. int i, ret;
  853. for (i = 0; events[i]; i++) {
  854. event = events[i];
  855. ret = register_ftrace_event(event);
  856. if (!ret) {
  857. printk(KERN_WARNING "event %d failed to register\n",
  858. event->type);
  859. WARN_ON_ONCE(1);
  860. }
  861. }
  862. return 0;
  863. }
  864. device_initcall(init_events);