fix usertrace and genevent for printf alignment
[lttv.git] / ltt-usertrace / ltt / ltt-facility-user_generic.h
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-usertrace.h>
7
8 #ifdef __cplusplus
9 extern "C" {
10 #endif
11
12 /* Named types */
13
14 /* Event string structures */
15 static inline void lttng_write_string_user_generic_string_data(
16 char *buffer,
17 size_t *to_base,
18 size_t *to,
19 const char **from,
20 size_t *len,
21 const char * obj)
22 {
23 size_t size;
24 size_t align;
25
26 /* Flush pending memcpy */
27 if(*len != 0) {
28 if(buffer != NULL)
29 memcpy(buffer+*to_base+*to, *from, *len);
30 }
31 *to += *len;
32 *len = 0;
33
34 align = sizeof(char);
35
36 if(*len == 0) {
37 *to += ltt_align(*to, align); /* align output */
38 } else {
39 *len += ltt_align(*to+*len, align); /* alignment, ok to do a memcpy of it */
40 }
41
42 /* Contains variable sized fields : must explode the structure */
43
44 size = strlen(obj) + 1; /* Include final NULL char. */
45 if(buffer != NULL)
46 memcpy(buffer+*to_base+*to, obj, size);
47 *to += size;
48
49 /* Realign the *to_base on arch size, set *to to 0 */
50 *to += ltt_align(*to, sizeof(void *));
51 *to_base = *to_base+*to;
52 *to = 0;
53
54 /* Put source *from just after the C string */
55 *from += size;
56 }
57
58
59 /* Event string logging function */
60 static inline int trace_user_generic_string(
61 const char * lttng_param_data);
62
63 #ifndef LTT_TRACE_FAST
64 static inline int trace_user_generic_string(
65 const char * lttng_param_data)
66 #ifndef LTT_TRACE
67 {
68 }
69 #else
70 {
71 int ret = 0;
72 char *buffer = NULL;
73 size_t real_to_base = 0; /* The buffer is allocated on arch_size alignment */
74 size_t *to_base = &real_to_base;
75 size_t real_to = 0;
76 size_t *to = &real_to;
77 size_t real_len = 0;
78 size_t *len = &real_len;
79 size_t reserve_size;
80 size_t slot_size;
81 const char *real_from;
82 const char **from = &real_from;
83 /* For each field, calculate the field size. */
84 /* size = *to_base + *to + *len */
85 /* Assume that the padding for alignment starts at a
86 * sizeof(void *) address. */
87
88 *from = (const char*)lttng_param_data;
89 lttng_write_string_user_generic_string_data(buffer, to_base, to, from, len, lttng_param_data);
90
91 reserve_size = *to_base + *to + *len;
92 {
93 char stack_buffer[reserve_size];
94 buffer = stack_buffer;
95
96 *to_base = *to = *len = 0;
97
98 *from = (const char*)lttng_param_data;
99 lttng_write_string_user_generic_string_data(buffer, to_base, to, from, len, lttng_param_data);
100
101 /* Flush pending memcpy */
102 if(*len != 0) {
103 memcpy(buffer+*to_base+*to, *from, *len);
104 *to += *len;
105 *len = 0;
106 }
107
108 ret = ltt_trace_generic(ltt_facility_user_generic_B1865E44, event_user_generic_string, buffer, reserve_size, LTT_BLOCKING);
109 }
110
111 return ret;
112
113 }
114 #endif //LTT_TRACE
115 #endif //!LTT_TRACE_FAST
116
117 #ifdef LTT_TRACE_FAST
118 static inline int trace_user_generic_string(
119 const char * lttng_param_data)
120 #ifndef LTT_TRACE
121 {
122 }
123 #else
124 {
125 unsigned int index;
126 struct ltt_trace_info *trace = thread_trace_info;
127 struct ltt_buf *ltt_buf;
128 char *buffer = NULL;
129 size_t real_to_base = 0; /* The buffer is allocated on arch_size alignment */
130 size_t *to_base = &real_to_base;
131 size_t real_to = 0;
132 size_t *to = &real_to;
133 size_t real_len = 0;
134 size_t *len = &real_len;
135 size_t reserve_size;
136 size_t slot_size;
137 const char *real_from;
138 const char **from = &real_from;
139 uint64_t tsc;
140 size_t before_hdr_pad, after_hdr_pad, header_size;
141
142 if(!trace) {
143 ltt_thread_init();
144 trace = thread_trace_info;
145 }
146
147
148 /* For each field, calculate the field size. */
149 /* size = *to_base + *to + *len */
150 /* Assume that the padding for alignment starts at a
151 * sizeof(void *) address. */
152
153 *from = (const char*)lttng_param_data;
154 lttng_write_string_user_generic_string_data(buffer, to_base, to, from, len, lttng_param_data);
155
156 reserve_size = *to_base + *to + *len;
157 trace->nesting++;
158 index = ltt_get_index_from_facility(ltt_facility_user_generic_B1865E44,
159 event_user_generic_string);
160
161 {
162 ltt_buf = ltt_get_channel_from_index(trace, index);
163 slot_size = 0;
164 buffer = ltt_reserve_slot(trace, ltt_buf,
165 reserve_size, &slot_size, &tsc,
166 &before_hdr_pad, &after_hdr_pad, &header_size);
167 if(!buffer) goto end; /* buffer full */
168
169 *to_base = *to = *len = 0;
170
171 ltt_write_event_header(trace, ltt_buf, buffer,
172 ltt_facility_user_generic_B1865E44, event_user_generic_string,
173 reserve_size, before_hdr_pad, tsc);
174 *to_base += before_hdr_pad + after_hdr_pad + header_size;
175
176 *from = (const char*)lttng_param_data;
177 lttng_write_string_user_generic_string_data(buffer, to_base, to, from, len, lttng_param_data);
178
179 /* Flush pending memcpy */
180 if(*len != 0) {
181 memcpy(buffer+*to_base+*to, *from, *len);
182 *to += *len;
183 *len = 0;
184 }
185
186 ltt_commit_slot(ltt_buf, buffer, slot_size);
187
188 }
189
190 end:
191 trace->nesting--;
192 }
193 #endif //LTT_TRACE
194 #endif //LTT_TRACE_FAST
195
196 /* Event string_pointer structures */
197 static inline void lttng_write_string_user_generic_string_pointer_string(
198 char *buffer,
199 size_t *to_base,
200 size_t *to,
201 const char **from,
202 size_t *len,
203 const char * obj)
204 {
205 size_t size;
206 size_t align;
207
208 /* Flush pending memcpy */
209 if(*len != 0) {
210 if(buffer != NULL)
211 memcpy(buffer+*to_base+*to, *from, *len);
212 }
213 *to += *len;
214 *len = 0;
215
216 align = sizeof(char);
217
218 if(*len == 0) {
219 *to += ltt_align(*to, align); /* align output */
220 } else {
221 *len += ltt_align(*to+*len, align); /* alignment, ok to do a memcpy of it */
222 }
223
224 /* Contains variable sized fields : must explode the structure */
225
226 size = strlen(obj) + 1; /* Include final NULL char. */
227 if(buffer != NULL)
228 memcpy(buffer+*to_base+*to, obj, size);
229 *to += size;
230
231 /* Realign the *to_base on arch size, set *to to 0 */
232 *to += ltt_align(*to, sizeof(void *));
233 *to_base = *to_base+*to;
234 *to = 0;
235
236 /* Put source *from just after the C string */
237 *from += size;
238 }
239
240
241 /* Event string_pointer logging function */
242 static inline int trace_user_generic_string_pointer(
243 const char * lttng_param_string,
244 const void * lttng_param_pointer);
245
246 #ifndef LTT_TRACE_FAST
247 static inline int trace_user_generic_string_pointer(
248 const char * lttng_param_string,
249 const void * lttng_param_pointer)
250 #ifndef LTT_TRACE
251 {
252 }
253 #else
254 {
255 int ret = 0;
256 char *buffer = NULL;
257 size_t real_to_base = 0; /* The buffer is allocated on arch_size alignment */
258 size_t *to_base = &real_to_base;
259 size_t real_to = 0;
260 size_t *to = &real_to;
261 size_t real_len = 0;
262 size_t *len = &real_len;
263 size_t reserve_size;
264 size_t slot_size;
265 size_t align;
266 const char *real_from;
267 const char **from = &real_from;
268 /* For each field, calculate the field size. */
269 /* size = *to_base + *to + *len */
270 /* Assume that the padding for alignment starts at a
271 * sizeof(void *) address. */
272
273 *from = (const char*)lttng_param_string;
274 lttng_write_string_user_generic_string_pointer_string(buffer, to_base, to, from, len, lttng_param_string);
275
276 *from = (const char*)&lttng_param_pointer;
277 align = sizeof(const void *);
278
279 if(*len == 0) {
280 *to += ltt_align(*to, align); /* align output */
281 } else {
282 *len += ltt_align(*to+*len, align); /* alignment, ok to do a memcpy of it */
283 }
284
285 *len += sizeof(const void *);
286
287 reserve_size = *to_base + *to + *len;
288 {
289 char stack_buffer[reserve_size];
290 buffer = stack_buffer;
291
292 *to_base = *to = *len = 0;
293
294 *from = (const char*)lttng_param_string;
295 lttng_write_string_user_generic_string_pointer_string(buffer, to_base, to, from, len, lttng_param_string);
296
297 /* Flush pending memcpy */
298 if(*len != 0) {
299 memcpy(buffer+*to_base+*to, *from, *len);
300 *to += *len;
301 *len = 0;
302 }
303
304 *from = (const char*)&lttng_param_pointer;
305 align = sizeof(const void *);
306
307 if(*len == 0) {
308 *to += ltt_align(*to, align); /* align output */
309 } else {
310 *len += ltt_align(*to+*len, align); /* alignment, ok to do a memcpy of it */
311 }
312
313 *len += sizeof(const void *);
314
315 /* Flush pending memcpy */
316 if(*len != 0) {
317 memcpy(buffer+*to_base+*to, *from, *len);
318 *to += *len;
319 *len = 0;
320 }
321
322 ret = ltt_trace_generic(ltt_facility_user_generic_B1865E44, event_user_generic_string_pointer, buffer, reserve_size, LTT_BLOCKING);
323 }
324
325 return ret;
326
327 }
328 #endif //LTT_TRACE
329 #endif //!LTT_TRACE_FAST
330
331 #ifdef LTT_TRACE_FAST
332 static inline int trace_user_generic_string_pointer(
333 const char * lttng_param_string,
334 const void * lttng_param_pointer)
335 #ifndef LTT_TRACE
336 {
337 }
338 #else
339 {
340 unsigned int index;
341 struct ltt_trace_info *trace = thread_trace_info;
342 struct ltt_buf *ltt_buf;
343 char *buffer = NULL;
344 size_t real_to_base = 0; /* The buffer is allocated on arch_size alignment */
345 size_t *to_base = &real_to_base;
346 size_t real_to = 0;
347 size_t *to = &real_to;
348 size_t real_len = 0;
349 size_t *len = &real_len;
350 size_t reserve_size;
351 size_t slot_size;
352 size_t align;
353 const char *real_from;
354 const char **from = &real_from;
355 uint64_t tsc;
356 size_t before_hdr_pad, after_hdr_pad, header_size;
357
358 if(!trace) {
359 ltt_thread_init();
360 trace = thread_trace_info;
361 }
362
363
364 /* For each field, calculate the field size. */
365 /* size = *to_base + *to + *len */
366 /* Assume that the padding for alignment starts at a
367 * sizeof(void *) address. */
368
369 *from = (const char*)lttng_param_string;
370 lttng_write_string_user_generic_string_pointer_string(buffer, to_base, to, from, len, lttng_param_string);
371
372 *from = (const char*)&lttng_param_pointer;
373 align = sizeof(const void *);
374
375 if(*len == 0) {
376 *to += ltt_align(*to, align); /* align output */
377 } else {
378 *len += ltt_align(*to+*len, align); /* alignment, ok to do a memcpy of it */
379 }
380
381 *len += sizeof(const void *);
382
383 reserve_size = *to_base + *to + *len;
384 trace->nesting++;
385 index = ltt_get_index_from_facility(ltt_facility_user_generic_B1865E44,
386 event_user_generic_string_pointer);
387
388 {
389 ltt_buf = ltt_get_channel_from_index(trace, index);
390 slot_size = 0;
391 buffer = ltt_reserve_slot(trace, ltt_buf,
392 reserve_size, &slot_size, &tsc,
393 &before_hdr_pad, &after_hdr_pad, &header_size);
394 if(!buffer) goto end; /* buffer full */
395
396 *to_base = *to = *len = 0;
397
398 ltt_write_event_header(trace, ltt_buf, buffer,
399 ltt_facility_user_generic_B1865E44, event_user_generic_string_pointer,
400 reserve_size, before_hdr_pad, tsc);
401 *to_base += before_hdr_pad + after_hdr_pad + header_size;
402
403 *from = (const char*)lttng_param_string;
404 lttng_write_string_user_generic_string_pointer_string(buffer, to_base, to, from, len, lttng_param_string);
405
406 /* Flush pending memcpy */
407 if(*len != 0) {
408 memcpy(buffer+*to_base+*to, *from, *len);
409 *to += *len;
410 *len = 0;
411 }
412
413 *from = (const char*)&lttng_param_pointer;
414 align = sizeof(const void *);
415
416 if(*len == 0) {
417 *to += ltt_align(*to, align); /* align output */
418 } else {
419 *len += ltt_align(*to+*len, align); /* alignment, ok to do a memcpy of it */
420 }
421
422 *len += sizeof(const void *);
423
424 /* Flush pending memcpy */
425 if(*len != 0) {
426 memcpy(buffer+*to_base+*to, *from, *len);
427 *to += *len;
428 *len = 0;
429 }
430
431 ltt_commit_slot(ltt_buf, buffer, slot_size);
432
433 }
434
435 end:
436 trace->nesting--;
437 }
438 #endif //LTT_TRACE
439 #endif //LTT_TRACE_FAST
440
441 /* Event slow_printf structures */
442 static inline void lttng_write_string_user_generic_slow_printf_string(
443 char *buffer,
444 size_t *to_base,
445 size_t *to,
446 const char **from,
447 size_t *len,
448 const char * obj)
449 {
450 size_t size;
451 size_t align;
452
453 /* Flush pending memcpy */
454 if(*len != 0) {
455 if(buffer != NULL)
456 memcpy(buffer+*to_base+*to, *from, *len);
457 }
458 *to += *len;
459 *len = 0;
460
461 align = sizeof(char);
462
463 if(*len == 0) {
464 *to += ltt_align(*to, align); /* align output */
465 } else {
466 *len += ltt_align(*to+*len, align); /* alignment, ok to do a memcpy of it */
467 }
468
469 /* Contains variable sized fields : must explode the structure */
470
471 size = strlen(obj) + 1; /* Include final NULL char. */
472 if(buffer != NULL)
473 memcpy(buffer+*to_base+*to, obj, size);
474 *to += size;
475
476 /* Realign the *to_base on arch size, set *to to 0 */
477 *to += ltt_align(*to, sizeof(void *));
478 *to_base = *to_base+*to;
479 *to = 0;
480
481 /* Put source *from just after the C string */
482 *from += size;
483 }
484
485
486 /* Event slow_printf logging function */
487 static inline int trace_user_generic_slow_printf_param_buffer(
488 char *buffer,
489 size_t reserve_size);
490
491 #ifndef LTT_TRACE_FAST
492 static inline int trace_user_generic_slow_printf_param_buffer(
493 char *buffer,
494 size_t reserve_size)
495 #ifndef LTT_TRACE
496 {
497 }
498 #else
499 {
500 int ret = 0;
501 {
502 ret = ltt_trace_generic(ltt_facility_user_generic_B1865E44, event_user_generic_slow_printf, buffer, reserve_size, LTT_BLOCKING);
503 }
504
505 return ret;
506
507 }
508 #endif //LTT_TRACE
509 #endif //!LTT_TRACE_FAST
510
511 #ifdef LTT_TRACE_FAST
512 static inline int trace_user_generic_slow_printf(
513 const char * lttng_param_string)
514 #ifndef LTT_TRACE
515 {
516 }
517 #else
518 {
519 unsigned int index;
520 struct ltt_trace_info *trace = thread_trace_info;
521 struct ltt_buf *ltt_buf;
522 char *buffer = NULL;
523 size_t real_to_base = 0; /* The buffer is allocated on arch_size alignment */
524 size_t *to_base = &real_to_base;
525 size_t real_to = 0;
526 size_t *to = &real_to;
527 size_t real_len = 0;
528 size_t *len = &real_len;
529 size_t reserve_size;
530 size_t slot_size;
531 const char *real_from;
532 const char **from = &real_from;
533 uint64_t tsc;
534 size_t before_hdr_pad, after_hdr_pad, header_size;
535
536 if(!trace) {
537 ltt_thread_init();
538 trace = thread_trace_info;
539 }
540
541
542 /* For each field, calculate the field size. */
543 /* size = *to_base + *to + *len */
544 /* Assume that the padding for alignment starts at a
545 * sizeof(void *) address. */
546
547 *from = (const char*)lttng_param_string;
548 lttng_write_string_user_generic_slow_printf_string(buffer, to_base, to, from, len, lttng_param_string);
549
550 reserve_size = *to_base + *to + *len;
551 trace->nesting++;
552 index = ltt_get_index_from_facility(ltt_facility_user_generic_B1865E44,
553 event_user_generic_slow_printf);
554
555 {
556 ltt_buf = ltt_get_channel_from_index(trace, index);
557 slot_size = 0;
558 buffer = ltt_reserve_slot(trace, ltt_buf,
559 reserve_size, &slot_size, &tsc,
560 &before_hdr_pad, &after_hdr_pad, &header_size);
561 if(!buffer) goto end; /* buffer full */
562
563 *to_base = *to = *len = 0;
564
565 ltt_write_event_header(trace, ltt_buf, buffer,
566 ltt_facility_user_generic_B1865E44, event_user_generic_slow_printf,
567 reserve_size, before_hdr_pad, tsc);
568 *to_base += before_hdr_pad + after_hdr_pad + header_size;
569
570 *from = (const char*)lttng_param_string;
571 lttng_write_string_user_generic_slow_printf_string(buffer, to_base, to, from, len, lttng_param_string);
572
573 /* Flush pending memcpy */
574 if(*len != 0) {
575 memcpy(buffer+*to_base+*to, *from, *len);
576 *to += *len;
577 *len = 0;
578 }
579
580 ltt_commit_slot(ltt_buf, buffer, slot_size);
581
582 }
583
584 end:
585 trace->nesting--;
586 }
587 #endif //LTT_TRACE
588 #endif //LTT_TRACE_FAST
589
590 /* Event function_entry structures */
591
592 /* Event function_entry logging function */
593 static inline __attribute__((no_instrument_function)) int trace_user_generic_function_entry(
594 const void * lttng_param_this_fn,
595 const void * lttng_param_call_site);
596
597 #ifndef LTT_TRACE_FAST
598 static inline int trace_user_generic_function_entry(
599 const void * lttng_param_this_fn,
600 const void * lttng_param_call_site)
601 #ifndef LTT_TRACE
602 {
603 }
604 #else
605 {
606 int ret = 0;
607 char *buffer = NULL;
608 size_t real_to_base = 0; /* The buffer is allocated on arch_size alignment */
609 size_t *to_base = &real_to_base;
610 size_t real_to = 0;
611 size_t *to = &real_to;
612 size_t real_len = 0;
613 size_t *len = &real_len;
614 size_t reserve_size;
615 size_t slot_size;
616 size_t align;
617 const char *real_from;
618 const char **from = &real_from;
619 /* For each field, calculate the field size. */
620 /* size = *to_base + *to + *len */
621 /* Assume that the padding for alignment starts at a
622 * sizeof(void *) address. */
623
624 *from = (const char*)&lttng_param_this_fn;
625 align = sizeof(const void *);
626
627 if(*len == 0) {
628 *to += ltt_align(*to, align); /* align output */
629 } else {
630 *len += ltt_align(*to+*len, align); /* alignment, ok to do a memcpy of it */
631 }
632
633 *len += sizeof(const void *);
634
635 *from = (const char*)&lttng_param_call_site;
636 align = sizeof(const void *);
637
638 if(*len == 0) {
639 *to += ltt_align(*to, align); /* align output */
640 } else {
641 *len += ltt_align(*to+*len, align); /* alignment, ok to do a memcpy of it */
642 }
643
644 *len += sizeof(const void *);
645
646 reserve_size = *to_base + *to + *len;
647 {
648 char stack_buffer[reserve_size];
649 buffer = stack_buffer;
650
651 *to_base = *to = *len = 0;
652
653 *from = (const char*)&lttng_param_this_fn;
654 align = sizeof(const void *);
655
656 if(*len == 0) {
657 *to += ltt_align(*to, align); /* align output */
658 } else {
659 *len += ltt_align(*to+*len, align); /* alignment, ok to do a memcpy of it */
660 }
661
662 *len += sizeof(const void *);
663
664 /* Flush pending memcpy */
665 if(*len != 0) {
666 memcpy(buffer+*to_base+*to, *from, *len);
667 *to += *len;
668 *len = 0;
669 }
670
671 *from = (const char*)&lttng_param_call_site;
672 align = sizeof(const void *);
673
674 if(*len == 0) {
675 *to += ltt_align(*to, align); /* align output */
676 } else {
677 *len += ltt_align(*to+*len, align); /* alignment, ok to do a memcpy of it */
678 }
679
680 *len += sizeof(const void *);
681
682 /* Flush pending memcpy */
683 if(*len != 0) {
684 memcpy(buffer+*to_base+*to, *from, *len);
685 *to += *len;
686 *len = 0;
687 }
688
689 ret = ltt_trace_generic(ltt_facility_user_generic_B1865E44, event_user_generic_function_entry, buffer, reserve_size, LTT_BLOCKING);
690 }
691
692 return ret;
693
694 }
695 #endif //LTT_TRACE
696 #endif //!LTT_TRACE_FAST
697
698 #ifdef LTT_TRACE_FAST
699 static inline __attribute__((no_instrument_function)) int trace_user_generic_function_entry(
700 const void * lttng_param_this_fn,
701 const void * lttng_param_call_site)
702 #ifndef LTT_TRACE
703 {
704 }
705 #else
706 {
707 unsigned int index;
708 struct ltt_trace_info *trace = thread_trace_info;
709 struct ltt_buf *ltt_buf;
710 char *buffer = NULL;
711 size_t real_to_base = 0; /* The buffer is allocated on arch_size alignment */
712 size_t *to_base = &real_to_base;
713 size_t real_to = 0;
714 size_t *to = &real_to;
715 size_t real_len = 0;
716 size_t *len = &real_len;
717 size_t reserve_size;
718 size_t slot_size;
719 size_t align;
720 const char *real_from;
721 const char **from = &real_from;
722 uint64_t tsc;
723 size_t before_hdr_pad, after_hdr_pad, header_size;
724
725 if(!trace) {
726 ltt_thread_init();
727 trace = thread_trace_info;
728 }
729
730
731 /* For each field, calculate the field size. */
732 /* size = *to_base + *to + *len */
733 /* Assume that the padding for alignment starts at a
734 * sizeof(void *) address. */
735
736 *from = (const char*)&lttng_param_this_fn;
737 align = sizeof(const void *);
738
739 if(*len == 0) {
740 *to += ltt_align(*to, align); /* align output */
741 } else {
742 *len += ltt_align(*to+*len, align); /* alignment, ok to do a memcpy of it */
743 }
744
745 *len += sizeof(const void *);
746
747 *from = (const char*)&lttng_param_call_site;
748 align = sizeof(const void *);
749
750 if(*len == 0) {
751 *to += ltt_align(*to, align); /* align output */
752 } else {
753 *len += ltt_align(*to+*len, align); /* alignment, ok to do a memcpy of it */
754 }
755
756 *len += sizeof(const void *);
757
758 reserve_size = *to_base + *to + *len;
759 trace->nesting++;
760 index = ltt_get_index_from_facility(ltt_facility_user_generic_B1865E44,
761 event_user_generic_function_entry);
762
763 {
764 ltt_buf = ltt_get_channel_from_index(trace, index);
765 slot_size = 0;
766 buffer = ltt_reserve_slot(trace, ltt_buf,
767 reserve_size, &slot_size, &tsc,
768 &before_hdr_pad, &after_hdr_pad, &header_size);
769 if(!buffer) goto end; /* buffer full */
770
771 *to_base = *to = *len = 0;
772
773 ltt_write_event_header(trace, ltt_buf, buffer,
774 ltt_facility_user_generic_B1865E44, event_user_generic_function_entry,
775 reserve_size, before_hdr_pad, tsc);
776 *to_base += before_hdr_pad + after_hdr_pad + header_size;
777
778 *from = (const char*)&lttng_param_this_fn;
779 align = sizeof(const void *);
780
781 if(*len == 0) {
782 *to += ltt_align(*to, align); /* align output */
783 } else {
784 *len += ltt_align(*to+*len, align); /* alignment, ok to do a memcpy of it */
785 }
786
787 *len += sizeof(const void *);
788
789 /* Flush pending memcpy */
790 if(*len != 0) {
791 memcpy(buffer+*to_base+*to, *from, *len);
792 *to += *len;
793 *len = 0;
794 }
795
796 *from = (const char*)&lttng_param_call_site;
797 align = sizeof(const void *);
798
799 if(*len == 0) {
800 *to += ltt_align(*to, align); /* align output */
801 } else {
802 *len += ltt_align(*to+*len, align); /* alignment, ok to do a memcpy of it */
803 }
804
805 *len += sizeof(const void *);
806
807 /* Flush pending memcpy */
808 if(*len != 0) {
809 memcpy(buffer+*to_base+*to, *from, *len);
810 *to += *len;
811 *len = 0;
812 }
813
814 ltt_commit_slot(ltt_buf, buffer, slot_size);
815
816 }
817
818 end:
819 trace->nesting--;
820 }
821 #endif //LTT_TRACE
822 #endif //LTT_TRACE_FAST
823
824 /* Event function_exit structures */
825
826 /* Event function_exit logging function */
827 static inline __attribute__((no_instrument_function)) int trace_user_generic_function_exit(
828 const void * lttng_param_this_fn,
829 const void * lttng_param_call_site);
830
831 #ifndef LTT_TRACE_FAST
832 static inline int trace_user_generic_function_exit(
833 const void * lttng_param_this_fn,
834 const void * lttng_param_call_site)
835 #ifndef LTT_TRACE
836 {
837 }
838 #else
839 {
840 int ret = 0;
841 char *buffer = NULL;
842 size_t real_to_base = 0; /* The buffer is allocated on arch_size alignment */
843 size_t *to_base = &real_to_base;
844 size_t real_to = 0;
845 size_t *to = &real_to;
846 size_t real_len = 0;
847 size_t *len = &real_len;
848 size_t reserve_size;
849 size_t slot_size;
850 size_t align;
851 const char *real_from;
852 const char **from = &real_from;
853 /* For each field, calculate the field size. */
854 /* size = *to_base + *to + *len */
855 /* Assume that the padding for alignment starts at a
856 * sizeof(void *) address. */
857
858 *from = (const char*)&lttng_param_this_fn;
859 align = sizeof(const void *);
860
861 if(*len == 0) {
862 *to += ltt_align(*to, align); /* align output */
863 } else {
864 *len += ltt_align(*to+*len, align); /* alignment, ok to do a memcpy of it */
865 }
866
867 *len += sizeof(const void *);
868
869 *from = (const char*)&lttng_param_call_site;
870 align = sizeof(const void *);
871
872 if(*len == 0) {
873 *to += ltt_align(*to, align); /* align output */
874 } else {
875 *len += ltt_align(*to+*len, align); /* alignment, ok to do a memcpy of it */
876 }
877
878 *len += sizeof(const void *);
879
880 reserve_size = *to_base + *to + *len;
881 {
882 char stack_buffer[reserve_size];
883 buffer = stack_buffer;
884
885 *to_base = *to = *len = 0;
886
887 *from = (const char*)&lttng_param_this_fn;
888 align = sizeof(const void *);
889
890 if(*len == 0) {
891 *to += ltt_align(*to, align); /* align output */
892 } else {
893 *len += ltt_align(*to+*len, align); /* alignment, ok to do a memcpy of it */
894 }
895
896 *len += sizeof(const void *);
897
898 /* Flush pending memcpy */
899 if(*len != 0) {
900 memcpy(buffer+*to_base+*to, *from, *len);
901 *to += *len;
902 *len = 0;
903 }
904
905 *from = (const char*)&lttng_param_call_site;
906 align = sizeof(const void *);
907
908 if(*len == 0) {
909 *to += ltt_align(*to, align); /* align output */
910 } else {
911 *len += ltt_align(*to+*len, align); /* alignment, ok to do a memcpy of it */
912 }
913
914 *len += sizeof(const void *);
915
916 /* Flush pending memcpy */
917 if(*len != 0) {
918 memcpy(buffer+*to_base+*to, *from, *len);
919 *to += *len;
920 *len = 0;
921 }
922
923 ret = ltt_trace_generic(ltt_facility_user_generic_B1865E44, event_user_generic_function_exit, buffer, reserve_size, LTT_BLOCKING);
924 }
925
926 return ret;
927
928 }
929 #endif //LTT_TRACE
930 #endif //!LTT_TRACE_FAST
931
932 #ifdef LTT_TRACE_FAST
933 static inline __attribute__((no_instrument_function)) int trace_user_generic_function_exit(
934 const void * lttng_param_this_fn,
935 const void * lttng_param_call_site)
936 #ifndef LTT_TRACE
937 {
938 }
939 #else
940 {
941 unsigned int index;
942 struct ltt_trace_info *trace = thread_trace_info;
943 struct ltt_buf *ltt_buf;
944 char *buffer = NULL;
945 size_t real_to_base = 0; /* The buffer is allocated on arch_size alignment */
946 size_t *to_base = &real_to_base;
947 size_t real_to = 0;
948 size_t *to = &real_to;
949 size_t real_len = 0;
950 size_t *len = &real_len;
951 size_t reserve_size;
952 size_t slot_size;
953 size_t align;
954 const char *real_from;
955 const char **from = &real_from;
956 uint64_t tsc;
957 size_t before_hdr_pad, after_hdr_pad, header_size;
958
959 if(!trace) {
960 ltt_thread_init();
961 trace = thread_trace_info;
962 }
963
964
965 /* For each field, calculate the field size. */
966 /* size = *to_base + *to + *len */
967 /* Assume that the padding for alignment starts at a
968 * sizeof(void *) address. */
969
970 *from = (const char*)&lttng_param_this_fn;
971 align = sizeof(const void *);
972
973 if(*len == 0) {
974 *to += ltt_align(*to, align); /* align output */
975 } else {
976 *len += ltt_align(*to+*len, align); /* alignment, ok to do a memcpy of it */
977 }
978
979 *len += sizeof(const void *);
980
981 *from = (const char*)&lttng_param_call_site;
982 align = sizeof(const void *);
983
984 if(*len == 0) {
985 *to += ltt_align(*to, align); /* align output */
986 } else {
987 *len += ltt_align(*to+*len, align); /* alignment, ok to do a memcpy of it */
988 }
989
990 *len += sizeof(const void *);
991
992 reserve_size = *to_base + *to + *len;
993 trace->nesting++;
994 index = ltt_get_index_from_facility(ltt_facility_user_generic_B1865E44,
995 event_user_generic_function_exit);
996
997 {
998 ltt_buf = ltt_get_channel_from_index(trace, index);
999 slot_size = 0;
1000 buffer = ltt_reserve_slot(trace, ltt_buf,
1001 reserve_size, &slot_size, &tsc,
1002 &before_hdr_pad, &after_hdr_pad, &header_size);
1003 if(!buffer) goto end; /* buffer full */
1004
1005 *to_base = *to = *len = 0;
1006
1007 ltt_write_event_header(trace, ltt_buf, buffer,
1008 ltt_facility_user_generic_B1865E44, event_user_generic_function_exit,
1009 reserve_size, before_hdr_pad, tsc);
1010 *to_base += before_hdr_pad + after_hdr_pad + header_size;
1011
1012 *from = (const char*)&lttng_param_this_fn;
1013 align = sizeof(const void *);
1014
1015 if(*len == 0) {
1016 *to += ltt_align(*to, align); /* align output */
1017 } else {
1018 *len += ltt_align(*to+*len, align); /* alignment, ok to do a memcpy of it */
1019 }
1020
1021 *len += sizeof(const void *);
1022
1023 /* Flush pending memcpy */
1024 if(*len != 0) {
1025 memcpy(buffer+*to_base+*to, *from, *len);
1026 *to += *len;
1027 *len = 0;
1028 }
1029
1030 *from = (const char*)&lttng_param_call_site;
1031 align = sizeof(const void *);
1032
1033 if(*len == 0) {
1034 *to += ltt_align(*to, align); /* align output */
1035 } else {
1036 *len += ltt_align(*to+*len, align); /* alignment, ok to do a memcpy of it */
1037 }
1038
1039 *len += sizeof(const void *);
1040
1041 /* Flush pending memcpy */
1042 if(*len != 0) {
1043 memcpy(buffer+*to_base+*to, *from, *len);
1044 *to += *len;
1045 *len = 0;
1046 }
1047
1048 ltt_commit_slot(ltt_buf, buffer, slot_size);
1049
1050 }
1051
1052 end:
1053 trace->nesting--;
1054 }
1055 #endif //LTT_TRACE
1056 #endif //LTT_TRACE_FAST
1057
1058 /* Event thread_brand structures */
1059 static inline void lttng_write_string_user_generic_thread_brand_name(
1060 char *buffer,
1061 size_t *to_base,
1062 size_t *to,
1063 const char **from,
1064 size_t *len,
1065 const char * obj)
1066 {
1067 size_t size;
1068 size_t align;
1069
1070 /* Flush pending memcpy */
1071 if(*len != 0) {
1072 if(buffer != NULL)
1073 memcpy(buffer+*to_base+*to, *from, *len);
1074 }
1075 *to += *len;
1076 *len = 0;
1077
1078 align = sizeof(char);
1079
1080 if(*len == 0) {
1081 *to += ltt_align(*to, align); /* align output */
1082 } else {
1083 *len += ltt_align(*to+*len, align); /* alignment, ok to do a memcpy of it */
1084 }
1085
1086 /* Contains variable sized fields : must explode the structure */
1087
1088 size = strlen(obj) + 1; /* Include final NULL char. */
1089 if(buffer != NULL)
1090 memcpy(buffer+*to_base+*to, obj, size);
1091 *to += size;
1092
1093 /* Realign the *to_base on arch size, set *to to 0 */
1094 *to += ltt_align(*to, sizeof(void *));
1095 *to_base = *to_base+*to;
1096 *to = 0;
1097
1098 /* Put source *from just after the C string */
1099 *from += size;
1100 }
1101
1102
1103 /* Event thread_brand logging function */
1104 static inline int trace_user_generic_thread_brand(
1105 const char * lttng_param_name);
1106
1107 #ifndef LTT_TRACE_FAST
1108 static inline int trace_user_generic_thread_brand(
1109 const char * lttng_param_name)
1110 #ifndef LTT_TRACE
1111 {
1112 }
1113 #else
1114 {
1115 int ret = 0;
1116 char *buffer = NULL;
1117 size_t real_to_base = 0; /* The buffer is allocated on arch_size alignment */
1118 size_t *to_base = &real_to_base;
1119 size_t real_to = 0;
1120 size_t *to = &real_to;
1121 size_t real_len = 0;
1122 size_t *len = &real_len;
1123 size_t reserve_size;
1124 size_t slot_size;
1125 const char *real_from;
1126 const char **from = &real_from;
1127 /* For each field, calculate the field size. */
1128 /* size = *to_base + *to + *len */
1129 /* Assume that the padding for alignment starts at a
1130 * sizeof(void *) address. */
1131
1132 *from = (const char*)lttng_param_name;
1133 lttng_write_string_user_generic_thread_brand_name(buffer, to_base, to, from, len, lttng_param_name);
1134
1135 reserve_size = *to_base + *to + *len;
1136 {
1137 char stack_buffer[reserve_size];
1138 buffer = stack_buffer;
1139
1140 *to_base = *to = *len = 0;
1141
1142 *from = (const char*)lttng_param_name;
1143 lttng_write_string_user_generic_thread_brand_name(buffer, to_base, to, from, len, lttng_param_name);
1144
1145 /* Flush pending memcpy */
1146 if(*len != 0) {
1147 memcpy(buffer+*to_base+*to, *from, *len);
1148 *to += *len;
1149 *len = 0;
1150 }
1151
1152 ret = ltt_trace_generic(ltt_facility_user_generic_B1865E44, event_user_generic_thread_brand, buffer, reserve_size, LTT_BLOCKING);
1153 }
1154
1155 return ret;
1156
1157 }
1158 #endif //LTT_TRACE
1159 #endif //!LTT_TRACE_FAST
1160
1161 #ifdef LTT_TRACE_FAST
1162 static inline int trace_user_generic_thread_brand(
1163 const char * lttng_param_name)
1164 #ifndef LTT_TRACE
1165 {
1166 }
1167 #else
1168 {
1169 unsigned int index;
1170 struct ltt_trace_info *trace = thread_trace_info;
1171 struct ltt_buf *ltt_buf;
1172 char *buffer = NULL;
1173 size_t real_to_base = 0; /* The buffer is allocated on arch_size alignment */
1174 size_t *to_base = &real_to_base;
1175 size_t real_to = 0;
1176 size_t *to = &real_to;
1177 size_t real_len = 0;
1178 size_t *len = &real_len;
1179 size_t reserve_size;
1180 size_t slot_size;
1181 const char *real_from;
1182 const char **from = &real_from;
1183 uint64_t tsc;
1184 size_t before_hdr_pad, after_hdr_pad, header_size;
1185
1186 if(!trace) {
1187 ltt_thread_init();
1188 trace = thread_trace_info;
1189 }
1190
1191
1192 /* For each field, calculate the field size. */
1193 /* size = *to_base + *to + *len */
1194 /* Assume that the padding for alignment starts at a
1195 * sizeof(void *) address. */
1196
1197 *from = (const char*)lttng_param_name;
1198 lttng_write_string_user_generic_thread_brand_name(buffer, to_base, to, from, len, lttng_param_name);
1199
1200 reserve_size = *to_base + *to + *len;
1201 trace->nesting++;
1202 index = ltt_get_index_from_facility(ltt_facility_user_generic_B1865E44,
1203 event_user_generic_thread_brand);
1204
1205 {
1206 ltt_buf = ltt_get_channel_from_index(trace, index);
1207 slot_size = 0;
1208 buffer = ltt_reserve_slot(trace, ltt_buf,
1209 reserve_size, &slot_size, &tsc,
1210 &before_hdr_pad, &after_hdr_pad, &header_size);
1211 if(!buffer) goto end; /* buffer full */
1212
1213 *to_base = *to = *len = 0;
1214
1215 ltt_write_event_header(trace, ltt_buf, buffer,
1216 ltt_facility_user_generic_B1865E44, event_user_generic_thread_brand,
1217 reserve_size, before_hdr_pad, tsc);
1218 *to_base += before_hdr_pad + after_hdr_pad + header_size;
1219
1220 *from = (const char*)lttng_param_name;
1221 lttng_write_string_user_generic_thread_brand_name(buffer, to_base, to, from, len, lttng_param_name);
1222
1223 /* Flush pending memcpy */
1224 if(*len != 0) {
1225 memcpy(buffer+*to_base+*to, *from, *len);
1226 *to += *len;
1227 *len = 0;
1228 }
1229
1230 ltt_commit_slot(ltt_buf, buffer, slot_size);
1231
1232 }
1233
1234 end:
1235 trace->nesting--;
1236 }
1237 #endif //LTT_TRACE
1238 #endif //LTT_TRACE_FAST
1239
1240 #ifdef __cplusplus
1241 } /* end of extern "C" */
1242 #endif
1243
1244 #endif //_LTT_FACILITY_USER_GENERIC_H_
This page took 0.053366 seconds and 4 git commands to generate.