it runs
[lttv.git] / usertrace-generic / ltt / ltt-facility-user_generic.h
CommitLineData
3d57eb5b 1#ifndef _LTT_FACILITY_USER_GENERIC_H_
2#define _LTT_FACILITY_USER_GENERIC_H_
3
4#include <sys/types.h>
5#include <ltt/ltt-facility-id-user_generic.h>
6#include <ltt/ltt-generic.h>
7
8/* Named types */
9
10/* Event string structures */
11static inline void lttng_write_string_user_generic_string_data(
12 void *buffer,
13 size_t *to_base,
14 size_t *to,
15 const void **from,
16 size_t *len,
17 const char * obj)
18{
19 size_t size;
20 size_t align;
21
22 /* Flush pending memcpy */
23 if(*len != 0) {
24 if(buffer != NULL)
25 memcpy(buffer+*to_base+*to, *from, *len);
26 }
27 *to += *len;
28 *len = 0;
29
30 align = sizeof(char);
31
32 if(*len == 0) {
33 *to += ltt_align(*to, align); /* align output */
34 } else {
35 *len += ltt_align(*to+*len, align); /* alignment, ok to do a memcpy of it */
36 }
37
38 /* Contains variable sized fields : must explode the structure */
39
40 size = strlen(obj) + 1; /* Include final NULL char. */
41 if(buffer != NULL)
42 memcpy(buffer+*to_base+*to, obj, size);
43 *to += size;
44
45 /* Realign the *to_base on arch size, set *to to 0 */
46 *to += ltt_align(*to, sizeof(void *));
47 *to_base = *to_base+*to;
48 *to = 0;
49
50 /* Put source *from just after the C string */
51 *from += size;
52}
53
54
55/* Event string logging function */
56static inline int trace_user_generic_string(
57 const char * lttng_param_data)
58#ifndef LTT_TRACE
59{
60}
61#else
62{
e36efdc5 63 int ret = 0;
3d57eb5b 64 void *buffer = NULL;
65 size_t real_to_base = 0; /* The buffer is allocated on arch_size alignment */
66 size_t *to_base = &real_to_base;
67 size_t real_to = 0;
68 size_t *to = &real_to;
69 size_t real_len = 0;
70 size_t *len = &real_len;
71 size_t reserve_size;
72 size_t slot_size;
3d57eb5b 73 const void *real_from;
74 const void **from = &real_from;
75 /* For each field, calculate the field size. */
76 /* size = *to_base + *to + *len */
77 /* Assume that the padding for alignment starts at a
78 * sizeof(void *) address. */
79
80 *from = lttng_param_data;
81 lttng_write_string_user_generic_string_data(buffer, to_base, to, from, len, lttng_param_data);
82
83 reserve_size = *to_base + *to + *len;
84 {
85 char stack_buffer[reserve_size];
86 buffer = stack_buffer;
87
88 *to_base = *to = *len = 0;
89
90 *from = lttng_param_data;
91 lttng_write_string_user_generic_string_data(buffer, to_base, to, from, len, lttng_param_data);
92
93 /* Flush pending memcpy */
94 if(*len != 0) {
95 memcpy(buffer+*to_base+*to, *from, *len);
96 *to += *len;
97 *len = 0;
98 }
99
e90c7b86 100 ret = ltt_trace_generic(ltt_facility_user_generic_F583779E, event_user_generic_string, buffer, reserve_size, LTT_BLOCKING);
3d57eb5b 101 }
102
103 return ret;
104
105}
106#endif //LTT_TRACE
107
108/* Event string_pointer structures */
109static inline void lttng_write_string_user_generic_string_pointer_string(
110 void *buffer,
111 size_t *to_base,
112 size_t *to,
113 const void **from,
114 size_t *len,
115 const char * obj)
116{
117 size_t size;
118 size_t align;
119
120 /* Flush pending memcpy */
121 if(*len != 0) {
122 if(buffer != NULL)
123 memcpy(buffer+*to_base+*to, *from, *len);
124 }
125 *to += *len;
126 *len = 0;
127
128 align = sizeof(char);
129
130 if(*len == 0) {
131 *to += ltt_align(*to, align); /* align output */
132 } else {
133 *len += ltt_align(*to+*len, align); /* alignment, ok to do a memcpy of it */
134 }
135
136 /* Contains variable sized fields : must explode the structure */
137
138 size = strlen(obj) + 1; /* Include final NULL char. */
139 if(buffer != NULL)
140 memcpy(buffer+*to_base+*to, obj, size);
141 *to += size;
142
143 /* Realign the *to_base on arch size, set *to to 0 */
144 *to += ltt_align(*to, sizeof(void *));
145 *to_base = *to_base+*to;
146 *to = 0;
147
148 /* Put source *from just after the C string */
149 *from += size;
150}
151
152
153/* Event string_pointer logging function */
154static inline int trace_user_generic_string_pointer(
155 const char * lttng_param_string,
156 const void * lttng_param_pointer)
157#ifndef LTT_TRACE
158{
159}
160#else
161{
e36efdc5 162 int ret = 0;
3d57eb5b 163 void *buffer = NULL;
164 size_t real_to_base = 0; /* The buffer is allocated on arch_size alignment */
165 size_t *to_base = &real_to_base;
166 size_t real_to = 0;
167 size_t *to = &real_to;
168 size_t real_len = 0;
169 size_t *len = &real_len;
170 size_t reserve_size;
171 size_t slot_size;
3d57eb5b 172 size_t align;
173 const void *real_from;
174 const void **from = &real_from;
175 /* For each field, calculate the field size. */
176 /* size = *to_base + *to + *len */
177 /* Assume that the padding for alignment starts at a
178 * sizeof(void *) address. */
179
180 *from = lttng_param_string;
181 lttng_write_string_user_generic_string_pointer_string(buffer, to_base, to, from, len, lttng_param_string);
182
183 *from = &lttng_param_pointer;
184 align = sizeof(const void *);
185
186 if(*len == 0) {
187 *to += ltt_align(*to, align); /* align output */
188 } else {
189 *len += ltt_align(*to+*len, align); /* alignment, ok to do a memcpy of it */
190 }
191
192 *len += sizeof(const void *);
193
194 reserve_size = *to_base + *to + *len;
195 {
196 char stack_buffer[reserve_size];
197 buffer = stack_buffer;
198
199 *to_base = *to = *len = 0;
200
201 *from = lttng_param_string;
202 lttng_write_string_user_generic_string_pointer_string(buffer, to_base, to, from, len, lttng_param_string);
203
204 /* Flush pending memcpy */
205 if(*len != 0) {
206 memcpy(buffer+*to_base+*to, *from, *len);
207 *to += *len;
208 *len = 0;
209 }
210
211 *from = &lttng_param_pointer;
212 align = sizeof(const void *);
213
214 if(*len == 0) {
215 *to += ltt_align(*to, align); /* align output */
216 } else {
217 *len += ltt_align(*to+*len, align); /* alignment, ok to do a memcpy of it */
218 }
219
220 *len += sizeof(const void *);
221
222 /* Flush pending memcpy */
223 if(*len != 0) {
224 memcpy(buffer+*to_base+*to, *from, *len);
225 *to += *len;
226 *len = 0;
227 }
228
e90c7b86 229 ret = ltt_trace_generic(ltt_facility_user_generic_F583779E, event_user_generic_string_pointer, buffer, reserve_size, LTT_BLOCKING);
e36efdc5 230 }
231
232 return ret;
233
234}
235#endif //LTT_TRACE
236
237/* Event slow_printf structures */
238static inline void lttng_write_string_user_generic_slow_printf_string(
239 void *buffer,
240 size_t *to_base,
241 size_t *to,
242 const void **from,
243 size_t *len,
244 const char * obj)
245{
246 size_t size;
247 size_t align;
248
249 /* Flush pending memcpy */
250 if(*len != 0) {
251 if(buffer != NULL)
252 memcpy(buffer+*to_base+*to, *from, *len);
253 }
254 *to += *len;
255 *len = 0;
256
257 align = sizeof(char);
258
259 if(*len == 0) {
260 *to += ltt_align(*to, align); /* align output */
261 } else {
262 *len += ltt_align(*to+*len, align); /* alignment, ok to do a memcpy of it */
263 }
264
265 /* Contains variable sized fields : must explode the structure */
266
267 size = strlen(obj) + 1; /* Include final NULL char. */
268 if(buffer != NULL)
269 memcpy(buffer+*to_base+*to, obj, size);
270 *to += size;
271
272 /* Realign the *to_base on arch size, set *to to 0 */
273 *to += ltt_align(*to, sizeof(void *));
274 *to_base = *to_base+*to;
275 *to = 0;
276
277 /* Put source *from just after the C string */
278 *from += size;
279}
280
281
282/* Event slow_printf logging function */
283static inline int trace_user_generic_slow_printf_param_buffer(
284 void *buffer,
285 size_t reserve_size)
286#ifndef LTT_TRACE
287{
288}
289#else
290{
291 int ret = 0;
e90c7b86 292 reserve_size = ltt_align(reserve_size, sizeof(void *));
e36efdc5 293 {
e90c7b86 294 ret = ltt_trace_generic(ltt_facility_user_generic_F583779E, event_user_generic_slow_printf, buffer, reserve_size, LTT_BLOCKING);
295 }
296
297 return ret;
298
299}
300#endif //LTT_TRACE
301
302/* Event function_entry structures */
303
304/* Event function_entry logging function */
305static inline __attribute__((no_instrument_function)) int trace_user_generic_function_entry(
306 const void * lttng_param_this_fn,
307 const void * lttng_param_call_site)
308#ifndef LTT_TRACE
309{
310}
311#else
312{
313 int ret = 0;
314 void *buffer = NULL;
315 size_t real_to_base = 0; /* The buffer is allocated on arch_size alignment */
316 size_t *to_base = &real_to_base;
317 size_t real_to = 0;
318 size_t *to = &real_to;
319 size_t real_len = 0;
320 size_t *len = &real_len;
321 size_t reserve_size;
322 size_t slot_size;
323 size_t align;
324 const void *real_from;
325 const void **from = &real_from;
326 /* For each field, calculate the field size. */
327 /* size = *to_base + *to + *len */
328 /* Assume that the padding for alignment starts at a
329 * sizeof(void *) address. */
330
331 *from = &lttng_param_this_fn;
332 align = sizeof(const void *);
333
334 if(*len == 0) {
335 *to += ltt_align(*to, align); /* align output */
336 } else {
337 *len += ltt_align(*to+*len, align); /* alignment, ok to do a memcpy of it */
338 }
339
340 *len += sizeof(const void *);
341
342 *from = &lttng_param_call_site;
343 align = sizeof(const void *);
344
345 if(*len == 0) {
346 *to += ltt_align(*to, align); /* align output */
347 } else {
348 *len += ltt_align(*to+*len, align); /* alignment, ok to do a memcpy of it */
349 }
350
351 *len += sizeof(const void *);
352
353 reserve_size = *to_base + *to + *len;
354 {
355 char stack_buffer[reserve_size];
356 buffer = stack_buffer;
357
358 *to_base = *to = *len = 0;
359
360 *from = &lttng_param_this_fn;
361 align = sizeof(const void *);
362
363 if(*len == 0) {
364 *to += ltt_align(*to, align); /* align output */
365 } else {
366 *len += ltt_align(*to+*len, align); /* alignment, ok to do a memcpy of it */
367 }
368
369 *len += sizeof(const void *);
370
371 /* Flush pending memcpy */
372 if(*len != 0) {
373 memcpy(buffer+*to_base+*to, *from, *len);
374 *to += *len;
375 *len = 0;
376 }
377
378 *from = &lttng_param_call_site;
379 align = sizeof(const void *);
380
381 if(*len == 0) {
382 *to += ltt_align(*to, align); /* align output */
383 } else {
384 *len += ltt_align(*to+*len, align); /* alignment, ok to do a memcpy of it */
385 }
386
387 *len += sizeof(const void *);
388
389 /* Flush pending memcpy */
390 if(*len != 0) {
391 memcpy(buffer+*to_base+*to, *from, *len);
392 *to += *len;
393 *len = 0;
394 }
395
396 ret = ltt_trace_generic(ltt_facility_user_generic_F583779E, event_user_generic_function_entry, buffer, reserve_size, LTT_BLOCKING);
397 }
398
399 return ret;
400
401}
402#endif //LTT_TRACE
403
404/* Event function_exit structures */
405
406/* Event function_exit logging function */
407static inline __attribute__((no_instrument_function)) int trace_user_generic_function_exit(
408 const void * lttng_param_this_fn,
409 const void * lttng_param_call_site)
410#ifndef LTT_TRACE
411{
412}
413#else
414{
415 int ret = 0;
416 void *buffer = NULL;
417 size_t real_to_base = 0; /* The buffer is allocated on arch_size alignment */
418 size_t *to_base = &real_to_base;
419 size_t real_to = 0;
420 size_t *to = &real_to;
421 size_t real_len = 0;
422 size_t *len = &real_len;
423 size_t reserve_size;
424 size_t slot_size;
425 size_t align;
426 const void *real_from;
427 const void **from = &real_from;
428 /* For each field, calculate the field size. */
429 /* size = *to_base + *to + *len */
430 /* Assume that the padding for alignment starts at a
431 * sizeof(void *) address. */
432
433 *from = &lttng_param_this_fn;
434 align = sizeof(const void *);
435
436 if(*len == 0) {
437 *to += ltt_align(*to, align); /* align output */
438 } else {
439 *len += ltt_align(*to+*len, align); /* alignment, ok to do a memcpy of it */
440 }
441
442 *len += sizeof(const void *);
443
444 *from = &lttng_param_call_site;
445 align = sizeof(const void *);
446
447 if(*len == 0) {
448 *to += ltt_align(*to, align); /* align output */
449 } else {
450 *len += ltt_align(*to+*len, align); /* alignment, ok to do a memcpy of it */
451 }
452
453 *len += sizeof(const void *);
454
455 reserve_size = *to_base + *to + *len;
456 {
457 char stack_buffer[reserve_size];
458 buffer = stack_buffer;
459
460 *to_base = *to = *len = 0;
461
462 *from = &lttng_param_this_fn;
463 align = sizeof(const void *);
464
465 if(*len == 0) {
466 *to += ltt_align(*to, align); /* align output */
467 } else {
468 *len += ltt_align(*to+*len, align); /* alignment, ok to do a memcpy of it */
469 }
470
471 *len += sizeof(const void *);
472
473 /* Flush pending memcpy */
474 if(*len != 0) {
475 memcpy(buffer+*to_base+*to, *from, *len);
476 *to += *len;
477 *len = 0;
478 }
479
480 *from = &lttng_param_call_site;
481 align = sizeof(const void *);
482
483 if(*len == 0) {
484 *to += ltt_align(*to, align); /* align output */
485 } else {
486 *len += ltt_align(*to+*len, align); /* alignment, ok to do a memcpy of it */
487 }
488
489 *len += sizeof(const void *);
490
491 /* Flush pending memcpy */
492 if(*len != 0) {
493 memcpy(buffer+*to_base+*to, *from, *len);
494 *to += *len;
495 *len = 0;
496 }
497
498 ret = ltt_trace_generic(ltt_facility_user_generic_F583779E, event_user_generic_function_exit, buffer, reserve_size, LTT_BLOCKING);
3d57eb5b 499 }
500
501 return ret;
502
503}
504#endif //LTT_TRACE
505
506#endif //_LTT_FACILITY_USER_GENERIC_H_
This page took 0.040818 seconds and 4 git commands to generate.