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