40e58b85a0d06b5eeb01dc4d696c2555403532ef
[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 reserve_size = ltt_align(reserve_size, sizeof(void *));
502 {
503 ret = ltt_trace_generic(ltt_facility_user_generic_B1865E44, event_user_generic_slow_printf, buffer, reserve_size, LTT_BLOCKING);
504 }
505
506 return ret;
507
508 }
509 #endif //LTT_TRACE
510 #endif //!LTT_TRACE_FAST
511
512 #ifdef LTT_TRACE_FAST
513 static inline int trace_user_generic_slow_printf(
514 const char * lttng_param_string)
515 #ifndef LTT_TRACE
516 {
517 }
518 #else
519 {
520 unsigned int index;
521 struct ltt_trace_info *trace = thread_trace_info;
522 struct ltt_buf *ltt_buf;
523 char *buffer = NULL;
524 size_t real_to_base = 0; /* The buffer is allocated on arch_size alignment */
525 size_t *to_base = &real_to_base;
526 size_t real_to = 0;
527 size_t *to = &real_to;
528 size_t real_len = 0;
529 size_t *len = &real_len;
530 size_t reserve_size;
531 size_t slot_size;
532 const char *real_from;
533 const char **from = &real_from;
534 uint64_t tsc;
535 size_t before_hdr_pad, after_hdr_pad, header_size;
536
537 if(!trace) {
538 ltt_thread_init();
539 trace = thread_trace_info;
540 }
541
542
543 /* For each field, calculate the field size. */
544 /* size = *to_base + *to + *len */
545 /* Assume that the padding for alignment starts at a
546 * sizeof(void *) address. */
547
548 *from = (const char*)lttng_param_string;
549 lttng_write_string_user_generic_slow_printf_string(buffer, to_base, to, from, len, lttng_param_string);
550
551 reserve_size = *to_base + *to + *len;
552 trace->nesting++;
553 index = ltt_get_index_from_facility(ltt_facility_user_generic_B1865E44,
554 event_user_generic_slow_printf);
555
556 {
557 ltt_buf = ltt_get_channel_from_index(trace, index);
558 slot_size = 0;
559 buffer = ltt_reserve_slot(trace, ltt_buf,
560 reserve_size, &slot_size, &tsc,
561 &before_hdr_pad, &after_hdr_pad, &header_size);
562 if(!buffer) goto end; /* buffer full */
563
564 *to_base = *to = *len = 0;
565
566 ltt_write_event_header(trace, ltt_buf, buffer,
567 ltt_facility_user_generic_B1865E44, event_user_generic_slow_printf,
568 reserve_size, before_hdr_pad, tsc);
569 *to_base += before_hdr_pad + after_hdr_pad + header_size;
570
571 *from = (const char*)lttng_param_string;
572 lttng_write_string_user_generic_slow_printf_string(buffer, to_base, to, from, len, lttng_param_string);
573
574 /* Flush pending memcpy */
575 if(*len != 0) {
576 memcpy(buffer+*to_base+*to, *from, *len);
577 *to += *len;
578 *len = 0;
579 }
580
581 ltt_commit_slot(ltt_buf, buffer, slot_size);
582
583 }
584
585 end:
586 trace->nesting--;
587 }
588 #endif //LTT_TRACE
589 #endif //LTT_TRACE_FAST
590
591 /* Event function_entry structures */
592
593 /* Event function_entry logging function */
594 static inline __attribute__((no_instrument_function)) int trace_user_generic_function_entry(
595 const void * lttng_param_this_fn,
596 const void * lttng_param_call_site);
597
598 #ifndef LTT_TRACE_FAST
599 static inline int trace_user_generic_function_entry(
600 const void * lttng_param_this_fn,
601 const void * lttng_param_call_site)
602 #ifndef LTT_TRACE
603 {
604 }
605 #else
606 {
607 int ret = 0;
608 char *buffer = NULL;
609 size_t real_to_base = 0; /* The buffer is allocated on arch_size alignment */
610 size_t *to_base = &real_to_base;
611 size_t real_to = 0;
612 size_t *to = &real_to;
613 size_t real_len = 0;
614 size_t *len = &real_len;
615 size_t reserve_size;
616 size_t slot_size;
617 size_t align;
618 const char *real_from;
619 const char **from = &real_from;
620 /* For each field, calculate the field size. */
621 /* size = *to_base + *to + *len */
622 /* Assume that the padding for alignment starts at a
623 * sizeof(void *) address. */
624
625 *from = (const char*)&lttng_param_this_fn;
626 align = sizeof(const void *);
627
628 if(*len == 0) {
629 *to += ltt_align(*to, align); /* align output */
630 } else {
631 *len += ltt_align(*to+*len, align); /* alignment, ok to do a memcpy of it */
632 }
633
634 *len += sizeof(const void *);
635
636 *from = (const char*)&lttng_param_call_site;
637 align = sizeof(const void *);
638
639 if(*len == 0) {
640 *to += ltt_align(*to, align); /* align output */
641 } else {
642 *len += ltt_align(*to+*len, align); /* alignment, ok to do a memcpy of it */
643 }
644
645 *len += sizeof(const void *);
646
647 reserve_size = *to_base + *to + *len;
648 {
649 char stack_buffer[reserve_size];
650 buffer = stack_buffer;
651
652 *to_base = *to = *len = 0;
653
654 *from = (const char*)&lttng_param_this_fn;
655 align = sizeof(const void *);
656
657 if(*len == 0) {
658 *to += ltt_align(*to, align); /* align output */
659 } else {
660 *len += ltt_align(*to+*len, align); /* alignment, ok to do a memcpy of it */
661 }
662
663 *len += sizeof(const void *);
664
665 /* Flush pending memcpy */
666 if(*len != 0) {
667 memcpy(buffer+*to_base+*to, *from, *len);
668 *to += *len;
669 *len = 0;
670 }
671
672 *from = (const char*)&lttng_param_call_site;
673 align = sizeof(const void *);
674
675 if(*len == 0) {
676 *to += ltt_align(*to, align); /* align output */
677 } else {
678 *len += ltt_align(*to+*len, align); /* alignment, ok to do a memcpy of it */
679 }
680
681 *len += sizeof(const void *);
682
683 /* Flush pending memcpy */
684 if(*len != 0) {
685 memcpy(buffer+*to_base+*to, *from, *len);
686 *to += *len;
687 *len = 0;
688 }
689
690 ret = ltt_trace_generic(ltt_facility_user_generic_B1865E44, event_user_generic_function_entry, buffer, reserve_size, LTT_BLOCKING);
691 }
692
693 return ret;
694
695 }
696 #endif //LTT_TRACE
697 #endif //!LTT_TRACE_FAST
698
699 #ifdef LTT_TRACE_FAST
700 static inline __attribute__((no_instrument_function)) int trace_user_generic_function_entry(
701 const void * lttng_param_this_fn,
702 const void * lttng_param_call_site)
703 #ifndef LTT_TRACE
704 {
705 }
706 #else
707 {
708 unsigned int index;
709 struct ltt_trace_info *trace = thread_trace_info;
710 struct ltt_buf *ltt_buf;
711 char *buffer = NULL;
712 size_t real_to_base = 0; /* The buffer is allocated on arch_size alignment */
713 size_t *to_base = &real_to_base;
714 size_t real_to = 0;
715 size_t *to = &real_to;
716 size_t real_len = 0;
717 size_t *len = &real_len;
718 size_t reserve_size;
719 size_t slot_size;
720 size_t align;
721 const char *real_from;
722 const char **from = &real_from;
723 uint64_t tsc;
724 size_t before_hdr_pad, after_hdr_pad, header_size;
725
726 if(!trace) {
727 ltt_thread_init();
728 trace = thread_trace_info;
729 }
730
731
732 /* For each field, calculate the field size. */
733 /* size = *to_base + *to + *len */
734 /* Assume that the padding for alignment starts at a
735 * sizeof(void *) address. */
736
737 *from = (const char*)&lttng_param_this_fn;
738 align = sizeof(const void *);
739
740 if(*len == 0) {
741 *to += ltt_align(*to, align); /* align output */
742 } else {
743 *len += ltt_align(*to+*len, align); /* alignment, ok to do a memcpy of it */
744 }
745
746 *len += sizeof(const void *);
747
748 *from = (const char*)&lttng_param_call_site;
749 align = sizeof(const void *);
750
751 if(*len == 0) {
752 *to += ltt_align(*to, align); /* align output */
753 } else {
754 *len += ltt_align(*to+*len, align); /* alignment, ok to do a memcpy of it */
755 }
756
757 *len += sizeof(const void *);
758
759 reserve_size = *to_base + *to + *len;
760 trace->nesting++;
761 index = ltt_get_index_from_facility(ltt_facility_user_generic_B1865E44,
762 event_user_generic_function_entry);
763
764 {
765 ltt_buf = ltt_get_channel_from_index(trace, index);
766 slot_size = 0;
767 buffer = ltt_reserve_slot(trace, ltt_buf,
768 reserve_size, &slot_size, &tsc,
769 &before_hdr_pad, &after_hdr_pad, &header_size);
770 if(!buffer) goto end; /* buffer full */
771
772 *to_base = *to = *len = 0;
773
774 ltt_write_event_header(trace, ltt_buf, buffer,
775 ltt_facility_user_generic_B1865E44, event_user_generic_function_entry,
776 reserve_size, before_hdr_pad, tsc);
777 *to_base += before_hdr_pad + after_hdr_pad + header_size;
778
779 *from = (const char*)&lttng_param_this_fn;
780 align = sizeof(const void *);
781
782 if(*len == 0) {
783 *to += ltt_align(*to, align); /* align output */
784 } else {
785 *len += ltt_align(*to+*len, align); /* alignment, ok to do a memcpy of it */
786 }
787
788 *len += sizeof(const void *);
789
790 /* Flush pending memcpy */
791 if(*len != 0) {
792 memcpy(buffer+*to_base+*to, *from, *len);
793 *to += *len;
794 *len = 0;
795 }
796
797 *from = (const char*)&lttng_param_call_site;
798 align = sizeof(const void *);
799
800 if(*len == 0) {
801 *to += ltt_align(*to, align); /* align output */
802 } else {
803 *len += ltt_align(*to+*len, align); /* alignment, ok to do a memcpy of it */
804 }
805
806 *len += sizeof(const void *);
807
808 /* Flush pending memcpy */
809 if(*len != 0) {
810 memcpy(buffer+*to_base+*to, *from, *len);
811 *to += *len;
812 *len = 0;
813 }
814
815 ltt_commit_slot(ltt_buf, buffer, slot_size);
816
817 }
818
819 end:
820 trace->nesting--;
821 }
822 #endif //LTT_TRACE
823 #endif //LTT_TRACE_FAST
824
825 /* Event function_exit structures */
826
827 /* Event function_exit logging function */
828 static inline __attribute__((no_instrument_function)) int trace_user_generic_function_exit(
829 const void * lttng_param_this_fn,
830 const void * lttng_param_call_site);
831
832 #ifndef LTT_TRACE_FAST
833 static inline int trace_user_generic_function_exit(
834 const void * lttng_param_this_fn,
835 const void * lttng_param_call_site)
836 #ifndef LTT_TRACE
837 {
838 }
839 #else
840 {
841 int ret = 0;
842 char *buffer = NULL;
843 size_t real_to_base = 0; /* The buffer is allocated on arch_size alignment */
844 size_t *to_base = &real_to_base;
845 size_t real_to = 0;
846 size_t *to = &real_to;
847 size_t real_len = 0;
848 size_t *len = &real_len;
849 size_t reserve_size;
850 size_t slot_size;
851 size_t align;
852 const char *real_from;
853 const char **from = &real_from;
854 /* For each field, calculate the field size. */
855 /* size = *to_base + *to + *len */
856 /* Assume that the padding for alignment starts at a
857 * sizeof(void *) address. */
858
859 *from = (const char*)&lttng_param_this_fn;
860 align = sizeof(const void *);
861
862 if(*len == 0) {
863 *to += ltt_align(*to, align); /* align output */
864 } else {
865 *len += ltt_align(*to+*len, align); /* alignment, ok to do a memcpy of it */
866 }
867
868 *len += sizeof(const void *);
869
870 *from = (const char*)&lttng_param_call_site;
871 align = sizeof(const void *);
872
873 if(*len == 0) {
874 *to += ltt_align(*to, align); /* align output */
875 } else {
876 *len += ltt_align(*to+*len, align); /* alignment, ok to do a memcpy of it */
877 }
878
879 *len += sizeof(const void *);
880
881 reserve_size = *to_base + *to + *len;
882 {
883 char stack_buffer[reserve_size];
884 buffer = stack_buffer;
885
886 *to_base = *to = *len = 0;
887
888 *from = (const char*)&lttng_param_this_fn;
889 align = sizeof(const void *);
890
891 if(*len == 0) {
892 *to += ltt_align(*to, align); /* align output */
893 } else {
894 *len += ltt_align(*to+*len, align); /* alignment, ok to do a memcpy of it */
895 }
896
897 *len += sizeof(const void *);
898
899 /* Flush pending memcpy */
900 if(*len != 0) {
901 memcpy(buffer+*to_base+*to, *from, *len);
902 *to += *len;
903 *len = 0;
904 }
905
906 *from = (const char*)&lttng_param_call_site;
907 align = sizeof(const void *);
908
909 if(*len == 0) {
910 *to += ltt_align(*to, align); /* align output */
911 } else {
912 *len += ltt_align(*to+*len, align); /* alignment, ok to do a memcpy of it */
913 }
914
915 *len += sizeof(const void *);
916
917 /* Flush pending memcpy */
918 if(*len != 0) {
919 memcpy(buffer+*to_base+*to, *from, *len);
920 *to += *len;
921 *len = 0;
922 }
923
924 ret = ltt_trace_generic(ltt_facility_user_generic_B1865E44, event_user_generic_function_exit, buffer, reserve_size, LTT_BLOCKING);
925 }
926
927 return ret;
928
929 }
930 #endif //LTT_TRACE
931 #endif //!LTT_TRACE_FAST
932
933 #ifdef LTT_TRACE_FAST
934 static inline __attribute__((no_instrument_function)) int trace_user_generic_function_exit(
935 const void * lttng_param_this_fn,
936 const void * lttng_param_call_site)
937 #ifndef LTT_TRACE
938 {
939 }
940 #else
941 {
942 unsigned int index;
943 struct ltt_trace_info *trace = thread_trace_info;
944 struct ltt_buf *ltt_buf;
945 char *buffer = NULL;
946 size_t real_to_base = 0; /* The buffer is allocated on arch_size alignment */
947 size_t *to_base = &real_to_base;
948 size_t real_to = 0;
949 size_t *to = &real_to;
950 size_t real_len = 0;
951 size_t *len = &real_len;
952 size_t reserve_size;
953 size_t slot_size;
954 size_t align;
955 const char *real_from;
956 const char **from = &real_from;
957 uint64_t tsc;
958 size_t before_hdr_pad, after_hdr_pad, header_size;
959
960 if(!trace) {
961 ltt_thread_init();
962 trace = thread_trace_info;
963 }
964
965
966 /* For each field, calculate the field size. */
967 /* size = *to_base + *to + *len */
968 /* Assume that the padding for alignment starts at a
969 * sizeof(void *) address. */
970
971 *from = (const char*)&lttng_param_this_fn;
972 align = sizeof(const void *);
973
974 if(*len == 0) {
975 *to += ltt_align(*to, align); /* align output */
976 } else {
977 *len += ltt_align(*to+*len, align); /* alignment, ok to do a memcpy of it */
978 }
979
980 *len += sizeof(const void *);
981
982 *from = (const char*)&lttng_param_call_site;
983 align = sizeof(const void *);
984
985 if(*len == 0) {
986 *to += ltt_align(*to, align); /* align output */
987 } else {
988 *len += ltt_align(*to+*len, align); /* alignment, ok to do a memcpy of it */
989 }
990
991 *len += sizeof(const void *);
992
993 reserve_size = *to_base + *to + *len;
994 trace->nesting++;
995 index = ltt_get_index_from_facility(ltt_facility_user_generic_B1865E44,
996 event_user_generic_function_exit);
997
998 {
999 ltt_buf = ltt_get_channel_from_index(trace, index);
1000 slot_size = 0;
1001 buffer = ltt_reserve_slot(trace, ltt_buf,
1002 reserve_size, &slot_size, &tsc,
1003 &before_hdr_pad, &after_hdr_pad, &header_size);
1004 if(!buffer) goto end; /* buffer full */
1005
1006 *to_base = *to = *len = 0;
1007
1008 ltt_write_event_header(trace, ltt_buf, buffer,
1009 ltt_facility_user_generic_B1865E44, event_user_generic_function_exit,
1010 reserve_size, before_hdr_pad, tsc);
1011 *to_base += before_hdr_pad + after_hdr_pad + header_size;
1012
1013 *from = (const char*)&lttng_param_this_fn;
1014 align = sizeof(const void *);
1015
1016 if(*len == 0) {
1017 *to += ltt_align(*to, align); /* align output */
1018 } else {
1019 *len += ltt_align(*to+*len, align); /* alignment, ok to do a memcpy of it */
1020 }
1021
1022 *len += sizeof(const void *);
1023
1024 /* Flush pending memcpy */
1025 if(*len != 0) {
1026 memcpy(buffer+*to_base+*to, *from, *len);
1027 *to += *len;
1028 *len = 0;
1029 }
1030
1031 *from = (const char*)&lttng_param_call_site;
1032 align = sizeof(const void *);
1033
1034 if(*len == 0) {
1035 *to += ltt_align(*to, align); /* align output */
1036 } else {
1037 *len += ltt_align(*to+*len, align); /* alignment, ok to do a memcpy of it */
1038 }
1039
1040 *len += sizeof(const void *);
1041
1042 /* Flush pending memcpy */
1043 if(*len != 0) {
1044 memcpy(buffer+*to_base+*to, *from, *len);
1045 *to += *len;
1046 *len = 0;
1047 }
1048
1049 ltt_commit_slot(ltt_buf, buffer, slot_size);
1050
1051 }
1052
1053 end:
1054 trace->nesting--;
1055 }
1056 #endif //LTT_TRACE
1057 #endif //LTT_TRACE_FAST
1058
1059 /* Event thread_brand structures */
1060 static inline void lttng_write_string_user_generic_thread_brand_name(
1061 char *buffer,
1062 size_t *to_base,
1063 size_t *to,
1064 const char **from,
1065 size_t *len,
1066 const char * obj)
1067 {
1068 size_t size;
1069 size_t align;
1070
1071 /* Flush pending memcpy */
1072 if(*len != 0) {
1073 if(buffer != NULL)
1074 memcpy(buffer+*to_base+*to, *from, *len);
1075 }
1076 *to += *len;
1077 *len = 0;
1078
1079 align = sizeof(char);
1080
1081 if(*len == 0) {
1082 *to += ltt_align(*to, align); /* align output */
1083 } else {
1084 *len += ltt_align(*to+*len, align); /* alignment, ok to do a memcpy of it */
1085 }
1086
1087 /* Contains variable sized fields : must explode the structure */
1088
1089 size = strlen(obj) + 1; /* Include final NULL char. */
1090 if(buffer != NULL)
1091 memcpy(buffer+*to_base+*to, obj, size);
1092 *to += size;
1093
1094 /* Realign the *to_base on arch size, set *to to 0 */
1095 *to += ltt_align(*to, sizeof(void *));
1096 *to_base = *to_base+*to;
1097 *to = 0;
1098
1099 /* Put source *from just after the C string */
1100 *from += size;
1101 }
1102
1103
1104 /* Event thread_brand logging function */
1105 static inline int trace_user_generic_thread_brand(
1106 const char * lttng_param_name);
1107
1108 #ifndef LTT_TRACE_FAST
1109 static inline int trace_user_generic_thread_brand(
1110 const char * lttng_param_name)
1111 #ifndef LTT_TRACE
1112 {
1113 }
1114 #else
1115 {
1116 int ret = 0;
1117 char *buffer = NULL;
1118 size_t real_to_base = 0; /* The buffer is allocated on arch_size alignment */
1119 size_t *to_base = &real_to_base;
1120 size_t real_to = 0;
1121 size_t *to = &real_to;
1122 size_t real_len = 0;
1123 size_t *len = &real_len;
1124 size_t reserve_size;
1125 size_t slot_size;
1126 const char *real_from;
1127 const char **from = &real_from;
1128 /* For each field, calculate the field size. */
1129 /* size = *to_base + *to + *len */
1130 /* Assume that the padding for alignment starts at a
1131 * sizeof(void *) address. */
1132
1133 *from = (const char*)lttng_param_name;
1134 lttng_write_string_user_generic_thread_brand_name(buffer, to_base, to, from, len, lttng_param_name);
1135
1136 reserve_size = *to_base + *to + *len;
1137 {
1138 char stack_buffer[reserve_size];
1139 buffer = stack_buffer;
1140
1141 *to_base = *to = *len = 0;
1142
1143 *from = (const char*)lttng_param_name;
1144 lttng_write_string_user_generic_thread_brand_name(buffer, to_base, to, from, len, lttng_param_name);
1145
1146 /* Flush pending memcpy */
1147 if(*len != 0) {
1148 memcpy(buffer+*to_base+*to, *from, *len);
1149 *to += *len;
1150 *len = 0;
1151 }
1152
1153 ret = ltt_trace_generic(ltt_facility_user_generic_B1865E44, event_user_generic_thread_brand, buffer, reserve_size, LTT_BLOCKING);
1154 }
1155
1156 return ret;
1157
1158 }
1159 #endif //LTT_TRACE
1160 #endif //!LTT_TRACE_FAST
1161
1162 #ifdef LTT_TRACE_FAST
1163 static inline int trace_user_generic_thread_brand(
1164 const char * lttng_param_name)
1165 #ifndef LTT_TRACE
1166 {
1167 }
1168 #else
1169 {
1170 unsigned int index;
1171 struct ltt_trace_info *trace = thread_trace_info;
1172 struct ltt_buf *ltt_buf;
1173 char *buffer = NULL;
1174 size_t real_to_base = 0; /* The buffer is allocated on arch_size alignment */
1175 size_t *to_base = &real_to_base;
1176 size_t real_to = 0;
1177 size_t *to = &real_to;
1178 size_t real_len = 0;
1179 size_t *len = &real_len;
1180 size_t reserve_size;
1181 size_t slot_size;
1182 const char *real_from;
1183 const char **from = &real_from;
1184 uint64_t tsc;
1185 size_t before_hdr_pad, after_hdr_pad, header_size;
1186
1187 if(!trace) {
1188 ltt_thread_init();
1189 trace = thread_trace_info;
1190 }
1191
1192
1193 /* For each field, calculate the field size. */
1194 /* size = *to_base + *to + *len */
1195 /* Assume that the padding for alignment starts at a
1196 * sizeof(void *) address. */
1197
1198 *from = (const char*)lttng_param_name;
1199 lttng_write_string_user_generic_thread_brand_name(buffer, to_base, to, from, len, lttng_param_name);
1200
1201 reserve_size = *to_base + *to + *len;
1202 trace->nesting++;
1203 index = ltt_get_index_from_facility(ltt_facility_user_generic_B1865E44,
1204 event_user_generic_thread_brand);
1205
1206 {
1207 ltt_buf = ltt_get_channel_from_index(trace, index);
1208 slot_size = 0;
1209 buffer = ltt_reserve_slot(trace, ltt_buf,
1210 reserve_size, &slot_size, &tsc,
1211 &before_hdr_pad, &after_hdr_pad, &header_size);
1212 if(!buffer) goto end; /* buffer full */
1213
1214 *to_base = *to = *len = 0;
1215
1216 ltt_write_event_header(trace, ltt_buf, buffer,
1217 ltt_facility_user_generic_B1865E44, event_user_generic_thread_brand,
1218 reserve_size, before_hdr_pad, tsc);
1219 *to_base += before_hdr_pad + after_hdr_pad + header_size;
1220
1221 *from = (const char*)lttng_param_name;
1222 lttng_write_string_user_generic_thread_brand_name(buffer, to_base, to, from, len, lttng_param_name);
1223
1224 /* Flush pending memcpy */
1225 if(*len != 0) {
1226 memcpy(buffer+*to_base+*to, *from, *len);
1227 *to += *len;
1228 *len = 0;
1229 }
1230
1231 ltt_commit_slot(ltt_buf, buffer, slot_size);
1232
1233 }
1234
1235 end:
1236 trace->nesting--;
1237 }
1238 #endif //LTT_TRACE
1239 #endif //LTT_TRACE_FAST
1240
1241 #ifdef __cplusplus
1242 } /* end of extern "C" */
1243 #endif
1244
1245 #endif //_LTT_FACILITY_USER_GENERIC_H_
This page took 0.053226 seconds and 3 git commands to generate.