tracepoint-probe-sample.c 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  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. static 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. static 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. tracepoint_synchronize_unregister();
  42. }
  43. module_exit(tp_sample_trace_exit);
  44. MODULE_LICENSE("GPL");
  45. MODULE_AUTHOR("Mathieu Desnoyers");
  46. MODULE_DESCRIPTION("Tracepoint Probes Samples");