trace_nop.c 2.2 KB

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