fix indentation
[lttv.git] / tests / kernel / probe-example.c
CommitLineData
d06fc4d5 1/* probe-example.c
2 *
3 * Connects a two functions to marker call sites.
4 *
5 * (C) Copyright 2007 Mathieu Desnoyers <mathieu.desnoyers@polymtl.ca>
6 *
7 * This file is released under the GPLv2.
8 * See the file COPYING for more details.
9 */
10
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>
16
17#define NUM_PROBES (sizeof(probe_array) / sizeof(struct probe_data))
18
19struct probe_data {
20 const char *name;
21 const char *format;
22 marker_probe_func *probe_func;
23};
24
25void probe_subsystem_event(const struct __mark_marker_c *mdata,
26 const char *format, ...)
27{
28 va_list ap;
29 /* Declare args */
30 unsigned int value;
31 const char *mystr;
32 int task_size, task_alignment;
33 struct task_struct *task;
34
35 /* Assign args */
36 va_start(ap, format);
37 value = va_arg(ap, typeof(value));
38 mystr = va_arg(ap, typeof(mystr));
39 task_size = va_arg(ap, typeof(task_size));
40 task_alignment = va_arg(ap, typeof(task_alignment));
41 task = va_arg(ap, typeof(task));
42
43 /* Call printk */
44 printk("Value %u, string %s, current ptr %p\n", value, mystr, current);
45
46 /* or count, check rights, serialize data in a buffer */
47
48 va_end(ap);
49}
50
51atomic_t eventb_count = ATOMIC_INIT(0);
52
53void probe_subsystem_eventb(const struct __mark_marker_c *mdata,
54 const char *format, ...)
55{
56 /* Increment counter */
57 atomic_inc(&eventb_count);
58}
59
60static struct probe_data probe_array[] =
61{
62 { .name = "subsystem_event",
63 .format = "%d %s %*.*r",
64 .probe_func = probe_subsystem_event },
65 { .name = "subsystem_eventb",
66 .format = MARK_NOARGS,
67 .probe_func = probe_subsystem_eventb },
68};
69
70static int __init probe_init(void)
71{
72 int result;
73 uint8_t eID;
74
75 for (eID = 0; eID < NUM_PROBES; eID++) {
76 result = marker_set_probe(probe_array[eID].name,
77 probe_array[eID].format,
78 probe_array[eID].probe_func, &probe_array[eID]);
79 if (!result)
80 printk(KERN_INFO "Unable to register probe %s\n",
81 probe_array[eID].name);
82 }
83 return 0;
84}
85
86static void __exit probe_fini(void)
87{
88 uint8_t eID;
89
90 for (eID = 0; eID < NUM_PROBES; eID++) {
91 marker_remove_probe(probe_array[eID].name);
92 }
93 synchronize_sched(); /* Wait for probes to finish */
94 printk("Number of event b : %u\n", atomic_read(&eventb_count));
95}
96
97module_init(probe_init);
98module_exit(probe_fini);
99
100MODULE_LICENSE("GPL");
101MODULE_AUTHOR("Mathieu Desnoyers");
102MODULE_DESCRIPTION("SUBSYSTEM Probe");
This page took 0.02634 seconds and 4 git commands to generate.