probe-example.c 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. /* probe-example.c
  2. *
  3. * Connects two functions to marker call sites.
  4. *
  5. * (C) Copyright 2007 Mathieu Desnoyers <mathieu.desnoyers@polymtl.ca>
  6. *
  7. * This file is released under the GPLv2.
  8. * See the file COPYING for more details.
  9. */
  10. #include <linux/sched.h>
  11. #include <linux/kernel.h>
  12. #include <linux/module.h>
  13. #include <linux/marker.h>
  14. #include <asm/atomic.h>
  15. struct probe_data {
  16. const char *name;
  17. const char *format;
  18. marker_probe_func *probe_func;
  19. };
  20. void probe_subsystem_event(void *probe_data, void *call_data,
  21. const char *format, va_list *args)
  22. {
  23. /* Declare args */
  24. unsigned int value;
  25. const char *mystr;
  26. /* Assign args */
  27. value = va_arg(*args, typeof(value));
  28. mystr = va_arg(*args, typeof(mystr));
  29. /* Call printk */
  30. printk(KERN_INFO "Value %u, string %s\n", value, mystr);
  31. /* or count, check rights, serialize data in a buffer */
  32. }
  33. atomic_t eventb_count = ATOMIC_INIT(0);
  34. void probe_subsystem_eventb(void *probe_data, void *call_data,
  35. const char *format, va_list *args)
  36. {
  37. /* Increment counter */
  38. atomic_inc(&eventb_count);
  39. }
  40. static struct probe_data probe_array[] =
  41. {
  42. { .name = "subsystem_event",
  43. .format = "integer %d string %s",
  44. .probe_func = probe_subsystem_event },
  45. { .name = "subsystem_eventb",
  46. .format = MARK_NOARGS,
  47. .probe_func = probe_subsystem_eventb },
  48. };
  49. static int __init probe_init(void)
  50. {
  51. int result;
  52. int i;
  53. for (i = 0; i < ARRAY_SIZE(probe_array); i++) {
  54. result = marker_probe_register(probe_array[i].name,
  55. probe_array[i].format,
  56. probe_array[i].probe_func, &probe_array[i]);
  57. if (result)
  58. printk(KERN_INFO "Unable to register probe %s\n",
  59. probe_array[i].name);
  60. }
  61. return 0;
  62. }
  63. static void __exit probe_fini(void)
  64. {
  65. int i;
  66. for (i = 0; i < ARRAY_SIZE(probe_array); i++)
  67. marker_probe_unregister(probe_array[i].name,
  68. probe_array[i].probe_func, &probe_array[i]);
  69. printk(KERN_INFO "Number of event b : %u\n",
  70. atomic_read(&eventb_count));
  71. marker_synchronize_unregister();
  72. }
  73. module_init(probe_init);
  74. module_exit(probe_fini);
  75. MODULE_LICENSE("GPL");
  76. MODULE_AUTHOR("Mathieu Desnoyers");
  77. MODULE_DESCRIPTION("SUBSYSTEM Probe");