move everything out of trunk
[lttv.git] / tests / user / ltt / ltt-facility-user_tests.h
1 #ifndef _LTT_FACILITY_USER_TESTS_H_
2 #define _LTT_FACILITY_USER_TESTS_H_
3
4 #include <sys/types.h>
5 #include <ltt/ltt-facility-id-user_tests.h>
6 #include <ltt/ltt-usertrace.h>
7
8 /* Named types */
9
10 /* Event write_4bytes structures */
11
12 /* Event write_4bytes logging function */
13 #ifndef LTT_TRACE_FAST
14 static inline int trace_user_tests_write_4bytes(
15 int lttng_param_data)
16 #ifndef LTT_TRACE
17 {
18 }
19 #else
20 {
21 int ret = 0;
22 void *buffer = NULL;
23 size_t real_to_base = 0; /* The buffer is allocated on arch_size alignment */
24 size_t *to_base = &real_to_base;
25 size_t real_to = 0;
26 size_t *to = &real_to;
27 size_t real_len = 0;
28 size_t *len = &real_len;
29 size_t reserve_size;
30 size_t slot_size;
31 size_t align;
32 const void *real_from;
33 const void **from = &real_from;
34 /* For each field, calculate the field size. */
35 /* size = *to_base + *to + *len */
36 /* Assume that the padding for alignment starts at a
37 * sizeof(void *) address. */
38
39 *from = &lttng_param_data;
40 align = sizeof(int);
41
42 if(*len == 0) {
43 *to += ltt_align(*to, align); /* align output */
44 } else {
45 *len += ltt_align(*to+*len, align); /* alignment, ok to do a memcpy of it */
46 }
47
48 *len += sizeof(int);
49
50 reserve_size = *to_base + *to + *len;
51 {
52 char stack_buffer[reserve_size];
53 buffer = stack_buffer;
54
55 *to_base = *to = *len = 0;
56
57 *from = &lttng_param_data;
58 align = sizeof(int);
59
60 if(*len == 0) {
61 *to += ltt_align(*to, align); /* align output */
62 } else {
63 *len += ltt_align(*to+*len, align); /* alignment, ok to do a memcpy of it */
64 }
65
66 *len += sizeof(int);
67
68 /* Flush pending memcpy */
69 if(*len != 0) {
70 memcpy(buffer+*to_base+*to, *from, *len);
71 *to += *len;
72 *len = 0;
73 }
74
75 ret = ltt_trace_generic(ltt_facility_user_tests_CDD24456, event_user_tests_write_4bytes, buffer, reserve_size, LTT_BLOCKING);
76 }
77
78 return ret;
79
80 }
81 #endif //LTT_TRACE
82 #endif //!LTT_TRACE_FAST
83
84 #ifdef LTT_TRACE_FAST
85 static inline int trace_user_tests_write_4bytes(
86 int lttng_param_data)
87 #ifndef LTT_TRACE
88 {
89 }
90 #else
91 {
92 unsigned int index;
93 struct ltt_trace_info *trace = thread_trace_info;
94 struct ltt_buf *ltt_buf;
95 void *buffer = NULL;
96 size_t real_to_base = 0; /* The buffer is allocated on arch_size alignment */
97 size_t *to_base = &real_to_base;
98 size_t real_to = 0;
99 size_t *to = &real_to;
100 size_t real_len = 0;
101 size_t *len = &real_len;
102 size_t reserve_size;
103 size_t slot_size;
104 size_t align;
105 const void *real_from;
106 const void **from = &real_from;
107 uint64_t tsc;
108 size_t before_hdr_pad, after_hdr_pad, header_size;
109
110 if(!trace) {
111 ltt_thread_init();
112 trace = thread_trace_info;
113 }
114
115
116 /* For each field, calculate the field size. */
117 /* size = *to_base + *to + *len */
118 /* Assume that the padding for alignment starts at a
119 * sizeof(void *) address. */
120
121 *from = &lttng_param_data;
122 align = sizeof(int);
123
124 if(*len == 0) {
125 *to += ltt_align(*to, align); /* align output */
126 } else {
127 *len += ltt_align(*to+*len, align); /* alignment, ok to do a memcpy of it */
128 }
129
130 *len += sizeof(int);
131
132 reserve_size = *to_base + *to + *len;
133 trace->nesting++;
134 index = ltt_get_index_from_facility(ltt_facility_user_tests_CDD24456,
135 event_user_tests_write_4bytes);
136
137 {
138 ltt_buf = ltt_get_channel_from_index(trace, index);
139 slot_size = 0;
140 buffer = ltt_reserve_slot(trace, ltt_buf,
141 reserve_size, &slot_size, &tsc,
142 &before_hdr_pad, &after_hdr_pad, &header_size);
143 if(!buffer) goto end; /* buffer full */
144
145 *to_base = *to = *len = 0;
146
147 ltt_write_event_header(trace, ltt_buf, buffer,
148 ltt_facility_user_tests_CDD24456, event_user_tests_write_4bytes,
149 reserve_size, before_hdr_pad, tsc);
150 *to_base += before_hdr_pad + after_hdr_pad + header_size;
151
152 *from = &lttng_param_data;
153 align = sizeof(int);
154
155 if(*len == 0) {
156 *to += ltt_align(*to, align); /* align output */
157 } else {
158 *len += ltt_align(*to+*len, align); /* alignment, ok to do a memcpy of it */
159 }
160
161 *len += sizeof(int);
162
163 /* Flush pending memcpy */
164 if(*len != 0) {
165 memcpy(buffer+*to_base+*to, *from, *len);
166 *to += *len;
167 *len = 0;
168 }
169
170 ltt_commit_slot(ltt_buf, buffer, slot_size);
171
172 }
173
174 end:
175 trace->nesting--;
176 }
177 #endif //LTT_TRACE
178 #endif //LTT_TRACE_FAST
179
180 #endif //_LTT_FACILITY_USER_TESTS_H_
This page took 0.03349 seconds and 4 git commands to generate.