trace_kdb.c 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. /*
  2. * kdb helper for dumping the ftrace buffer
  3. *
  4. * Copyright (C) 2010 Jason Wessel <jason.wessel@windriver.com>
  5. *
  6. * ftrace_dump_buf based on ftrace_dump:
  7. * Copyright (C) 2007-2008 Steven Rostedt <srostedt@redhat.com>
  8. * Copyright (C) 2008 Ingo Molnar <mingo@redhat.com>
  9. *
  10. */
  11. #include <linux/init.h>
  12. #include <linux/kgdb.h>
  13. #include <linux/kdb.h>
  14. #include <linux/ftrace.h>
  15. #include "trace.h"
  16. #include "trace_output.h"
  17. static void ftrace_dump_buf(int skip_lines, long cpu_file)
  18. {
  19. /* use static because iter can be a bit big for the stack */
  20. static struct trace_iterator iter;
  21. unsigned int old_userobj;
  22. int cnt = 0, cpu;
  23. trace_init_global_iter(&iter);
  24. for_each_tracing_cpu(cpu) {
  25. atomic_inc(&iter.tr->data[cpu]->disabled);
  26. }
  27. old_userobj = trace_flags;
  28. /* don't look at user memory in panic mode */
  29. trace_flags &= ~TRACE_ITER_SYM_USEROBJ;
  30. kdb_printf("Dumping ftrace buffer:\n");
  31. /* reset all but tr, trace, and overruns */
  32. memset(&iter.seq, 0,
  33. sizeof(struct trace_iterator) -
  34. offsetof(struct trace_iterator, seq));
  35. iter.iter_flags |= TRACE_FILE_LAT_FMT;
  36. iter.pos = -1;
  37. if (cpu_file == TRACE_PIPE_ALL_CPU) {
  38. for_each_tracing_cpu(cpu) {
  39. iter.buffer_iter[cpu] =
  40. ring_buffer_read_prepare(iter.tr->buffer, cpu);
  41. ring_buffer_read_start(iter.buffer_iter[cpu]);
  42. tracing_iter_reset(&iter, cpu);
  43. }
  44. } else {
  45. iter.cpu_file = cpu_file;
  46. iter.buffer_iter[cpu_file] =
  47. ring_buffer_read_prepare(iter.tr->buffer, cpu_file);
  48. ring_buffer_read_start(iter.buffer_iter[cpu_file]);
  49. tracing_iter_reset(&iter, cpu_file);
  50. }
  51. if (!trace_empty(&iter))
  52. trace_find_next_entry_inc(&iter);
  53. while (!trace_empty(&iter)) {
  54. if (!cnt)
  55. kdb_printf("---------------------------------\n");
  56. cnt++;
  57. if (trace_find_next_entry_inc(&iter) != NULL && !skip_lines)
  58. print_trace_line(&iter);
  59. if (!skip_lines)
  60. trace_printk_seq(&iter.seq);
  61. else
  62. skip_lines--;
  63. if (KDB_FLAG(CMD_INTERRUPT))
  64. goto out;
  65. }
  66. if (!cnt)
  67. kdb_printf(" (ftrace buffer empty)\n");
  68. else
  69. kdb_printf("---------------------------------\n");
  70. out:
  71. trace_flags = old_userobj;
  72. for_each_tracing_cpu(cpu) {
  73. atomic_dec(&iter.tr->data[cpu]->disabled);
  74. }
  75. for_each_tracing_cpu(cpu)
  76. if (iter.buffer_iter[cpu])
  77. ring_buffer_read_finish(iter.buffer_iter[cpu]);
  78. }
  79. /*
  80. * kdb_ftdump - Dump the ftrace log buffer
  81. */
  82. static int kdb_ftdump(int argc, const char **argv)
  83. {
  84. int skip_lines = 0;
  85. long cpu_file;
  86. char *cp;
  87. if (argc > 2)
  88. return KDB_ARGCOUNT;
  89. if (argc) {
  90. skip_lines = simple_strtol(argv[1], &cp, 0);
  91. if (*cp)
  92. skip_lines = 0;
  93. }
  94. if (argc == 2) {
  95. cpu_file = simple_strtol(argv[2], &cp, 0);
  96. if (*cp || cpu_file >= NR_CPUS || cpu_file < 0 ||
  97. !cpu_online(cpu_file))
  98. return KDB_BADINT;
  99. } else {
  100. cpu_file = TRACE_PIPE_ALL_CPU;
  101. }
  102. kdb_trap_printk++;
  103. ftrace_dump_buf(skip_lines, cpu_file);
  104. kdb_trap_printk--;
  105. return 0;
  106. }
  107. static __init int kdb_ftrace_register(void)
  108. {
  109. kdb_register_repeat("ftdump", kdb_ftdump, "[skip_#lines] [cpu]",
  110. "Dump ftrace log", 0, KDB_REPEAT_NONE);
  111. return 0;
  112. }
  113. late_initcall(kdb_ftrace_register);