1c97db939e9a5740846e9015c6be74d098ea77b6
[lttng-ust.git] / hello / hello.c
1 #include <stdio.h>
2 #include <unistd.h>
3 #include <sys/mman.h>
4
5 #include "../libmarkers/marker.h"
6 #include "usterr.h"
7 #include "tracer.h"
8 #include "marker-control.h"
9
10 void probe(const struct marker *mdata,
11 void *probe_private, void *call_private,
12 const char *fmt, va_list *args)
13 {
14 printf("In probe\n");
15 }
16
17 //ust// void try_map()
18 //ust// {
19 //ust// char *m;
20 //ust//
21 //ust// /* maybe add MAP_LOCKED */
22 //ust// m = mmap(NULL, 4096, PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS | MAP_POPULATE , -1, 0);
23 //ust// if(m == (char*)-1) {
24 //ust// perror("mmap");
25 //ust// return;
26 //ust// }
27 //ust//
28 //ust// printf("The mapping is at %p.\n", m);
29 //ust// strcpy(m, "Hello, Mapping!");
30 //ust// }
31
32 //sig_atomic_t must_quit;
33
34 void inthandler(int sig)
35 {
36 printf("in handler\n");
37 exit(0);
38 }
39
40 int init_int_handler(void)
41 {
42 int result;
43 struct sigaction act;
44
45 result = sigemptyset(&act.sa_mask);
46 if(result == -1) {
47 PERROR("sigemptyset");
48 return -1;
49 }
50
51 act.sa_handler = inthandler;
52 act.sa_flags = SA_RESTART;
53
54 /* Only defer ourselves. Also, try to restart interrupted
55 * syscalls to disturb the traced program as little as possible.
56 */
57 result = sigaction(SIGINT, &act, NULL);
58 if(result == -1) {
59 PERROR("sigaction");
60 return -1;
61 }
62
63 return 0;
64 }
65
66 //ust// DEFINE_MUTEX(probes_mutex);
67 //ust//
68 //ust// static LIST_HEAD(probes_registered_list);
69 //ust//
70 //ust// int ltt_marker_connect(const char *channel, const char *mname,
71 //ust// const char *pname)
72 //ust//
73 //ust// {
74 //ust// int ret;
75 //ust// struct ltt_active_marker *pdata;
76 //ust// struct ltt_available_probe *probe;
77 //ust//
78 //ust// ltt_lock_traces();
79 //ust// mutex_lock(&probes_mutex);
80 //ust// probe = get_probe_from_name(pname);
81 //ust// if (!probe) {
82 //ust// ret = -ENOENT;
83 //ust// goto end;
84 //ust// }
85 //ust// pdata = marker_get_private_data(channel, mname, probe->probe_func, 0);
86 //ust// if (pdata && !IS_ERR(pdata)) {
87 //ust// ret = -EEXIST;
88 //ust// goto end;
89 //ust// }
90 //ust// pdata = kmem_cache_zalloc(markers_loaded_cachep, GFP_KERNEL);
91 //ust// if (!pdata) {
92 //ust// ret = -ENOMEM;
93 //ust// goto end;
94 //ust// }
95 //ust// pdata->probe = probe;
96 //ust// /*
97 //ust// * ID has priority over channel in case of conflict.
98 //ust// */
99 //ust// ret = marker_probe_register(channel, mname, NULL,
100 //ust// probe->probe_func, pdata);
101 //ust// if (ret)
102 //ust// kmem_cache_free(markers_loaded_cachep, pdata);
103 //ust// else
104 //ust// list_add(&pdata->node, &markers_loaded_list);
105 //ust// end:
106 //ust// mutex_unlock(&probes_mutex);
107 //ust// ltt_unlock_traces();
108 //ust// return ret;
109 //ust// }
110 //ust//
111 //ust//
112 //ust// int ltt_probe_register(struct ltt_available_probe *pdata)
113 //ust// {
114 //ust// int ret = 0;
115 //ust// int comparison;
116 //ust// struct ltt_available_probe *iter;
117 //ust//
118 //ust// mutex_lock(&probes_mutex);
119 //ust// list_for_each_entry_reverse(iter, &probes_registered_list, node) {
120 //ust// comparison = strcmp(pdata->name, iter->name);
121 //ust// if (!comparison) {
122 //ust// ret = -EBUSY;
123 //ust// goto end;
124 //ust// } else if (comparison > 0) {
125 //ust// /* We belong to the location right after iter. */
126 //ust// list_add(&pdata->node, &iter->node);
127 //ust// goto end;
128 //ust// }
129 //ust// }
130 //ust// /* Should be added at the head of the list */
131 //ust// list_add(&pdata->node, &probes_registered_list);
132 //ust// end:
133 //ust// mutex_unlock(&probes_mutex);
134 //ust// return ret;
135 //ust// }
136 //ust//
137 //ust//
138 //ust// struct ltt_available_probe default_probe = {
139 //ust// .name = "default",
140 //ust// .format = NULL,
141 //ust// .probe_func = ltt_vtrace,
142 //ust// .callbacks[0] = ltt_serialize_data,
143 //ust// };
144
145 int main()
146 {
147 int result;
148
149 init_int_handler();
150
151 init_ustrelay_transport();
152
153 printf("page size is %d\n", sysconf(_SC_PAGE_SIZE));
154
155 char trace_name[] = "theusttrace";
156 char trace_type[] = "ustrelay";
157
158 marker_control_init();
159
160 marker_probe_register("abc", "testmark", "", probe, NULL);
161 marker_probe_register("metadata", "core_marker_id", "channel %s name %s event_id %hu int #1u%zu long #1u%zu pointer #1u%zu size_t #1u%zu alignment #1u%u", probe, NULL);
162 //ust// result = ltt_probe_register(&default_probe);
163 //ust// if(result)
164 //ust// ERR("ltt_probe_register");
165
166 result = ltt_marker_connect("abc", "testmark2", "default");
167 if(result)
168 ERR("ltt_marker_connect");
169
170
171 result = ltt_trace_setup(trace_name);
172 if(result < 0) {
173 ERR("ltt_trace_setup failed");
174 return 1;
175 }
176
177 result = ltt_trace_set_type(trace_name, trace_type);
178 if(result < 0) {
179 ERR("ltt_trace_set_type failed");
180 return 1;
181 }
182
183 result = ltt_trace_alloc(trace_name);
184 if(result < 0) {
185 ERR("ltt_trace_alloc failed");
186 return 1;
187 }
188
189 result = ltt_trace_start(trace_name);
190 if(result < 0) {
191 ERR("ltt_trace_start failed");
192 return 1;
193 }
194
195
196 printf("Hello, World!\n");
197
198 for(;;) {
199 trace_mark(abc, testmark, "", MARK_NOARGS);
200 trace_mark(abc, testmark2, "", MARK_NOARGS);
201 sleep(1);
202 }
203
204 scanf("%*s");
205
206 return 0;
207 }
This page took 0.039807 seconds and 3 git commands to generate.