move everything out of trunk
[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;
d06fc4d5 32
33 /* Assign args */
34 va_start(ap, format);
35 value = va_arg(ap, typeof(value));
36 mystr = va_arg(ap, typeof(mystr));
d06fc4d5 37
38 /* Call printk */
421991b0 39 printk("Value %u, string %s\n", value, mystr);
d06fc4d5 40
41 /* or count, check rights, serialize data in a buffer */
42
43 va_end(ap);
44}
45
46atomic_t eventb_count = ATOMIC_INIT(0);
47
48void probe_subsystem_eventb(const struct __mark_marker_c *mdata,
49 const char *format, ...)
50{
51 /* Increment counter */
52 atomic_inc(&eventb_count);
53}
54
55static struct probe_data probe_array[] =
56{
57 { .name = "subsystem_event",
421991b0 58 .format = "%d %s",
d06fc4d5 59 .probe_func = probe_subsystem_event },
60 { .name = "subsystem_eventb",
61 .format = MARK_NOARGS,
62 .probe_func = probe_subsystem_eventb },
63};
64
65static int __init probe_init(void)
66{
67 int result;
68 uint8_t eID;
69
70 for (eID = 0; eID < NUM_PROBES; eID++) {
71 result = marker_set_probe(probe_array[eID].name,
72 probe_array[eID].format,
73 probe_array[eID].probe_func, &probe_array[eID]);
74 if (!result)
75 printk(KERN_INFO "Unable to register probe %s\n",
76 probe_array[eID].name);
77 }
78 return 0;
79}
80
81static void __exit probe_fini(void)
82{
83 uint8_t eID;
84
85 for (eID = 0; eID < NUM_PROBES; eID++) {
86 marker_remove_probe(probe_array[eID].name);
87 }
88 synchronize_sched(); /* Wait for probes to finish */
89 printk("Number of event b : %u\n", atomic_read(&eventb_count));
90}
91
92module_init(probe_init);
93module_exit(probe_fini);
94
95MODULE_LICENSE("GPL");
96MODULE_AUTHOR("Mathieu Desnoyers");
97MODULE_DESCRIPTION("SUBSYSTEM Probe");
This page took 0.033764 seconds and 4 git commands to generate.