2 * SPDX-License-Identifier: LGPL-2.1-only
4 * Copyright (C) 2009 Pierre-Marc Fournier
5 * Copyright (C) 2011 Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
16 #include <sys/types.h>
19 * Work-around inet.h missing struct mmsghdr forward declaration, with
20 * triggers a warning when system files warnings are enabled.
23 #include <arpa/inet.h>
28 #define TRACEPOINT_DEFINE
29 #include "ust_tests_hello.h"
31 #include <lttng/ust-events.h>
32 #include <lttng/ringbuffer-context.h>
33 /* Internal header. */
34 #include <ust-context-provider.h>
36 static __thread
unsigned int test_count
;
39 void test_inc_count(void)
45 size_t test_get_size(struct lttng_ust_ctx_field
*field
__attribute__((unused
)), size_t offset
)
47 int sel
= test_count
% _NR_LTTNG_UST_DYNAMIC_TYPES
;
50 size
+= lttng_ust_lib_ring_buffer_align(offset
, lttng_ust_rb_alignof(char));
51 size
+= sizeof(char); /* tag */
53 case LTTNG_UST_DYNAMIC_TYPE_NONE
:
55 case LTTNG_UST_DYNAMIC_TYPE_S8
:
56 size
+= lttng_ust_lib_ring_buffer_align(offset
, lttng_ust_rb_alignof(int8_t));
57 size
+= sizeof(int8_t); /* variant */
59 case LTTNG_UST_DYNAMIC_TYPE_S16
:
60 size
+= lttng_ust_lib_ring_buffer_align(offset
, lttng_ust_rb_alignof(int16_t));
61 size
+= sizeof(int16_t); /* variant */
63 case LTTNG_UST_DYNAMIC_TYPE_S32
:
64 size
+= lttng_ust_lib_ring_buffer_align(offset
, lttng_ust_rb_alignof(int32_t));
65 size
+= sizeof(int32_t); /* variant */
67 case LTTNG_UST_DYNAMIC_TYPE_S64
:
68 size
+= lttng_ust_lib_ring_buffer_align(offset
, lttng_ust_rb_alignof(int64_t));
69 size
+= sizeof(int64_t); /* variant */
71 case LTTNG_UST_DYNAMIC_TYPE_U8
:
72 size
+= lttng_ust_lib_ring_buffer_align(offset
, lttng_ust_rb_alignof(uint8_t));
73 size
+= sizeof(uint8_t); /* variant */
75 case LTTNG_UST_DYNAMIC_TYPE_U16
:
76 size
+= lttng_ust_lib_ring_buffer_align(offset
, lttng_ust_rb_alignof(uint16_t));
77 size
+= sizeof(uint16_t); /* variant */
79 case LTTNG_UST_DYNAMIC_TYPE_U32
:
80 size
+= lttng_ust_lib_ring_buffer_align(offset
, lttng_ust_rb_alignof(uint32_t));
81 size
+= sizeof(uint32_t); /* variant */
83 case LTTNG_UST_DYNAMIC_TYPE_U64
:
84 size
+= lttng_ust_lib_ring_buffer_align(offset
, lttng_ust_rb_alignof(uint64_t));
85 size
+= sizeof(uint64_t); /* variant */
87 case LTTNG_UST_DYNAMIC_TYPE_FLOAT
:
88 size
+= lttng_ust_lib_ring_buffer_align(offset
, lttng_ust_rb_alignof(float));
89 size
+= sizeof(float); /* variant */
91 case LTTNG_UST_DYNAMIC_TYPE_DOUBLE
:
92 size
+= lttng_ust_lib_ring_buffer_align(offset
, lttng_ust_rb_alignof(double));
93 size
+= sizeof(double); /* variant */
95 case LTTNG_UST_DYNAMIC_TYPE_STRING
:
96 size
+= strlen("teststr") + 1;
106 void test_record(struct lttng_ust_ctx_field
*field
__attribute__((unused
)),
107 struct lttng_ust_lib_ring_buffer_ctx
*ctx
,
108 struct lttng_ust_channel_buffer
*lttng_chan_buf
)
110 int sel
= test_count
% _NR_LTTNG_UST_DYNAMIC_TYPES
;
111 char sel_char
= (char) sel
;
113 lttng_chan_buf
->ops
->event_write(ctx
, &sel_char
, sizeof(sel_char
), lttng_ust_rb_alignof(char));
115 case LTTNG_UST_DYNAMIC_TYPE_NONE
:
117 case LTTNG_UST_DYNAMIC_TYPE_S8
:
121 lttng_chan_buf
->ops
->event_write(ctx
, &v
, sizeof(v
), lttng_ust_rb_alignof(v
));
124 case LTTNG_UST_DYNAMIC_TYPE_S16
:
128 lttng_chan_buf
->ops
->event_write(ctx
, &v
, sizeof(v
), lttng_ust_rb_alignof(v
));
131 case LTTNG_UST_DYNAMIC_TYPE_S32
:
135 lttng_chan_buf
->ops
->event_write(ctx
, &v
, sizeof(v
), lttng_ust_rb_alignof(v
));
138 case LTTNG_UST_DYNAMIC_TYPE_S64
:
142 lttng_chan_buf
->ops
->event_write(ctx
, &v
, sizeof(v
), lttng_ust_rb_alignof(v
));
145 case LTTNG_UST_DYNAMIC_TYPE_U8
:
149 lttng_chan_buf
->ops
->event_write(ctx
, &v
, sizeof(v
), lttng_ust_rb_alignof(v
));
152 case LTTNG_UST_DYNAMIC_TYPE_U16
:
156 lttng_chan_buf
->ops
->event_write(ctx
, &v
, sizeof(v
), lttng_ust_rb_alignof(v
));
159 case LTTNG_UST_DYNAMIC_TYPE_U32
:
163 lttng_chan_buf
->ops
->event_write(ctx
, &v
, sizeof(v
), lttng_ust_rb_alignof(v
));
166 case LTTNG_UST_DYNAMIC_TYPE_U64
:
170 lttng_chan_buf
->ops
->event_write(ctx
, &v
, sizeof(v
), lttng_ust_rb_alignof(v
));
173 case LTTNG_UST_DYNAMIC_TYPE_FLOAT
:
177 lttng_chan_buf
->ops
->event_write(ctx
, &f
, sizeof(f
), lttng_ust_rb_alignof(f
));
180 case LTTNG_UST_DYNAMIC_TYPE_DOUBLE
:
184 lttng_chan_buf
->ops
->event_write(ctx
, &d
, sizeof(d
), lttng_ust_rb_alignof(d
));
187 case LTTNG_UST_DYNAMIC_TYPE_STRING
:
189 const char *str
= "teststr";
190 lttng_chan_buf
->ops
->event_write(ctx
, str
, strlen(str
) + 1, 1);
199 void test_get_value(struct lttng_ust_ctx_field
*field
__attribute__((unused
)),
200 struct lttng_ust_ctx_value
*value
)
202 int sel
= test_count
% _NR_LTTNG_UST_DYNAMIC_TYPES
;
206 case LTTNG_UST_DYNAMIC_TYPE_NONE
:
208 case LTTNG_UST_DYNAMIC_TYPE_S8
:
211 case LTTNG_UST_DYNAMIC_TYPE_S16
:
214 case LTTNG_UST_DYNAMIC_TYPE_S32
:
217 case LTTNG_UST_DYNAMIC_TYPE_S64
:
220 case LTTNG_UST_DYNAMIC_TYPE_U8
:
223 case LTTNG_UST_DYNAMIC_TYPE_U16
:
226 case LTTNG_UST_DYNAMIC_TYPE_U32
:
229 case LTTNG_UST_DYNAMIC_TYPE_U64
:
232 case LTTNG_UST_DYNAMIC_TYPE_FLOAT
:
233 value
->u
.d
= 22322.0;
235 case LTTNG_UST_DYNAMIC_TYPE_DOUBLE
:
238 case LTTNG_UST_DYNAMIC_TYPE_STRING
:
239 value
->u
.str
= "teststr";
246 static char myprovider_name
[] = "$app.myprovider";
247 struct lttng_ust_context_provider myprovider
= {
248 .struct_size
= sizeof(struct lttng_ust_context_provider
),
249 .name
= myprovider_name
,
250 .get_size
= test_get_size
,
251 .record
= test_record
,
252 .get_value
= test_get_value
,
256 void inthandler(int sig
__attribute__((unused
)))
258 printf("in SIGUSR1 handler\n");
259 tracepoint(ust_tests_hello
, tptest_sighandler
);
263 int init_int_handler(void)
266 struct sigaction act
;
268 memset(&act
, 0, sizeof(act
));
269 result
= sigemptyset(&act
.sa_mask
);
271 perror("sigemptyset");
275 act
.sa_handler
= inthandler
;
276 act
.sa_flags
= SA_RESTART
;
278 /* Only defer ourselves. Also, try to restart interrupted
279 * syscalls to disturb the traced program as little as possible.
281 result
= sigaction(SIGUSR1
, &act
, NULL
);
290 int main(int argc
, char **argv
)
293 long values
[] = { 1, 2, 3 };
294 char text
[10] = "test";
298 bool mybool
= 123; /* should print "1" */
303 delay
= atoi(argv
[1]);
305 if (lttng_ust_context_provider_register(&myprovider
))
308 fprintf(stderr
, "Hello, World!\n");
312 fprintf(stderr
, "Tracing... ");
313 for (i
= 0; i
< 1000000; i
++) {
315 tracepoint(ust_tests_hello
, tptest
, i
, netint
, values
,
316 text
, strlen(text
), dbl
, flt
, mybool
);
320 lttng_ust_context_provider_unregister(&myprovider
);
321 fprintf(stderr
, " done.\n");