trace_functions.c 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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, cpu);
  23. }
  24. static void start_function_trace(struct trace_array *tr)
  25. {
  26. tr->cpu = get_cpu();
  27. function_reset(tr);
  28. put_cpu();
  29. tracing_start_cmdline_record();
  30. tracing_start_function_trace();
  31. }
  32. static void stop_function_trace(struct trace_array *tr)
  33. {
  34. tracing_stop_function_trace();
  35. tracing_stop_cmdline_record();
  36. }
  37. static int function_trace_init(struct trace_array *tr)
  38. {
  39. start_function_trace(tr);
  40. return 0;
  41. }
  42. static void function_trace_reset(struct trace_array *tr)
  43. {
  44. stop_function_trace(tr);
  45. }
  46. static void function_trace_start(struct trace_array *tr)
  47. {
  48. function_reset(tr);
  49. }
  50. static struct tracer function_trace __read_mostly =
  51. {
  52. .name = "function",
  53. .init = function_trace_init,
  54. .reset = function_trace_reset,
  55. .start = function_trace_start,
  56. #ifdef CONFIG_FTRACE_SELFTEST
  57. .selftest = trace_selftest_startup_function,
  58. #endif
  59. };
  60. static __init int init_function_trace(void)
  61. {
  62. return register_tracer(&function_trace);
  63. }
  64. device_initcall(init_function_trace);