trace_nop.c 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  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. ctx_trace = tr;
  42. tracing_reset_online_cpus(tr);
  43. start_nop_trace(tr);
  44. return 0;
  45. }
  46. static void nop_trace_reset(struct trace_array *tr)
  47. {
  48. stop_nop_trace(tr);
  49. }
  50. /* It only serves as a signal handler and a callback to
  51. * accept or refuse tthe setting of a flag.
  52. * If you don't implement it, then the flag setting will be
  53. * automatically accepted.
  54. */
  55. static int nop_set_flag(u32 old_flags, u32 bit, int set)
  56. {
  57. /*
  58. * Note that you don't need to update nop_flags.val yourself.
  59. * The tracing Api will do it automatically if you return 0
  60. */
  61. if (bit == TRACE_NOP_OPT_ACCEPT) {
  62. printk(KERN_DEBUG "nop_test_accept flag set to %d: we accept."
  63. " Now cat trace_options to see the result\n",
  64. set);
  65. return 0;
  66. }
  67. if (bit == TRACE_NOP_OPT_REFUSE) {
  68. printk(KERN_DEBUG "nop_test_refuse flag set to %d: we refuse."
  69. "Now cat trace_options to see the result\n",
  70. set);
  71. return -EINVAL;
  72. }
  73. return 0;
  74. }
  75. struct tracer nop_trace __read_mostly =
  76. {
  77. .name = "nop",
  78. .init = nop_trace_init,
  79. .reset = nop_trace_reset,
  80. #ifdef CONFIG_FTRACE_SELFTEST
  81. .selftest = trace_selftest_startup_nop,
  82. #endif
  83. .flags = &nop_flags,
  84. .set_flag = nop_set_flag
  85. };