2 * Copyright (C) 2009 Pierre-Marc Fournier
3 * Copyright (C) 2011 Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; version 2.1 of
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
24 #include <sys/types.h>
30 * Work-around inet.h missing struct mmsghdr forward declaration, with
31 * triggers a warning when system files warnings are enabled.
34 #include <arpa/inet.h>
38 #define TRACEPOINT_DEFINE
39 #include "ust_tests_hello.h"
41 /* Internal header. */
42 #include <lttng/ust-events.h>
43 #include <lttng/ringbuffer-config.h>
44 #include <lttng/ust-context-provider.h>
46 static __thread
unsigned int test_count
;
48 void test_inc_count(void)
54 size_t test_get_size(struct lttng_ctx_field
*field
, size_t offset
)
56 int sel
= test_count
% _NR_LTTNG_UST_DYNAMIC_TYPES
;
59 size
+= lib_ring_buffer_align(offset
, lttng_alignof(char));
60 size
+= sizeof(char); /* tag */
62 case LTTNG_UST_DYNAMIC_TYPE_NONE
:
64 case LTTNG_UST_DYNAMIC_TYPE_S8
:
65 size
+= lib_ring_buffer_align(offset
, lttng_alignof(int8_t));
66 size
+= sizeof(int8_t); /* variant */
68 case LTTNG_UST_DYNAMIC_TYPE_S16
:
69 size
+= lib_ring_buffer_align(offset
, lttng_alignof(int16_t));
70 size
+= sizeof(int16_t); /* variant */
72 case LTTNG_UST_DYNAMIC_TYPE_S32
:
73 size
+= lib_ring_buffer_align(offset
, lttng_alignof(int32_t));
74 size
+= sizeof(int32_t); /* variant */
76 case LTTNG_UST_DYNAMIC_TYPE_S64
:
77 size
+= lib_ring_buffer_align(offset
, lttng_alignof(int64_t));
78 size
+= sizeof(int64_t); /* variant */
80 case LTTNG_UST_DYNAMIC_TYPE_U8
:
81 size
+= lib_ring_buffer_align(offset
, lttng_alignof(uint8_t));
82 size
+= sizeof(uint8_t); /* variant */
84 case LTTNG_UST_DYNAMIC_TYPE_U16
:
85 size
+= lib_ring_buffer_align(offset
, lttng_alignof(uint16_t));
86 size
+= sizeof(uint16_t); /* variant */
88 case LTTNG_UST_DYNAMIC_TYPE_U32
:
89 size
+= lib_ring_buffer_align(offset
, lttng_alignof(uint32_t));
90 size
+= sizeof(uint32_t); /* variant */
92 case LTTNG_UST_DYNAMIC_TYPE_U64
:
93 size
+= lib_ring_buffer_align(offset
, lttng_alignof(uint64_t));
94 size
+= sizeof(uint64_t); /* variant */
96 case LTTNG_UST_DYNAMIC_TYPE_FLOAT
:
97 size
+= lib_ring_buffer_align(offset
, lttng_alignof(float));
98 size
+= sizeof(float); /* variant */
100 case LTTNG_UST_DYNAMIC_TYPE_DOUBLE
:
101 size
+= lib_ring_buffer_align(offset
, lttng_alignof(double));
102 size
+= sizeof(double); /* variant */
104 case LTTNG_UST_DYNAMIC_TYPE_STRING
:
105 size
+= strlen("teststr") + 1;
115 void test_record(struct lttng_ctx_field
*field
,
116 struct lttng_ust_lib_ring_buffer_ctx
*ctx
,
117 struct lttng_channel
*chan
)
119 int sel
= test_count
% _NR_LTTNG_UST_DYNAMIC_TYPES
;
120 char sel_char
= (char) sel
;
122 lib_ring_buffer_align_ctx(ctx
, lttng_alignof(char));
123 chan
->ops
->event_write(ctx
, &sel_char
, sizeof(sel_char
));
125 case LTTNG_UST_DYNAMIC_TYPE_NONE
:
127 case LTTNG_UST_DYNAMIC_TYPE_S8
:
131 lib_ring_buffer_align_ctx(ctx
, lttng_alignof(v
));
132 chan
->ops
->event_write(ctx
, &v
, sizeof(v
));
135 case LTTNG_UST_DYNAMIC_TYPE_S16
:
139 lib_ring_buffer_align_ctx(ctx
, lttng_alignof(v
));
140 chan
->ops
->event_write(ctx
, &v
, sizeof(v
));
143 case LTTNG_UST_DYNAMIC_TYPE_S32
:
147 lib_ring_buffer_align_ctx(ctx
, lttng_alignof(v
));
148 chan
->ops
->event_write(ctx
, &v
, sizeof(v
));
151 case LTTNG_UST_DYNAMIC_TYPE_S64
:
155 lib_ring_buffer_align_ctx(ctx
, lttng_alignof(v
));
156 chan
->ops
->event_write(ctx
, &v
, sizeof(v
));
159 case LTTNG_UST_DYNAMIC_TYPE_U8
:
163 lib_ring_buffer_align_ctx(ctx
, lttng_alignof(v
));
164 chan
->ops
->event_write(ctx
, &v
, sizeof(v
));
167 case LTTNG_UST_DYNAMIC_TYPE_U16
:
171 lib_ring_buffer_align_ctx(ctx
, lttng_alignof(v
));
172 chan
->ops
->event_write(ctx
, &v
, sizeof(v
));
175 case LTTNG_UST_DYNAMIC_TYPE_U32
:
179 lib_ring_buffer_align_ctx(ctx
, lttng_alignof(v
));
180 chan
->ops
->event_write(ctx
, &v
, sizeof(v
));
183 case LTTNG_UST_DYNAMIC_TYPE_U64
:
187 lib_ring_buffer_align_ctx(ctx
, lttng_alignof(v
));
188 chan
->ops
->event_write(ctx
, &v
, sizeof(v
));
191 case LTTNG_UST_DYNAMIC_TYPE_FLOAT
:
195 lib_ring_buffer_align_ctx(ctx
, lttng_alignof(f
));
196 chan
->ops
->event_write(ctx
, &f
, sizeof(f
));
199 case LTTNG_UST_DYNAMIC_TYPE_DOUBLE
:
203 lib_ring_buffer_align_ctx(ctx
, lttng_alignof(d
));
204 chan
->ops
->event_write(ctx
, &d
, sizeof(d
));
207 case LTTNG_UST_DYNAMIC_TYPE_STRING
:
209 const char *str
= "teststr";
210 chan
->ops
->event_write(ctx
, str
, strlen(str
) + 1);
219 void test_get_value(struct lttng_ctx_field
*field
,
220 struct lttng_ctx_value
*value
)
222 int sel
= test_count
% _NR_LTTNG_UST_DYNAMIC_TYPES
;
226 case LTTNG_UST_DYNAMIC_TYPE_NONE
:
228 case LTTNG_UST_DYNAMIC_TYPE_S8
:
231 case LTTNG_UST_DYNAMIC_TYPE_S16
:
234 case LTTNG_UST_DYNAMIC_TYPE_S32
:
237 case LTTNG_UST_DYNAMIC_TYPE_S64
:
240 case LTTNG_UST_DYNAMIC_TYPE_U8
:
243 case LTTNG_UST_DYNAMIC_TYPE_U16
:
246 case LTTNG_UST_DYNAMIC_TYPE_U32
:
249 case LTTNG_UST_DYNAMIC_TYPE_U64
:
252 case LTTNG_UST_DYNAMIC_TYPE_FLOAT
:
253 value
->u
.d
= 22322.0;
255 case LTTNG_UST_DYNAMIC_TYPE_DOUBLE
:
258 case LTTNG_UST_DYNAMIC_TYPE_STRING
:
259 value
->u
.str
= "teststr";
266 struct lttng_ust_context_provider myprovider
= {
267 .name
= "$app.myprovider",
268 .get_size
= test_get_size
,
269 .record
= test_record
,
270 .get_value
= test_get_value
,
273 void inthandler(int sig
)
275 printf("in SIGUSR1 handler\n");
276 tracepoint(ust_tests_hello
, tptest_sighandler
);
279 int init_int_handler(void)
282 struct sigaction act
;
284 memset(&act
, 0, sizeof(act
));
285 result
= sigemptyset(&act
.sa_mask
);
287 perror("sigemptyset");
291 act
.sa_handler
= inthandler
;
292 act
.sa_flags
= SA_RESTART
;
294 /* Only defer ourselves. Also, try to restart interrupted
295 * syscalls to disturb the traced program as little as possible.
297 result
= sigaction(SIGUSR1
, &act
, NULL
);
306 void test_inc_count(void);
308 int main(int argc
, char **argv
)
311 long values
[] = { 1, 2, 3 };
312 char text
[10] = "test";
316 bool mybool
= 123; /* should print "1" */
321 delay
= atoi(argv
[1]);
323 if (lttng_ust_context_provider_register(&myprovider
))
326 fprintf(stderr
, "Hello, World!\n");
330 fprintf(stderr
, "Tracing... ");
331 for (i
= 0; i
< 1000000; i
++) {
333 tracepoint(ust_tests_hello
, tptest
, i
, netint
, values
,
334 text
, strlen(text
), dbl
, flt
, mybool
);
338 lttng_ust_context_provider_unregister(&myprovider
);
339 fprintf(stderr
, " done.\n");