tracepoint-probe-sample.c 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. /*
  2. * tracepoint-probe-sample.c
  3. *
  4. * sample tracepoint probes.
  5. */
  6. #include <linux/module.h>
  7. #include <linux/file.h>
  8. #include <linux/dcache.h>
  9. #include "tp-samples-trace.h"
  10. /*
  11. * Here the caller only guarantees locking for struct file and struct inode.
  12. * Locking must therefore be done in the probe to use the dentry.
  13. */
  14. static void probe_subsys_event(void *ignore,
  15. struct inode *inode, struct file *file)
  16. {
  17. path_get(&file->f_path);
  18. dget(file->f_path.dentry);
  19. printk(KERN_INFO "Event is encountered with filename %s\n",
  20. file->f_path.dentry->d_name.name);
  21. dput(file->f_path.dentry);
  22. path_put(&file->f_path);
  23. }
  24. static void probe_subsys_eventb(void *ignore)
  25. {
  26. printk(KERN_INFO "Event B is encountered\n");
  27. }
  28. static int __init tp_sample_trace_init(void)
  29. {
  30. int ret;
  31. ret = register_trace_subsys_event(probe_subsys_event, NULL);
  32. WARN_ON(ret);
  33. ret = register_trace_subsys_eventb(probe_subsys_eventb, NULL);
  34. WARN_ON(ret);
  35. return 0;
  36. }
  37. module_init(tp_sample_trace_init);
  38. static void __exit tp_sample_trace_exit(void)
  39. {
  40. unregister_trace_subsys_eventb(probe_subsys_eventb, NULL);
  41. unregister_trace_subsys_event(probe_subsys_event, NULL);
  42. tracepoint_synchronize_unregister();
  43. }
  44. module_exit(tp_sample_trace_exit);
  45. MODULE_LICENSE("GPL");
  46. MODULE_AUTHOR("Mathieu Desnoyers");
  47. MODULE_DESCRIPTION("Tracepoint Probes Samples");