trace_nop.c 2.2 KB

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