| 1 | /* test-time-probe.c |
| 2 | * |
| 3 | * Test time spent in a LTTng instrumentation probe. |
| 4 | */ |
| 5 | |
| 6 | |
| 7 | #include <linux/init.h> |
| 8 | #include <linux/module.h> |
| 9 | #include <linux/ltt-tracer.h> |
| 10 | #include <linux/timex.h> |
| 11 | #include <linux/marker.h> |
| 12 | #include <linux/proc_fs.h> |
| 13 | |
| 14 | struct proc_dir_entry *pentry_test = NULL; |
| 15 | |
| 16 | /* Event logged : 4 bytes. Let's use 1MB of |
| 17 | * buffers. 1MB / 4bytes = 262144 (plus heartbeats). So, if we write 20000 |
| 18 | * event, we should not lose events. Check event lost count after tests. */ |
| 19 | |
| 20 | #define NR_LOOPS 20000 |
| 21 | |
| 22 | static int my_open(struct inode *inode, struct file *file) |
| 23 | { |
| 24 | unsigned int i; |
| 25 | cycles_t time1, time2, time; |
| 26 | cycles_t tot_time = 0; |
| 27 | unsigned long flags; |
| 28 | |
| 29 | printk(KERN_ALERT "test begin\n"); |
| 30 | local_irq_save(flags); |
| 31 | time1 = get_cycles(); |
| 32 | for(i=0; i<NR_LOOPS; i++) { |
| 33 | _MARK(_MF_DEFAULT | ltt_flag_mask(LTT_FLAG_COMPACT), |
| 34 | compact_event_a, MARK_NOARGS); |
| 35 | _MARK(_MF_DEFAULT | ltt_flag_mask(LTT_FLAG_COMPACT), |
| 36 | compact_event_b, "%4b", 0xFFFF); |
| 37 | _MARK(_MF_DEFAULT | ltt_flag_mask(LTT_FLAG_COMPACT), |
| 38 | compact_event_c, "%8b", 0xFFFFFFFFULL); |
| 39 | _MARK(_MF_DEFAULT | ltt_flag_mask(LTT_FLAG_COMPACT) |
| 40 | | ltt_flag_mask(LTT_FLAG_COMPACT_DATA), |
| 41 | compact_event_d, MARK_NOARGS, 0xFFFF); |
| 42 | _MARK(_MF_DEFAULT | ltt_flag_mask(LTT_FLAG_COMPACT) |
| 43 | | ltt_flag_mask(LTT_FLAG_COMPACT_DATA), |
| 44 | compact_event_e, "%8b", 0xFFFF, 0xFFFFFFFFULL); |
| 45 | } |
| 46 | time2 = get_cycles(); |
| 47 | time = time2 - time1; |
| 48 | tot_time += time; |
| 49 | local_irq_restore(flags); |
| 50 | |
| 51 | printk(KERN_ALERT "test results : time per probe\n"); |
| 52 | printk(KERN_ALERT "number of loops : %d\n", NR_LOOPS); |
| 53 | printk(KERN_ALERT "total time : %llu\n", tot_time); |
| 54 | |
| 55 | printk(KERN_ALERT "test end\n"); |
| 56 | return -EPERM; |
| 57 | } |
| 58 | |
| 59 | static struct file_operations mark_ops = { |
| 60 | .open = my_open, |
| 61 | }; |
| 62 | |
| 63 | static int ltt_test_init(void) |
| 64 | { |
| 65 | printk(KERN_ALERT "test init\n"); |
| 66 | pentry_test = create_proc_entry("test-compact", 0444, NULL); |
| 67 | if (pentry_test) |
| 68 | pentry_test->proc_fops = &mark_ops; |
| 69 | else |
| 70 | return -EPERM; |
| 71 | return 0; |
| 72 | } |
| 73 | |
| 74 | static void ltt_test_exit(void) |
| 75 | { |
| 76 | printk(KERN_ALERT "test exit\n"); |
| 77 | remove_proc_entry("test-compact", NULL); |
| 78 | } |
| 79 | |
| 80 | module_init(ltt_test_init) |
| 81 | module_exit(ltt_test_exit) |
| 82 | |
| 83 | MODULE_LICENSE("GPL"); |
| 84 | MODULE_AUTHOR("Mathieu Desnoyers"); |
| 85 | MODULE_DESCRIPTION("Linux Trace Toolkit Test"); |
| 86 | |