x86: rodata config hookup
[wrt350n-kernel.git] / samples / markers / probe-example.c
bloba36797535615dc77647260f12d2496d850bd4177
1 /* probe-example.c
3 * Connects two functions to marker call sites.
5 * (C) Copyright 2007 Mathieu Desnoyers <mathieu.desnoyers@polymtl.ca>
7 * This file is released under the GPLv2.
8 * See the file COPYING for more details.
9 */
11 #include <linux/sched.h>
12 #include <linux/kernel.h>
13 #include <linux/module.h>
14 #include <linux/marker.h>
15 #include <asm/atomic.h>
17 struct probe_data {
18 const char *name;
19 const char *format;
20 marker_probe_func *probe_func;
23 void probe_subsystem_event(const struct marker *mdata, void *private,
24 const char *format, ...)
26 va_list ap;
27 /* Declare args */
28 unsigned int value;
29 const char *mystr;
31 /* Assign args */
32 va_start(ap, format);
33 value = va_arg(ap, typeof(value));
34 mystr = va_arg(ap, typeof(mystr));
36 /* Call printk */
37 printk(KERN_DEBUG "Value %u, string %s\n", value, mystr);
39 /* or count, check rights, serialize data in a buffer */
41 va_end(ap);
44 atomic_t eventb_count = ATOMIC_INIT(0);
46 void probe_subsystem_eventb(const struct marker *mdata, void *private,
47 const char *format, ...)
49 /* Increment counter */
50 atomic_inc(&eventb_count);
53 static struct probe_data probe_array[] =
55 { .name = "subsystem_event",
56 .format = "integer %d string %s",
57 .probe_func = probe_subsystem_event },
58 { .name = "subsystem_eventb",
59 .format = MARK_NOARGS,
60 .probe_func = probe_subsystem_eventb },
63 static int __init probe_init(void)
65 int result;
66 int i;
68 for (i = 0; i < ARRAY_SIZE(probe_array); i++) {
69 result = marker_probe_register(probe_array[i].name,
70 probe_array[i].format,
71 probe_array[i].probe_func, &probe_array[i]);
72 if (result)
73 printk(KERN_INFO "Unable to register probe %s\n",
74 probe_array[i].name);
75 result = marker_arm(probe_array[i].name);
76 if (result)
77 printk(KERN_INFO "Unable to arm probe %s\n",
78 probe_array[i].name);
80 return 0;
83 static void __exit probe_fini(void)
85 int i;
87 for (i = 0; i < ARRAY_SIZE(probe_array); i++)
88 marker_probe_unregister(probe_array[i].name);
89 printk(KERN_INFO "Number of event b : %u\n",
90 atomic_read(&eventb_count));
93 module_init(probe_init);
94 module_exit(probe_fini);
96 MODULE_LICENSE("GPL");
97 MODULE_AUTHOR("Mathieu Desnoyers");
98 MODULE_DESCRIPTION("SUBSYSTEM Probe");