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
;
38 void test_inc_count(void)
44 size_t test_get_size(struct lttng_ust_ctx_field
*field
, size_t offset
)
46 int sel
= test_count
% _NR_LTTNG_UST_DYNAMIC_TYPES
;
49 size
+= lib_ring_buffer_align(offset
, lttng_alignof(char));
50 size
+= sizeof(char); /* tag */
52 case LTTNG_UST_DYNAMIC_TYPE_NONE
:
54 case LTTNG_UST_DYNAMIC_TYPE_S8
:
55 size
+= lib_ring_buffer_align(offset
, lttng_alignof(int8_t));
56 size
+= sizeof(int8_t); /* variant */
58 case LTTNG_UST_DYNAMIC_TYPE_S16
:
59 size
+= lib_ring_buffer_align(offset
, lttng_alignof(int16_t));
60 size
+= sizeof(int16_t); /* variant */
62 case LTTNG_UST_DYNAMIC_TYPE_S32
:
63 size
+= lib_ring_buffer_align(offset
, lttng_alignof(int32_t));
64 size
+= sizeof(int32_t); /* variant */
66 case LTTNG_UST_DYNAMIC_TYPE_S64
:
67 size
+= lib_ring_buffer_align(offset
, lttng_alignof(int64_t));
68 size
+= sizeof(int64_t); /* variant */
70 case LTTNG_UST_DYNAMIC_TYPE_U8
:
71 size
+= lib_ring_buffer_align(offset
, lttng_alignof(uint8_t));
72 size
+= sizeof(uint8_t); /* variant */
74 case LTTNG_UST_DYNAMIC_TYPE_U16
:
75 size
+= lib_ring_buffer_align(offset
, lttng_alignof(uint16_t));
76 size
+= sizeof(uint16_t); /* variant */
78 case LTTNG_UST_DYNAMIC_TYPE_U32
:
79 size
+= lib_ring_buffer_align(offset
, lttng_alignof(uint32_t));
80 size
+= sizeof(uint32_t); /* variant */
82 case LTTNG_UST_DYNAMIC_TYPE_U64
:
83 size
+= lib_ring_buffer_align(offset
, lttng_alignof(uint64_t));
84 size
+= sizeof(uint64_t); /* variant */
86 case LTTNG_UST_DYNAMIC_TYPE_FLOAT
:
87 size
+= lib_ring_buffer_align(offset
, lttng_alignof(float));
88 size
+= sizeof(float); /* variant */
90 case LTTNG_UST_DYNAMIC_TYPE_DOUBLE
:
91 size
+= lib_ring_buffer_align(offset
, lttng_alignof(double));
92 size
+= sizeof(double); /* variant */
94 case LTTNG_UST_DYNAMIC_TYPE_STRING
:
95 size
+= strlen("teststr") + 1;
105 void test_record(struct lttng_ust_ctx_field
*field
,
106 struct lttng_ust_lib_ring_buffer_ctx
*ctx
,
107 struct lttng_ust_channel_buffer
*lttng_chan_buf
)
109 int sel
= test_count
% _NR_LTTNG_UST_DYNAMIC_TYPES
;
110 char sel_char
= (char) sel
;
112 lib_ring_buffer_align_ctx(ctx
, lttng_alignof(char));
113 lttng_chan_buf
->ops
->event_write(ctx
, &sel_char
, sizeof(sel_char
));
115 case LTTNG_UST_DYNAMIC_TYPE_NONE
:
117 case LTTNG_UST_DYNAMIC_TYPE_S8
:
121 lib_ring_buffer_align_ctx(ctx
, lttng_alignof(v
));
122 lttng_chan_buf
->ops
->event_write(ctx
, &v
, sizeof(v
));
125 case LTTNG_UST_DYNAMIC_TYPE_S16
:
129 lib_ring_buffer_align_ctx(ctx
, lttng_alignof(v
));
130 lttng_chan_buf
->ops
->event_write(ctx
, &v
, sizeof(v
));
133 case LTTNG_UST_DYNAMIC_TYPE_S32
:
137 lib_ring_buffer_align_ctx(ctx
, lttng_alignof(v
));
138 lttng_chan_buf
->ops
->event_write(ctx
, &v
, sizeof(v
));
141 case LTTNG_UST_DYNAMIC_TYPE_S64
:
145 lib_ring_buffer_align_ctx(ctx
, lttng_alignof(v
));
146 lttng_chan_buf
->ops
->event_write(ctx
, &v
, sizeof(v
));
149 case LTTNG_UST_DYNAMIC_TYPE_U8
:
153 lib_ring_buffer_align_ctx(ctx
, lttng_alignof(v
));
154 lttng_chan_buf
->ops
->event_write(ctx
, &v
, sizeof(v
));
157 case LTTNG_UST_DYNAMIC_TYPE_U16
:
161 lib_ring_buffer_align_ctx(ctx
, lttng_alignof(v
));
162 lttng_chan_buf
->ops
->event_write(ctx
, &v
, sizeof(v
));
165 case LTTNG_UST_DYNAMIC_TYPE_U32
:
169 lib_ring_buffer_align_ctx(ctx
, lttng_alignof(v
));
170 lttng_chan_buf
->ops
->event_write(ctx
, &v
, sizeof(v
));
173 case LTTNG_UST_DYNAMIC_TYPE_U64
:
177 lib_ring_buffer_align_ctx(ctx
, lttng_alignof(v
));
178 lttng_chan_buf
->ops
->event_write(ctx
, &v
, sizeof(v
));
181 case LTTNG_UST_DYNAMIC_TYPE_FLOAT
:
185 lib_ring_buffer_align_ctx(ctx
, lttng_alignof(f
));
186 lttng_chan_buf
->ops
->event_write(ctx
, &f
, sizeof(f
));
189 case LTTNG_UST_DYNAMIC_TYPE_DOUBLE
:
193 lib_ring_buffer_align_ctx(ctx
, lttng_alignof(d
));
194 lttng_chan_buf
->ops
->event_write(ctx
, &d
, sizeof(d
));
197 case LTTNG_UST_DYNAMIC_TYPE_STRING
:
199 const char *str
= "teststr";
200 lttng_chan_buf
->ops
->event_write(ctx
, str
, strlen(str
) + 1);
209 void test_get_value(struct lttng_ust_ctx_field
*field
,
210 struct lttng_ust_ctx_value
*value
)
212 int sel
= test_count
% _NR_LTTNG_UST_DYNAMIC_TYPES
;
216 case LTTNG_UST_DYNAMIC_TYPE_NONE
:
218 case LTTNG_UST_DYNAMIC_TYPE_S8
:
221 case LTTNG_UST_DYNAMIC_TYPE_S16
:
224 case LTTNG_UST_DYNAMIC_TYPE_S32
:
227 case LTTNG_UST_DYNAMIC_TYPE_S64
:
230 case LTTNG_UST_DYNAMIC_TYPE_U8
:
233 case LTTNG_UST_DYNAMIC_TYPE_U16
:
236 case LTTNG_UST_DYNAMIC_TYPE_U32
:
239 case LTTNG_UST_DYNAMIC_TYPE_U64
:
242 case LTTNG_UST_DYNAMIC_TYPE_FLOAT
:
243 value
->u
.d
= 22322.0;
245 case LTTNG_UST_DYNAMIC_TYPE_DOUBLE
:
248 case LTTNG_UST_DYNAMIC_TYPE_STRING
:
249 value
->u
.str
= "teststr";
256 struct lttng_ust_context_provider myprovider
= {
257 .struct_size
= sizeof(struct lttng_ust_context_provider
),
258 .name
= "$app.myprovider",
259 .get_size
= test_get_size
,
260 .record
= test_record
,
261 .get_value
= test_get_value
,
264 void inthandler(int sig
)
266 printf("in SIGUSR1 handler\n");
267 tracepoint(ust_tests_hello
, tptest_sighandler
);
270 int init_int_handler(void)
273 struct sigaction act
;
275 memset(&act
, 0, sizeof(act
));
276 result
= sigemptyset(&act
.sa_mask
);
278 perror("sigemptyset");
282 act
.sa_handler
= inthandler
;
283 act
.sa_flags
= SA_RESTART
;
285 /* Only defer ourselves. Also, try to restart interrupted
286 * syscalls to disturb the traced program as little as possible.
288 result
= sigaction(SIGUSR1
, &act
, NULL
);
297 void test_inc_count(void);
299 int main(int argc
, char **argv
)
302 long values
[] = { 1, 2, 3 };
303 char text
[10] = "test";
307 bool mybool
= 123; /* should print "1" */
312 delay
= atoi(argv
[1]);
314 if (lttng_ust_context_provider_register(&myprovider
))
317 fprintf(stderr
, "Hello, World!\n");
321 fprintf(stderr
, "Tracing... ");
322 for (i
= 0; i
< 1000000; i
++) {
324 tracepoint(ust_tests_hello
, tptest
, i
, netint
, values
,
325 text
, strlen(text
), dbl
, flt
, mybool
);
329 lttng_ust_context_provider_unregister(&myprovider
);
330 fprintf(stderr
, " done.\n");