trace_nop.c 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. /*
  2. * nop tracer
  3. *
  4. * Copyright (C) 2008 Steven Noonan <steven@uplinklabs.net>
  5. *
  6. */
  7. #include <linux/module.h>
  8. #include <linux/fs.h>
  9. #include <linux/debugfs.h>
  10. #include <linux/ftrace.h>
  11. #include "trace.h"
  12. /* Our two options */
  13. enum {
  14. TRACE_NOP_OPT_ACCEPT = 0x1,
  15. TRACE_NOP_OPT_REFUSE = 0x2
  16. };
  17. /* Options for the tracer (see trace_options file) */
  18. static struct tracer_opt nop_opts[] = {
  19. /* Option that will be accepted by set_flag callback */
  20. { TRACER_OPT(test_nop_accept, TRACE_NOP_OPT_ACCEPT) },
  21. /* Option that will be refused by set_flag callback */
  22. { TRACER_OPT(test_nop_refuse, TRACE_NOP_OPT_REFUSE) },
  23. { } /* Always set a last empty entry */
  24. };
  25. static struct tracer_flags nop_flags = {
  26. /* You can check your flags value here when you want. */
  27. .val = 0, /* By default: all flags disabled */
  28. .opts = nop_opts
  29. };
  30. static struct trace_array *ctx_trace;
  31. static void start_nop_trace(struct trace_array *tr)
  32. {
  33. /* Nothing to do! */
  34. }
  35. static void stop_nop_trace(struct trace_array *tr)
  36. {
  37. /* Nothing to do! */
  38. }
  39. static int nop_trace_init(struct trace_array *tr)
  40. {
  41. int cpu;
  42. ctx_trace = tr;
  43. for_each_online_cpu(cpu)
  44. tracing_reset(tr, cpu);
  45. start_nop_trace(tr);
  46. return 0;
  47. }
  48. static void nop_trace_reset(struct trace_array *tr)
  49. {
  50. stop_nop_trace(tr);
  51. }
  52. /* It only serves as a signal handler and a callback to
  53. * accept or refuse tthe setting of a flag.
  54. * If you don't implement it, then the flag setting will be
  55. * automatically accepted.
  56. */
  57. static int nop_set_flag(u32 old_flags, u32 bit, int set)
  58. {
  59. /*
  60. * Note that you don't need to update nop_flags.val yourself.
  61. * The tracing Api will do it automatically if you return 0
  62. */
  63. if (bit == TRACE_NOP_OPT_ACCEPT) {
  64. printk(KERN_DEBUG "nop_test_accept flag set to %d: we accept."
  65. " Now cat trace_options to see the result\n",
  66. set);
  67. return 0;
  68. }
  69. if (bit == TRACE_NOP_OPT_REFUSE) {
  70. printk(KERN_DEBUG "nop_test_refuse flag set to %d: we refuse."
  71. "Now cat trace_options to see the result\n",
  72. set);
  73. return -EINVAL;
  74. }
  75. return 0;
  76. }
  77. struct tracer nop_trace __read_mostly =
  78. {
  79. .name = "nop",
  80. .init = nop_trace_init,
  81. .reset = nop_trace_reset,
  82. #ifdef CONFIG_FTRACE_SELFTEST
  83. .selftest = trace_selftest_startup_nop,
  84. #endif
  85. .flags = &nop_flags,
  86. .set_flag = nop_set_flag
  87. };