tracepoint-probe-sample.c 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  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(struct inode *inode, struct file *file)
  15. {
  16. path_get(&file->f_path);
  17. dget(file->f_path.dentry);
  18. printk(KERN_INFO "Event is encountered with filename %s\n",
  19. file->f_path.dentry->d_name.name);
  20. dput(file->f_path.dentry);
  21. path_put(&file->f_path);
  22. }
  23. static void probe_subsys_eventb(void)
  24. {
  25. printk(KERN_INFO "Event B is encountered\n");
  26. }
  27. int __init tp_sample_trace_init(void)
  28. {
  29. int ret;
  30. ret = register_trace_subsys_event(probe_subsys_event);
  31. WARN_ON(ret);
  32. ret = register_trace_subsys_eventb(probe_subsys_eventb);
  33. WARN_ON(ret);
  34. return 0;
  35. }
  36. module_init(tp_sample_trace_init);
  37. void __exit tp_sample_trace_exit(void)
  38. {
  39. unregister_trace_subsys_eventb(probe_subsys_eventb);
  40. unregister_trace_subsys_event(probe_subsys_event);
  41. }
  42. module_exit(tp_sample_trace_exit);
  43. MODULE_LICENSE("GPL");
  44. MODULE_AUTHOR("Mathieu Desnoyers");
  45. MODULE_DESCRIPTION("Tracepoint Probes Samples");