- /*
- * kprobe_jiffies.c
- */
- #include <linux/module.h>
- #include <linux/kernel.h>
- #include <linux/string.h>
- #include <linux/init.h>
- #include <linux/kprobes.h>
- #include <linux/kallsyms.h>
- /* global probe object */
- struct kprobe probe;
- /* jiffies record */
- unsigned long jiffies_enter = 0;
- unsigned long jiffies_exit = 0;
- /*
- * enter the probe pointer
- */
- static int pre_probe(struct kprobe *probe, struct pt_regs *regs)
- {
- jiffiesjiffies_enter = jiffies;
- return 0;
- }
- /*
- * exit the probe pointer
- */
- static void post_probe(struct kprobe *probe, struct pt_regs *regs, unsigned long flags)
- {
- unsigned long diff;
- jiffiesjiffies_exit = jiffies;
- diff = jiffies_exit - jiffies_enter;
- printk("spending time: %lu, enter: %lu, exit: %lu\n",
- diff, jiffies_enter, jiffies_exit);
- }
- static int __init kprobe_jiffies_init(void)
- {
- probe.pre_handler = pre_probe;
- probe.post_handler = post_probe;
- probe.addr = (kprobe_opcode_t *) kallsyms_lookup_name("probe_function");
- if (probe.addr == NULL) {
- printk("Cannot find out 'dd_xor_encode_sse' in system\n");
- return 1;
- }
- register_kprobe(&probe);
- printk("register probe jffies driver.\n");
- return 0;
- }
- static void __exit kprobe_jiffies_exit(void)
- {
- unregister_kprobe(&probe);
- printk("unregister probe jffies driver.\n");
- return;
- }
- module_init(kprobe_jiffies_init);
- module_exit(kprobe_jiffies_exit);
- MODULE_AUTHOR("xxx");
- MODULE_DESCRIPTION("kernel probe driver");
- MODULE_LICENSE("GPL");
我想Kprobe是個非常不錯的東西,如果在Kprobe的基礎上包裝一下,使得用戶更加容易的使用,那麼對內核程序的調試將是會發生革命性的變化。我想有時間我應該在Kprobe的基礎上做一個內核調試工具了。
本文出自 “存儲之道” 博客,請務必保留此出處http://alanwu.blog.51cto.com/3652632/1109054