trace_output.c 32 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507
  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. 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. int 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. int ret;
  20. ret = seq_write(m, s->buffer, len);
  21. /*
  22. * Only reset this buffer if we successfully wrote to the
  23. * seq_file buffer.
  24. */
  25. if (!ret)
  26. trace_seq_init(s);
  27. return ret;
  28. }
  29. enum print_line_t trace_print_bprintk_msg_only(struct trace_iterator *iter)
  30. {
  31. struct trace_seq *s = &iter->seq;
  32. struct trace_entry *entry = iter->ent;
  33. struct bprint_entry *field;
  34. int ret;
  35. trace_assign_type(field, entry);
  36. ret = trace_seq_bprintf(s, field->fmt, field->buf);
  37. if (!ret)
  38. return TRACE_TYPE_PARTIAL_LINE;
  39. return TRACE_TYPE_HANDLED;
  40. }
  41. enum print_line_t trace_print_printk_msg_only(struct trace_iterator *iter)
  42. {
  43. struct trace_seq *s = &iter->seq;
  44. struct trace_entry *entry = iter->ent;
  45. struct print_entry *field;
  46. int ret;
  47. trace_assign_type(field, entry);
  48. ret = trace_seq_printf(s, "%s", field->buf);
  49. if (!ret)
  50. return TRACE_TYPE_PARTIAL_LINE;
  51. return TRACE_TYPE_HANDLED;
  52. }
  53. /**
  54. * trace_seq_printf - sequence printing of trace information
  55. * @s: trace sequence descriptor
  56. * @fmt: printf format string
  57. *
  58. * It returns 0 if the trace oversizes the buffer's free
  59. * space, 1 otherwise.
  60. *
  61. * The tracer may use either sequence operations or its own
  62. * copy to user routines. To simplify formating of a trace
  63. * trace_seq_printf is used to store strings into a special
  64. * buffer (@s). Then the output may be either used by
  65. * the sequencer or pulled into another buffer.
  66. */
  67. int
  68. trace_seq_printf(struct trace_seq *s, const char *fmt, ...)
  69. {
  70. int len = (PAGE_SIZE - 1) - s->len;
  71. va_list ap;
  72. int ret;
  73. if (s->full || !len)
  74. return 0;
  75. va_start(ap, fmt);
  76. ret = vsnprintf(s->buffer + s->len, len, fmt, ap);
  77. va_end(ap);
  78. /* If we can't write it all, don't bother writing anything */
  79. if (ret >= len) {
  80. s->full = 1;
  81. return 0;
  82. }
  83. s->len += ret;
  84. return 1;
  85. }
  86. EXPORT_SYMBOL_GPL(trace_seq_printf);
  87. /**
  88. * trace_seq_vprintf - sequence printing of trace information
  89. * @s: trace sequence descriptor
  90. * @fmt: printf format string
  91. *
  92. * The tracer may use either sequence operations or its own
  93. * copy to user routines. To simplify formating of a trace
  94. * trace_seq_printf is used to store strings into a special
  95. * buffer (@s). Then the output may be either used by
  96. * the sequencer or pulled into another buffer.
  97. */
  98. int
  99. trace_seq_vprintf(struct trace_seq *s, const char *fmt, va_list args)
  100. {
  101. int len = (PAGE_SIZE - 1) - s->len;
  102. int ret;
  103. if (s->full || !len)
  104. return 0;
  105. ret = vsnprintf(s->buffer + s->len, len, fmt, args);
  106. /* If we can't write it all, don't bother writing anything */
  107. if (ret >= len) {
  108. s->full = 1;
  109. return 0;
  110. }
  111. s->len += ret;
  112. return len;
  113. }
  114. EXPORT_SYMBOL_GPL(trace_seq_vprintf);
  115. int trace_seq_bprintf(struct trace_seq *s, const char *fmt, const u32 *binary)
  116. {
  117. int len = (PAGE_SIZE - 1) - s->len;
  118. int ret;
  119. if (s->full || !len)
  120. return 0;
  121. ret = bstr_printf(s->buffer + s->len, len, fmt, binary);
  122. /* If we can't write it all, don't bother writing anything */
  123. if (ret >= len) {
  124. s->full = 1;
  125. return 0;
  126. }
  127. s->len += ret;
  128. return len;
  129. }
  130. /**
  131. * trace_seq_puts - trace sequence printing of simple string
  132. * @s: trace sequence descriptor
  133. * @str: simple string to record
  134. *
  135. * The tracer may use either the sequence operations or its own
  136. * copy to user routines. This function records a simple string
  137. * into a special buffer (@s) for later retrieval by a sequencer
  138. * or other mechanism.
  139. */
  140. int trace_seq_puts(struct trace_seq *s, const char *str)
  141. {
  142. int len = strlen(str);
  143. if (s->full)
  144. return 0;
  145. if (len > ((PAGE_SIZE - 1) - s->len)) {
  146. s->full = 1;
  147. return 0;
  148. }
  149. memcpy(s->buffer + s->len, str, len);
  150. s->len += len;
  151. return len;
  152. }
  153. int trace_seq_putc(struct trace_seq *s, unsigned char c)
  154. {
  155. if (s->full)
  156. return 0;
  157. if (s->len >= (PAGE_SIZE - 1)) {
  158. s->full = 1;
  159. return 0;
  160. }
  161. s->buffer[s->len++] = c;
  162. return 1;
  163. }
  164. EXPORT_SYMBOL(trace_seq_putc);
  165. int trace_seq_putmem(struct trace_seq *s, const void *mem, size_t len)
  166. {
  167. if (s->full)
  168. return 0;
  169. if (len > ((PAGE_SIZE - 1) - s->len)) {
  170. s->full = 1;
  171. return 0;
  172. }
  173. memcpy(s->buffer + s->len, mem, len);
  174. s->len += len;
  175. return len;
  176. }
  177. int trace_seq_putmem_hex(struct trace_seq *s, const void *mem, size_t len)
  178. {
  179. unsigned char hex[HEX_CHARS];
  180. const unsigned char *data = mem;
  181. int i, j;
  182. if (s->full)
  183. return 0;
  184. #ifdef __BIG_ENDIAN
  185. for (i = 0, j = 0; i < len; i++) {
  186. #else
  187. for (i = len-1, j = 0; i >= 0; i--) {
  188. #endif
  189. hex[j++] = hex_asc_hi(data[i]);
  190. hex[j++] = hex_asc_lo(data[i]);
  191. }
  192. hex[j++] = ' ';
  193. return trace_seq_putmem(s, hex, j);
  194. }
  195. void *trace_seq_reserve(struct trace_seq *s, size_t len)
  196. {
  197. void *ret;
  198. if (s->full)
  199. return NULL;
  200. if (len > ((PAGE_SIZE - 1) - s->len)) {
  201. s->full = 1;
  202. return NULL;
  203. }
  204. ret = s->buffer + s->len;
  205. s->len += len;
  206. return ret;
  207. }
  208. int trace_seq_path(struct trace_seq *s, const struct path *path)
  209. {
  210. unsigned char *p;
  211. if (s->full)
  212. return 0;
  213. if (s->len >= (PAGE_SIZE - 1)) {
  214. s->full = 1;
  215. return 0;
  216. }
  217. p = d_path(path, s->buffer + s->len, PAGE_SIZE - s->len);
  218. if (!IS_ERR(p)) {
  219. p = mangle_path(s->buffer + s->len, p, "\n");
  220. if (p) {
  221. s->len = p - s->buffer;
  222. return 1;
  223. }
  224. } else {
  225. s->buffer[s->len++] = '?';
  226. return 1;
  227. }
  228. s->full = 1;
  229. return 0;
  230. }
  231. const char *
  232. ftrace_print_flags_seq(struct trace_seq *p, const char *delim,
  233. unsigned long flags,
  234. const struct trace_print_flags *flag_array)
  235. {
  236. unsigned long mask;
  237. const char *str;
  238. const char *ret = p->buffer + p->len;
  239. int i, first = 1;
  240. for (i = 0; flag_array[i].name && flags; i++) {
  241. mask = flag_array[i].mask;
  242. if ((flags & mask) != mask)
  243. continue;
  244. str = flag_array[i].name;
  245. flags &= ~mask;
  246. if (!first && delim)
  247. trace_seq_puts(p, delim);
  248. else
  249. first = 0;
  250. trace_seq_puts(p, str);
  251. }
  252. /* check for left over flags */
  253. if (flags) {
  254. if (!first && delim)
  255. trace_seq_puts(p, delim);
  256. trace_seq_printf(p, "0x%lx", flags);
  257. }
  258. trace_seq_putc(p, 0);
  259. return ret;
  260. }
  261. EXPORT_SYMBOL(ftrace_print_flags_seq);
  262. const char *
  263. ftrace_print_symbols_seq(struct trace_seq *p, unsigned long val,
  264. const struct trace_print_flags *symbol_array)
  265. {
  266. int i;
  267. const char *ret = p->buffer + p->len;
  268. for (i = 0; symbol_array[i].name; i++) {
  269. if (val != symbol_array[i].mask)
  270. continue;
  271. trace_seq_puts(p, symbol_array[i].name);
  272. break;
  273. }
  274. if (ret == (const char *)(p->buffer + p->len))
  275. trace_seq_printf(p, "0x%lx", val);
  276. trace_seq_putc(p, 0);
  277. return ret;
  278. }
  279. EXPORT_SYMBOL(ftrace_print_symbols_seq);
  280. #if BITS_PER_LONG == 32
  281. const char *
  282. ftrace_print_symbols_seq_u64(struct trace_seq *p, unsigned long long val,
  283. const struct trace_print_flags_u64 *symbol_array)
  284. {
  285. int i;
  286. const char *ret = p->buffer + p->len;
  287. for (i = 0; symbol_array[i].name; i++) {
  288. if (val != symbol_array[i].mask)
  289. continue;
  290. trace_seq_puts(p, symbol_array[i].name);
  291. break;
  292. }
  293. if (ret == (const char *)(p->buffer + p->len))
  294. trace_seq_printf(p, "0x%llx", val);
  295. trace_seq_putc(p, 0);
  296. return ret;
  297. }
  298. EXPORT_SYMBOL(ftrace_print_symbols_seq_u64);
  299. #endif
  300. const char *
  301. ftrace_print_hex_seq(struct trace_seq *p, const unsigned char *buf, int buf_len)
  302. {
  303. int i;
  304. const char *ret = p->buffer + p->len;
  305. for (i = 0; i < buf_len; i++)
  306. trace_seq_printf(p, "%s%2.2x", i == 0 ? "" : " ", buf[i]);
  307. trace_seq_putc(p, 0);
  308. return ret;
  309. }
  310. EXPORT_SYMBOL(ftrace_print_hex_seq);
  311. #ifdef CONFIG_KRETPROBES
  312. static inline const char *kretprobed(const char *name)
  313. {
  314. static const char tramp_name[] = "kretprobe_trampoline";
  315. int size = sizeof(tramp_name);
  316. if (strncmp(tramp_name, name, size) == 0)
  317. return "[unknown/kretprobe'd]";
  318. return name;
  319. }
  320. #else
  321. static inline const char *kretprobed(const char *name)
  322. {
  323. return name;
  324. }
  325. #endif /* CONFIG_KRETPROBES */
  326. static int
  327. seq_print_sym_short(struct trace_seq *s, const char *fmt, unsigned long address)
  328. {
  329. #ifdef CONFIG_KALLSYMS
  330. char str[KSYM_SYMBOL_LEN];
  331. const char *name;
  332. kallsyms_lookup(address, NULL, NULL, NULL, str);
  333. name = kretprobed(str);
  334. return trace_seq_printf(s, fmt, name);
  335. #endif
  336. return 1;
  337. }
  338. static int
  339. seq_print_sym_offset(struct trace_seq *s, const char *fmt,
  340. unsigned long address)
  341. {
  342. #ifdef CONFIG_KALLSYMS
  343. char str[KSYM_SYMBOL_LEN];
  344. const char *name;
  345. sprint_symbol(str, address);
  346. name = kretprobed(str);
  347. return trace_seq_printf(s, fmt, name);
  348. #endif
  349. return 1;
  350. }
  351. #ifndef CONFIG_64BIT
  352. # define IP_FMT "%08lx"
  353. #else
  354. # define IP_FMT "%016lx"
  355. #endif
  356. int seq_print_user_ip(struct trace_seq *s, struct mm_struct *mm,
  357. unsigned long ip, unsigned long sym_flags)
  358. {
  359. struct file *file = NULL;
  360. unsigned long vmstart = 0;
  361. int ret = 1;
  362. if (s->full)
  363. return 0;
  364. if (mm) {
  365. const struct vm_area_struct *vma;
  366. down_read(&mm->mmap_sem);
  367. vma = find_vma(mm, ip);
  368. if (vma) {
  369. file = vma->vm_file;
  370. vmstart = vma->vm_start;
  371. }
  372. if (file) {
  373. ret = trace_seq_path(s, &file->f_path);
  374. if (ret)
  375. ret = trace_seq_printf(s, "[+0x%lx]",
  376. ip - vmstart);
  377. }
  378. up_read(&mm->mmap_sem);
  379. }
  380. if (ret && ((sym_flags & TRACE_ITER_SYM_ADDR) || !file))
  381. ret = trace_seq_printf(s, " <" IP_FMT ">", ip);
  382. return ret;
  383. }
  384. int
  385. seq_print_userip_objs(const struct userstack_entry *entry, struct trace_seq *s,
  386. unsigned long sym_flags)
  387. {
  388. struct mm_struct *mm = NULL;
  389. int ret = 1;
  390. unsigned int i;
  391. if (trace_flags & TRACE_ITER_SYM_USEROBJ) {
  392. struct task_struct *task;
  393. /*
  394. * we do the lookup on the thread group leader,
  395. * since individual threads might have already quit!
  396. */
  397. rcu_read_lock();
  398. task = find_task_by_vpid(entry->tgid);
  399. if (task)
  400. mm = get_task_mm(task);
  401. rcu_read_unlock();
  402. }
  403. for (i = 0; i < FTRACE_STACK_ENTRIES; i++) {
  404. unsigned long ip = entry->caller[i];
  405. if (ip == ULONG_MAX || !ret)
  406. break;
  407. if (ret)
  408. ret = trace_seq_puts(s, " => ");
  409. if (!ip) {
  410. if (ret)
  411. ret = trace_seq_puts(s, "??");
  412. if (ret)
  413. ret = trace_seq_puts(s, "\n");
  414. continue;
  415. }
  416. if (!ret)
  417. break;
  418. if (ret)
  419. ret = seq_print_user_ip(s, mm, ip, sym_flags);
  420. ret = trace_seq_puts(s, "\n");
  421. }
  422. if (mm)
  423. mmput(mm);
  424. return ret;
  425. }
  426. int
  427. seq_print_ip_sym(struct trace_seq *s, unsigned long ip, unsigned long sym_flags)
  428. {
  429. int ret;
  430. if (!ip)
  431. return trace_seq_printf(s, "0");
  432. if (sym_flags & TRACE_ITER_SYM_OFFSET)
  433. ret = seq_print_sym_offset(s, "%s", ip);
  434. else
  435. ret = seq_print_sym_short(s, "%s", ip);
  436. if (!ret)
  437. return 0;
  438. if (sym_flags & TRACE_ITER_SYM_ADDR)
  439. ret = trace_seq_printf(s, " <" IP_FMT ">", ip);
  440. return ret;
  441. }
  442. /**
  443. * trace_print_lat_fmt - print the irq, preempt and lockdep fields
  444. * @s: trace seq struct to write to
  445. * @entry: The trace entry field from the ring buffer
  446. *
  447. * Prints the generic fields of irqs off, in hard or softirq, preempt
  448. * count.
  449. */
  450. int trace_print_lat_fmt(struct trace_seq *s, struct trace_entry *entry)
  451. {
  452. char hardsoft_irq;
  453. char need_resched;
  454. char irqs_off;
  455. int hardirq;
  456. int softirq;
  457. int ret;
  458. hardirq = entry->flags & TRACE_FLAG_HARDIRQ;
  459. softirq = entry->flags & TRACE_FLAG_SOFTIRQ;
  460. irqs_off =
  461. (entry->flags & TRACE_FLAG_IRQS_OFF) ? 'd' :
  462. (entry->flags & TRACE_FLAG_IRQS_NOSUPPORT) ? 'X' :
  463. '.';
  464. need_resched =
  465. (entry->flags & TRACE_FLAG_NEED_RESCHED) ? 'N' : '.';
  466. hardsoft_irq =
  467. (hardirq && softirq) ? 'H' :
  468. hardirq ? 'h' :
  469. softirq ? 's' :
  470. '.';
  471. if (!trace_seq_printf(s, "%c%c%c",
  472. irqs_off, need_resched, hardsoft_irq))
  473. return 0;
  474. if (entry->preempt_count)
  475. ret = trace_seq_printf(s, "%x", entry->preempt_count);
  476. else
  477. ret = trace_seq_putc(s, '.');
  478. return ret;
  479. }
  480. static int
  481. lat_print_generic(struct trace_seq *s, struct trace_entry *entry, int cpu)
  482. {
  483. char comm[TASK_COMM_LEN];
  484. trace_find_cmdline(entry->pid, comm);
  485. if (!trace_seq_printf(s, "%8.8s-%-5d %3d",
  486. comm, entry->pid, cpu))
  487. return 0;
  488. return trace_print_lat_fmt(s, entry);
  489. }
  490. static unsigned long preempt_mark_thresh = 100;
  491. static int
  492. lat_print_timestamp(struct trace_seq *s, u64 abs_usecs,
  493. unsigned long rel_usecs)
  494. {
  495. return trace_seq_printf(s, " %4lldus%c: ", abs_usecs,
  496. rel_usecs > preempt_mark_thresh ? '!' :
  497. rel_usecs > 1 ? '+' : ' ');
  498. }
  499. int trace_print_context(struct trace_iterator *iter)
  500. {
  501. struct trace_seq *s = &iter->seq;
  502. struct trace_entry *entry = iter->ent;
  503. unsigned long long t = ns2usecs(iter->ts);
  504. unsigned long usec_rem = do_div(t, USEC_PER_SEC);
  505. unsigned long secs = (unsigned long)t;
  506. char comm[TASK_COMM_LEN];
  507. int ret;
  508. int tgid;
  509. trace_find_cmdline(entry->pid, comm);
  510. ret = trace_seq_printf(s, "%16s-%-5d ", comm, entry->pid);
  511. if (!ret)
  512. return 0;
  513. if (trace_flags & TRACE_ITER_TGID) {
  514. tgid = trace_find_tgid(entry->pid);
  515. if (tgid < 0)
  516. ret = trace_seq_puts(s, "(-----) ");
  517. else
  518. ret = trace_seq_printf(s, "(%5d) ", tgid);
  519. if (!ret)
  520. return 0;
  521. }
  522. ret = trace_seq_printf(s, "[%03d] ", iter->cpu);
  523. if (!ret)
  524. return 0;
  525. if (trace_flags & TRACE_ITER_IRQ_INFO) {
  526. ret = trace_print_lat_fmt(s, entry);
  527. if (!ret)
  528. return 0;
  529. }
  530. return trace_seq_printf(s, " %5lu.%06lu: ",
  531. secs, usec_rem);
  532. }
  533. int trace_print_lat_context(struct trace_iterator *iter)
  534. {
  535. u64 next_ts;
  536. int ret;
  537. /* trace_find_next_entry will reset ent_size */
  538. int ent_size = iter->ent_size;
  539. struct trace_seq *s = &iter->seq;
  540. struct trace_entry *entry = iter->ent,
  541. *next_entry = trace_find_next_entry(iter, NULL,
  542. &next_ts);
  543. unsigned long verbose = (trace_flags & TRACE_ITER_VERBOSE);
  544. unsigned long abs_usecs = ns2usecs(iter->ts - iter->tr->time_start);
  545. unsigned long rel_usecs;
  546. /* Restore the original ent_size */
  547. iter->ent_size = ent_size;
  548. if (!next_entry)
  549. next_ts = iter->ts;
  550. rel_usecs = ns2usecs(next_ts - iter->ts);
  551. if (verbose) {
  552. char comm[TASK_COMM_LEN];
  553. trace_find_cmdline(entry->pid, comm);
  554. ret = trace_seq_printf(s, "%16s %5d %3d %d %08x %08lx [%08llx]"
  555. " %ld.%03ldms (+%ld.%03ldms): ", comm,
  556. entry->pid, iter->cpu, entry->flags,
  557. entry->preempt_count, iter->idx,
  558. ns2usecs(iter->ts),
  559. abs_usecs / USEC_PER_MSEC,
  560. abs_usecs % USEC_PER_MSEC,
  561. rel_usecs / USEC_PER_MSEC,
  562. rel_usecs % USEC_PER_MSEC);
  563. } else {
  564. ret = lat_print_generic(s, entry, iter->cpu);
  565. if (ret)
  566. ret = lat_print_timestamp(s, abs_usecs, rel_usecs);
  567. }
  568. return ret;
  569. }
  570. static const char state_to_char[] = TASK_STATE_TO_CHAR_STR;
  571. static int task_state_char(unsigned long state)
  572. {
  573. int bit = state ? __ffs(state) + 1 : 0;
  574. return bit < sizeof(state_to_char) - 1 ? state_to_char[bit] : '?';
  575. }
  576. /**
  577. * ftrace_find_event - find a registered event
  578. * @type: the type of event to look for
  579. *
  580. * Returns an event of type @type otherwise NULL
  581. * Called with trace_event_read_lock() held.
  582. */
  583. struct trace_event *ftrace_find_event(int type)
  584. {
  585. struct trace_event *event;
  586. struct hlist_node *n;
  587. unsigned key;
  588. key = type & (EVENT_HASHSIZE - 1);
  589. hlist_for_each_entry(event, n, &event_hash[key], node) {
  590. if (event->type == type)
  591. return event;
  592. }
  593. return NULL;
  594. }
  595. static LIST_HEAD(ftrace_event_list);
  596. static int trace_search_list(struct list_head **list)
  597. {
  598. struct trace_event *e;
  599. int last = __TRACE_LAST_TYPE;
  600. if (list_empty(&ftrace_event_list)) {
  601. *list = &ftrace_event_list;
  602. return last + 1;
  603. }
  604. /*
  605. * We used up all possible max events,
  606. * lets see if somebody freed one.
  607. */
  608. list_for_each_entry(e, &ftrace_event_list, list) {
  609. if (e->type != last + 1)
  610. break;
  611. last++;
  612. }
  613. /* Did we used up all 65 thousand events??? */
  614. if ((last + 1) > FTRACE_MAX_EVENT)
  615. return 0;
  616. *list = &e->list;
  617. return last + 1;
  618. }
  619. void trace_event_read_lock(void)
  620. {
  621. down_read(&trace_event_mutex);
  622. }
  623. void trace_event_read_unlock(void)
  624. {
  625. up_read(&trace_event_mutex);
  626. }
  627. /**
  628. * register_ftrace_event - register output for an event type
  629. * @event: the event type to register
  630. *
  631. * Event types are stored in a hash and this hash is used to
  632. * find a way to print an event. If the @event->type is set
  633. * then it will use that type, otherwise it will assign a
  634. * type to use.
  635. *
  636. * If you assign your own type, please make sure it is added
  637. * to the trace_type enum in trace.h, to avoid collisions
  638. * with the dynamic types.
  639. *
  640. * Returns the event type number or zero on error.
  641. */
  642. int register_ftrace_event(struct trace_event *event)
  643. {
  644. unsigned key;
  645. int ret = 0;
  646. down_write(&trace_event_mutex);
  647. if (WARN_ON(!event))
  648. goto out;
  649. if (WARN_ON(!event->funcs))
  650. goto out;
  651. INIT_LIST_HEAD(&event->list);
  652. if (!event->type) {
  653. struct list_head *list = NULL;
  654. if (next_event_type > FTRACE_MAX_EVENT) {
  655. event->type = trace_search_list(&list);
  656. if (!event->type)
  657. goto out;
  658. } else {
  659. event->type = next_event_type++;
  660. list = &ftrace_event_list;
  661. }
  662. if (WARN_ON(ftrace_find_event(event->type)))
  663. goto out;
  664. list_add_tail(&event->list, list);
  665. } else if (event->type > __TRACE_LAST_TYPE) {
  666. printk(KERN_WARNING "Need to add type to trace.h\n");
  667. WARN_ON(1);
  668. goto out;
  669. } else {
  670. /* Is this event already used */
  671. if (ftrace_find_event(event->type))
  672. goto out;
  673. }
  674. if (event->funcs->trace == NULL)
  675. event->funcs->trace = trace_nop_print;
  676. if (event->funcs->raw == NULL)
  677. event->funcs->raw = trace_nop_print;
  678. if (event->funcs->hex == NULL)
  679. event->funcs->hex = trace_nop_print;
  680. if (event->funcs->binary == NULL)
  681. event->funcs->binary = trace_nop_print;
  682. key = event->type & (EVENT_HASHSIZE - 1);
  683. hlist_add_head(&event->node, &event_hash[key]);
  684. ret = event->type;
  685. out:
  686. up_write(&trace_event_mutex);
  687. return ret;
  688. }
  689. EXPORT_SYMBOL_GPL(register_ftrace_event);
  690. /*
  691. * Used by module code with the trace_event_mutex held for write.
  692. */
  693. int __unregister_ftrace_event(struct trace_event *event)
  694. {
  695. hlist_del(&event->node);
  696. list_del(&event->list);
  697. return 0;
  698. }
  699. /**
  700. * unregister_ftrace_event - remove a no longer used event
  701. * @event: the event to remove
  702. */
  703. int unregister_ftrace_event(struct trace_event *event)
  704. {
  705. down_write(&trace_event_mutex);
  706. __unregister_ftrace_event(event);
  707. up_write(&trace_event_mutex);
  708. return 0;
  709. }
  710. EXPORT_SYMBOL_GPL(unregister_ftrace_event);
  711. /*
  712. * Standard events
  713. */
  714. enum print_line_t trace_nop_print(struct trace_iterator *iter, int flags,
  715. struct trace_event *event)
  716. {
  717. if (!trace_seq_printf(&iter->seq, "type: %d\n", iter->ent->type))
  718. return TRACE_TYPE_PARTIAL_LINE;
  719. return TRACE_TYPE_HANDLED;
  720. }
  721. /* TRACE_FN */
  722. static enum print_line_t trace_fn_trace(struct trace_iterator *iter, int flags,
  723. struct trace_event *event)
  724. {
  725. struct ftrace_entry *field;
  726. struct trace_seq *s = &iter->seq;
  727. trace_assign_type(field, iter->ent);
  728. if (!seq_print_ip_sym(s, field->ip, flags))
  729. goto partial;
  730. if ((flags & TRACE_ITER_PRINT_PARENT) && field->parent_ip) {
  731. if (!trace_seq_printf(s, " <-"))
  732. goto partial;
  733. if (!seq_print_ip_sym(s,
  734. field->parent_ip,
  735. flags))
  736. goto partial;
  737. }
  738. if (!trace_seq_printf(s, "\n"))
  739. goto partial;
  740. return TRACE_TYPE_HANDLED;
  741. partial:
  742. return TRACE_TYPE_PARTIAL_LINE;
  743. }
  744. static enum print_line_t trace_fn_raw(struct trace_iterator *iter, int flags,
  745. struct trace_event *event)
  746. {
  747. struct ftrace_entry *field;
  748. trace_assign_type(field, iter->ent);
  749. if (!trace_seq_printf(&iter->seq, "%lx %lx\n",
  750. field->ip,
  751. field->parent_ip))
  752. return TRACE_TYPE_PARTIAL_LINE;
  753. return TRACE_TYPE_HANDLED;
  754. }
  755. static enum print_line_t trace_fn_hex(struct trace_iterator *iter, int flags,
  756. struct trace_event *event)
  757. {
  758. struct ftrace_entry *field;
  759. struct trace_seq *s = &iter->seq;
  760. trace_assign_type(field, iter->ent);
  761. SEQ_PUT_HEX_FIELD_RET(s, field->ip);
  762. SEQ_PUT_HEX_FIELD_RET(s, field->parent_ip);
  763. return TRACE_TYPE_HANDLED;
  764. }
  765. static enum print_line_t trace_fn_bin(struct trace_iterator *iter, int flags,
  766. struct trace_event *event)
  767. {
  768. struct ftrace_entry *field;
  769. struct trace_seq *s = &iter->seq;
  770. trace_assign_type(field, iter->ent);
  771. SEQ_PUT_FIELD_RET(s, field->ip);
  772. SEQ_PUT_FIELD_RET(s, field->parent_ip);
  773. return TRACE_TYPE_HANDLED;
  774. }
  775. static struct trace_event_functions trace_fn_funcs = {
  776. .trace = trace_fn_trace,
  777. .raw = trace_fn_raw,
  778. .hex = trace_fn_hex,
  779. .binary = trace_fn_bin,
  780. };
  781. static struct trace_event trace_fn_event = {
  782. .type = TRACE_FN,
  783. .funcs = &trace_fn_funcs,
  784. };
  785. /* TRACE_GRAPH_ENT */
  786. static enum print_line_t trace_graph_ent_trace(struct trace_iterator *iter, int flags,
  787. struct trace_event *event)
  788. {
  789. struct trace_seq *s = &iter->seq;
  790. struct ftrace_graph_ent_entry *field;
  791. trace_assign_type(field, iter->ent);
  792. if (!trace_seq_puts(s, "graph_ent: func="))
  793. return TRACE_TYPE_PARTIAL_LINE;
  794. if (!seq_print_ip_sym(s, field->graph_ent.func, flags))
  795. return TRACE_TYPE_PARTIAL_LINE;
  796. if (!trace_seq_puts(s, "\n"))
  797. return TRACE_TYPE_PARTIAL_LINE;
  798. return TRACE_TYPE_HANDLED;
  799. }
  800. static enum print_line_t trace_graph_ent_raw(struct trace_iterator *iter, int flags,
  801. struct trace_event *event)
  802. {
  803. struct ftrace_graph_ent_entry *field;
  804. trace_assign_type(field, iter->ent);
  805. if (!trace_seq_printf(&iter->seq, "%lx %d\n",
  806. field->graph_ent.func,
  807. field->graph_ent.depth))
  808. return TRACE_TYPE_PARTIAL_LINE;
  809. return TRACE_TYPE_HANDLED;
  810. }
  811. static enum print_line_t trace_graph_ent_hex(struct trace_iterator *iter, int flags,
  812. struct trace_event *event)
  813. {
  814. struct ftrace_graph_ent_entry *field;
  815. struct trace_seq *s = &iter->seq;
  816. trace_assign_type(field, iter->ent);
  817. SEQ_PUT_HEX_FIELD_RET(s, field->graph_ent.func);
  818. SEQ_PUT_HEX_FIELD_RET(s, field->graph_ent.depth);
  819. return TRACE_TYPE_HANDLED;
  820. }
  821. static enum print_line_t trace_graph_ent_bin(struct trace_iterator *iter, int flags,
  822. struct trace_event *event)
  823. {
  824. struct ftrace_graph_ent_entry *field;
  825. struct trace_seq *s = &iter->seq;
  826. trace_assign_type(field, iter->ent);
  827. SEQ_PUT_FIELD_RET(s, field->graph_ent.func);
  828. SEQ_PUT_FIELD_RET(s, field->graph_ent.depth);
  829. return TRACE_TYPE_HANDLED;
  830. }
  831. static struct trace_event_functions trace_graph_ent_funcs = {
  832. .trace = trace_graph_ent_trace,
  833. .raw = trace_graph_ent_raw,
  834. .hex = trace_graph_ent_hex,
  835. .binary = trace_graph_ent_bin,
  836. };
  837. static struct trace_event trace_graph_ent_event = {
  838. .type = TRACE_GRAPH_ENT,
  839. .funcs = &trace_graph_ent_funcs,
  840. };
  841. /* TRACE_GRAPH_RET */
  842. static enum print_line_t trace_graph_ret_trace(struct trace_iterator *iter, int flags,
  843. struct trace_event *event)
  844. {
  845. struct trace_seq *s = &iter->seq;
  846. struct trace_entry *entry = iter->ent;
  847. struct ftrace_graph_ret_entry *field;
  848. trace_assign_type(field, entry);
  849. if (!trace_seq_puts(s, "graph_ret: func="))
  850. return TRACE_TYPE_PARTIAL_LINE;
  851. if (!seq_print_ip_sym(s, field->ret.func, flags))
  852. return TRACE_TYPE_PARTIAL_LINE;
  853. if (!trace_seq_puts(s, "\n"))
  854. return TRACE_TYPE_PARTIAL_LINE;
  855. return TRACE_TYPE_HANDLED;
  856. }
  857. static enum print_line_t trace_graph_ret_raw(struct trace_iterator *iter, int flags,
  858. struct trace_event *event)
  859. {
  860. struct ftrace_graph_ret_entry *field;
  861. trace_assign_type(field, iter->ent);
  862. if (!trace_seq_printf(&iter->seq, "%lx %lld %lld %ld %d\n",
  863. field->ret.func,
  864. field->ret.calltime,
  865. field->ret.rettime,
  866. field->ret.overrun,
  867. field->ret.depth));
  868. return TRACE_TYPE_PARTIAL_LINE;
  869. return TRACE_TYPE_HANDLED;
  870. }
  871. static enum print_line_t trace_graph_ret_hex(struct trace_iterator *iter, int flags,
  872. struct trace_event *event)
  873. {
  874. struct ftrace_graph_ret_entry *field;
  875. struct trace_seq *s = &iter->seq;
  876. trace_assign_type(field, iter->ent);
  877. SEQ_PUT_HEX_FIELD_RET(s, field->ret.func);
  878. SEQ_PUT_HEX_FIELD_RET(s, field->ret.calltime);
  879. SEQ_PUT_HEX_FIELD_RET(s, field->ret.rettime);
  880. SEQ_PUT_HEX_FIELD_RET(s, field->ret.overrun);
  881. SEQ_PUT_HEX_FIELD_RET(s, field->ret.depth);
  882. return TRACE_TYPE_HANDLED;
  883. }
  884. static enum print_line_t trace_graph_ret_bin(struct trace_iterator *iter, int flags,
  885. struct trace_event *event)
  886. {
  887. struct ftrace_graph_ret_entry *field;
  888. struct trace_seq *s = &iter->seq;
  889. trace_assign_type(field, iter->ent);
  890. SEQ_PUT_FIELD_RET(s, field->ret.func);
  891. SEQ_PUT_FIELD_RET(s, field->ret.calltime);
  892. SEQ_PUT_FIELD_RET(s, field->ret.rettime);
  893. SEQ_PUT_FIELD_RET(s, field->ret.overrun);
  894. SEQ_PUT_FIELD_RET(s, field->ret.depth);
  895. return TRACE_TYPE_HANDLED;
  896. }
  897. static struct trace_event_functions trace_graph_ret_funcs = {
  898. .trace = trace_graph_ret_trace,
  899. .raw = trace_graph_ret_raw,
  900. .hex = trace_graph_ret_hex,
  901. .binary = trace_graph_ret_bin,
  902. };
  903. static struct trace_event trace_graph_ret_event = {
  904. .type = TRACE_GRAPH_RET,
  905. .funcs = &trace_graph_ret_funcs,
  906. };
  907. /* TRACE_CTX an TRACE_WAKE */
  908. static enum print_line_t trace_ctxwake_print(struct trace_iterator *iter,
  909. char *delim)
  910. {
  911. struct ctx_switch_entry *field;
  912. char comm[TASK_COMM_LEN];
  913. int S, T;
  914. trace_assign_type(field, iter->ent);
  915. T = task_state_char(field->next_state);
  916. S = task_state_char(field->prev_state);
  917. trace_find_cmdline(field->next_pid, comm);
  918. if (!trace_seq_printf(&iter->seq,
  919. " %5d:%3d:%c %s [%03d] %5d:%3d:%c %s\n",
  920. field->prev_pid,
  921. field->prev_prio,
  922. S, delim,
  923. field->next_cpu,
  924. field->next_pid,
  925. field->next_prio,
  926. T, comm))
  927. return TRACE_TYPE_PARTIAL_LINE;
  928. return TRACE_TYPE_HANDLED;
  929. }
  930. static enum print_line_t trace_ctx_print(struct trace_iterator *iter, int flags,
  931. struct trace_event *event)
  932. {
  933. return trace_ctxwake_print(iter, "==>");
  934. }
  935. static enum print_line_t trace_wake_print(struct trace_iterator *iter,
  936. int flags, struct trace_event *event)
  937. {
  938. return trace_ctxwake_print(iter, " +");
  939. }
  940. static int trace_ctxwake_raw(struct trace_iterator *iter, char S)
  941. {
  942. struct ctx_switch_entry *field;
  943. int T;
  944. trace_assign_type(field, iter->ent);
  945. if (!S)
  946. S = task_state_char(field->prev_state);
  947. T = task_state_char(field->next_state);
  948. if (!trace_seq_printf(&iter->seq, "%d %d %c %d %d %d %c\n",
  949. field->prev_pid,
  950. field->prev_prio,
  951. S,
  952. field->next_cpu,
  953. field->next_pid,
  954. field->next_prio,
  955. T))
  956. return TRACE_TYPE_PARTIAL_LINE;
  957. return TRACE_TYPE_HANDLED;
  958. }
  959. static enum print_line_t trace_ctx_raw(struct trace_iterator *iter, int flags,
  960. struct trace_event *event)
  961. {
  962. return trace_ctxwake_raw(iter, 0);
  963. }
  964. static enum print_line_t trace_wake_raw(struct trace_iterator *iter, int flags,
  965. struct trace_event *event)
  966. {
  967. return trace_ctxwake_raw(iter, '+');
  968. }
  969. static int trace_ctxwake_hex(struct trace_iterator *iter, char S)
  970. {
  971. struct ctx_switch_entry *field;
  972. struct trace_seq *s = &iter->seq;
  973. int T;
  974. trace_assign_type(field, iter->ent);
  975. if (!S)
  976. S = task_state_char(field->prev_state);
  977. T = task_state_char(field->next_state);
  978. SEQ_PUT_HEX_FIELD_RET(s, field->prev_pid);
  979. SEQ_PUT_HEX_FIELD_RET(s, field->prev_prio);
  980. SEQ_PUT_HEX_FIELD_RET(s, S);
  981. SEQ_PUT_HEX_FIELD_RET(s, field->next_cpu);
  982. SEQ_PUT_HEX_FIELD_RET(s, field->next_pid);
  983. SEQ_PUT_HEX_FIELD_RET(s, field->next_prio);
  984. SEQ_PUT_HEX_FIELD_RET(s, T);
  985. return TRACE_TYPE_HANDLED;
  986. }
  987. static enum print_line_t trace_ctx_hex(struct trace_iterator *iter, int flags,
  988. struct trace_event *event)
  989. {
  990. return trace_ctxwake_hex(iter, 0);
  991. }
  992. static enum print_line_t trace_wake_hex(struct trace_iterator *iter, int flags,
  993. struct trace_event *event)
  994. {
  995. return trace_ctxwake_hex(iter, '+');
  996. }
  997. static enum print_line_t trace_ctxwake_bin(struct trace_iterator *iter,
  998. int flags, struct trace_event *event)
  999. {
  1000. struct ctx_switch_entry *field;
  1001. struct trace_seq *s = &iter->seq;
  1002. trace_assign_type(field, iter->ent);
  1003. SEQ_PUT_FIELD_RET(s, field->prev_pid);
  1004. SEQ_PUT_FIELD_RET(s, field->prev_prio);
  1005. SEQ_PUT_FIELD_RET(s, field->prev_state);
  1006. SEQ_PUT_FIELD_RET(s, field->next_pid);
  1007. SEQ_PUT_FIELD_RET(s, field->next_prio);
  1008. SEQ_PUT_FIELD_RET(s, field->next_state);
  1009. return TRACE_TYPE_HANDLED;
  1010. }
  1011. static struct trace_event_functions trace_ctx_funcs = {
  1012. .trace = trace_ctx_print,
  1013. .raw = trace_ctx_raw,
  1014. .hex = trace_ctx_hex,
  1015. .binary = trace_ctxwake_bin,
  1016. };
  1017. static struct trace_event trace_ctx_event = {
  1018. .type = TRACE_CTX,
  1019. .funcs = &trace_ctx_funcs,
  1020. };
  1021. static struct trace_event_functions trace_wake_funcs = {
  1022. .trace = trace_wake_print,
  1023. .raw = trace_wake_raw,
  1024. .hex = trace_wake_hex,
  1025. .binary = trace_ctxwake_bin,
  1026. };
  1027. static struct trace_event trace_wake_event = {
  1028. .type = TRACE_WAKE,
  1029. .funcs = &trace_wake_funcs,
  1030. };
  1031. /* TRACE_STACK */
  1032. static enum print_line_t trace_stack_print(struct trace_iterator *iter,
  1033. int flags, struct trace_event *event)
  1034. {
  1035. struct stack_entry *field;
  1036. struct trace_seq *s = &iter->seq;
  1037. unsigned long *p;
  1038. unsigned long *end;
  1039. trace_assign_type(field, iter->ent);
  1040. end = (unsigned long *)((long)iter->ent + iter->ent_size);
  1041. if (!trace_seq_puts(s, "<stack trace>\n"))
  1042. goto partial;
  1043. for (p = field->caller; p && *p != ULONG_MAX && p < end; p++) {
  1044. if (!trace_seq_puts(s, " => "))
  1045. goto partial;
  1046. if (!seq_print_ip_sym(s, *p, flags))
  1047. goto partial;
  1048. if (!trace_seq_puts(s, "\n"))
  1049. goto partial;
  1050. }
  1051. return TRACE_TYPE_HANDLED;
  1052. partial:
  1053. return TRACE_TYPE_PARTIAL_LINE;
  1054. }
  1055. static struct trace_event_functions trace_stack_funcs = {
  1056. .trace = trace_stack_print,
  1057. };
  1058. static struct trace_event trace_stack_event = {
  1059. .type = TRACE_STACK,
  1060. .funcs = &trace_stack_funcs,
  1061. };
  1062. /* TRACE_USER_STACK */
  1063. static enum print_line_t trace_user_stack_print(struct trace_iterator *iter,
  1064. int flags, struct trace_event *event)
  1065. {
  1066. struct userstack_entry *field;
  1067. struct trace_seq *s = &iter->seq;
  1068. trace_assign_type(field, iter->ent);
  1069. if (!trace_seq_puts(s, "<user stack trace>\n"))
  1070. goto partial;
  1071. if (!seq_print_userip_objs(field, s, flags))
  1072. goto partial;
  1073. return TRACE_TYPE_HANDLED;
  1074. partial:
  1075. return TRACE_TYPE_PARTIAL_LINE;
  1076. }
  1077. static struct trace_event_functions trace_user_stack_funcs = {
  1078. .trace = trace_user_stack_print,
  1079. };
  1080. static struct trace_event trace_user_stack_event = {
  1081. .type = TRACE_USER_STACK,
  1082. .funcs = &trace_user_stack_funcs,
  1083. };
  1084. /* TRACE_BPRINT */
  1085. static enum print_line_t
  1086. trace_bprint_print(struct trace_iterator *iter, int flags,
  1087. struct trace_event *event)
  1088. {
  1089. struct trace_entry *entry = iter->ent;
  1090. struct trace_seq *s = &iter->seq;
  1091. struct bprint_entry *field;
  1092. trace_assign_type(field, entry);
  1093. if (!seq_print_ip_sym(s, field->ip, flags))
  1094. goto partial;
  1095. if (!trace_seq_puts(s, ": "))
  1096. goto partial;
  1097. if (!trace_seq_bprintf(s, field->fmt, field->buf))
  1098. goto partial;
  1099. return TRACE_TYPE_HANDLED;
  1100. partial:
  1101. return TRACE_TYPE_PARTIAL_LINE;
  1102. }
  1103. static enum print_line_t
  1104. trace_bprint_raw(struct trace_iterator *iter, int flags,
  1105. struct trace_event *event)
  1106. {
  1107. struct bprint_entry *field;
  1108. struct trace_seq *s = &iter->seq;
  1109. trace_assign_type(field, iter->ent);
  1110. if (!trace_seq_printf(s, ": %lx : ", field->ip))
  1111. goto partial;
  1112. if (!trace_seq_bprintf(s, field->fmt, field->buf))
  1113. goto partial;
  1114. return TRACE_TYPE_HANDLED;
  1115. partial:
  1116. return TRACE_TYPE_PARTIAL_LINE;
  1117. }
  1118. static struct trace_event_functions trace_bprint_funcs = {
  1119. .trace = trace_bprint_print,
  1120. .raw = trace_bprint_raw,
  1121. };
  1122. static struct trace_event trace_bprint_event = {
  1123. .type = TRACE_BPRINT,
  1124. .funcs = &trace_bprint_funcs,
  1125. };
  1126. /* TRACE_PRINT */
  1127. static enum print_line_t trace_print_print(struct trace_iterator *iter,
  1128. int flags, struct trace_event *event)
  1129. {
  1130. struct print_entry *field;
  1131. struct trace_seq *s = &iter->seq;
  1132. trace_assign_type(field, iter->ent);
  1133. if (!seq_print_ip_sym(s, field->ip, flags))
  1134. goto partial;
  1135. if (!trace_seq_printf(s, ": %s", field->buf))
  1136. goto partial;
  1137. return TRACE_TYPE_HANDLED;
  1138. partial:
  1139. return TRACE_TYPE_PARTIAL_LINE;
  1140. }
  1141. static enum print_line_t trace_print_raw(struct trace_iterator *iter, int flags,
  1142. struct trace_event *event)
  1143. {
  1144. struct print_entry *field;
  1145. trace_assign_type(field, iter->ent);
  1146. if (!trace_seq_printf(&iter->seq, "# %lx %s", field->ip, field->buf))
  1147. goto partial;
  1148. return TRACE_TYPE_HANDLED;
  1149. partial:
  1150. return TRACE_TYPE_PARTIAL_LINE;
  1151. }
  1152. static struct trace_event_functions trace_print_funcs = {
  1153. .trace = trace_print_print,
  1154. .raw = trace_print_raw,
  1155. };
  1156. static struct trace_event trace_print_event = {
  1157. .type = TRACE_PRINT,
  1158. .funcs = &trace_print_funcs,
  1159. };
  1160. static struct trace_event *events[] __initdata = {
  1161. &trace_fn_event,
  1162. &trace_graph_ent_event,
  1163. &trace_graph_ret_event,
  1164. &trace_ctx_event,
  1165. &trace_wake_event,
  1166. &trace_stack_event,
  1167. &trace_user_stack_event,
  1168. &trace_bprint_event,
  1169. &trace_print_event,
  1170. NULL
  1171. };
  1172. __init static int init_events(void)
  1173. {
  1174. struct trace_event *event;
  1175. int i, ret;
  1176. for (i = 0; events[i]; i++) {
  1177. event = events[i];
  1178. ret = register_ftrace_event(event);
  1179. if (!ret) {
  1180. printk(KERN_WARNING "event %d failed to register\n",
  1181. event->type);
  1182. WARN_ON_ONCE(1);
  1183. }
  1184. }
  1185. return 0;
  1186. }
  1187. device_initcall(init_events);