update
[lttv.git] / markers-userspace / marker-lib.c
1
2 #include "marker.h"
3 #include <stdio.h>
4 #include <errno.h>
5
6 __attribute__ ((visibility ("protected")))
7 extern struct marker __start___markers[];
8
9 __attribute__ ((visibility ("protected")))
10 extern struct marker __stop___markers[];
11
12 /**
13 * __mark_empty_function - Empty probe callback
14 * @probe_private: probe private data
15 * @call_private: call site private data
16 * @fmt: format string
17 * @...: variable argument list
18 *
19 * Empty callback provided as a probe to the markers. By providing this to a
20 * disabled marker, we make sure the execution flow is always valid even
21 * though the function pointer change and the marker enabling are two distinct
22 * operations that modifies the execution flow of preemptible code.
23 */
24 __attribute__ ((visibility ("protected")))
25 void __mark_empty_function(void *probe_private, void *call_private,
26 const char *fmt, va_list *args)
27 {
28 }
29
30 /*
31 * marker_probe_cb Callback that prepares the variable argument list for probes.
32 * @mdata: pointer of type struct marker
33 * @call_private: caller site private data
34 * @fmt: format string
35 * @...: Variable argument list.
36 *
37 */
38 __attribute__ ((visibility ("protected")))
39 void marker_probe_cb(const struct marker *mdata, void *call_private,
40 const char *fmt, ...)
41 {
42 static unsigned int count = 0;
43
44 printf("Test probe function %u\n", count++);
45 }
46
47 //FIXME : imv_read won't work with optimized immediate values.
48 //will need to issue one sys_marker call for each immediate value.
49 __attribute__ ((visibility ("protected")))
50 void testip(void)
51 {
52 printf("addr : %p\n", __builtin_return_address(0));
53 }
54
55 __attribute__((constructor, visibility ("protected")))
56 void marker_init(void)
57 {
58 struct marker *iter;
59 int ret;
60
61 printf("Marker section : from %p to %p (init)\n",
62 __start___markers, __stop___markers);
63 testip();
64 for (iter = __start___markers; iter < __stop___markers; iter++) {
65 printf("Marker : %s\n", iter->name);
66 ret = sys_marker(iter->name, iter->format,
67 &imv_read(iter->state), 1);
68 if (ret)
69 perror("Error connecting markers");
70 }
71 }
72
73 __attribute__((destructor, visibility ("protected")))
74 void marker_fini(void)
75 {
76 struct marker *iter;
77 int ret;
78
79 printf("Marker section : from %p to %p (fini)\n",
80 __start___markers, __stop___markers);
81 for (iter = __start___markers; iter < __stop___markers; iter++) {
82 printf("Marker : %s\n", iter->name);
83 ret = sys_marker(iter->name, iter->format,
84 &imv_read(iter->state), 0);
85 if (ret)
86 perror("Error disconnecting markers");
87 }
88 }
This page took 0.032606 seconds and 5 git commands to generate.