trace_functions.c 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. /*
  2. * ring buffer based function tracer
  3. *
  4. * Copyright (C) 2007-2008 Steven Rostedt <srostedt@redhat.com>
  5. * Copyright (C) 2008 Ingo Molnar <mingo@redhat.com>
  6. *
  7. * Based on code from the latency_tracer, that is:
  8. *
  9. * Copyright (C) 2004-2006 Ingo Molnar
  10. * Copyright (C) 2004 William Lee Irwin III
  11. */
  12. #include <linux/debugfs.h>
  13. #include <linux/uaccess.h>
  14. #include <linux/ftrace.h>
  15. #include <linux/fs.h>
  16. #include "trace.h"
  17. static void function_reset(struct trace_array *tr)
  18. {
  19. int cpu;
  20. tr->time_start = ftrace_now(tr->cpu);
  21. for_each_online_cpu(cpu)
  22. tracing_reset(tr->data[cpu]);
  23. }
  24. static void start_function_trace(struct trace_array *tr)
  25. {
  26. function_reset(tr);
  27. atomic_inc(&trace_record_cmdline_enabled);
  28. tracing_start_function_trace();
  29. }
  30. static void stop_function_trace(struct trace_array *tr)
  31. {
  32. tracing_stop_function_trace();
  33. atomic_dec(&trace_record_cmdline_enabled);
  34. }
  35. static void function_trace_init(struct trace_array *tr)
  36. {
  37. if (tr->ctrl)
  38. start_function_trace(tr);
  39. }
  40. static void function_trace_reset(struct trace_array *tr)
  41. {
  42. if (tr->ctrl)
  43. stop_function_trace(tr);
  44. }
  45. static void function_trace_ctrl_update(struct trace_array *tr)
  46. {
  47. if (tr->ctrl)
  48. start_function_trace(tr);
  49. else
  50. stop_function_trace(tr);
  51. }
  52. static struct tracer function_trace __read_mostly =
  53. {
  54. .name = "ftrace",
  55. .init = function_trace_init,
  56. .reset = function_trace_reset,
  57. .ctrl_update = function_trace_ctrl_update,
  58. #ifdef CONFIG_FTRACE_SELFTEST
  59. .selftest = trace_selftest_startup_function,
  60. #endif
  61. };
  62. static __init int init_function_trace(void)
  63. {
  64. return register_tracer(&function_trace);
  65. }
  66. device_initcall(init_function_trace);