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
+= lttng_ust_lib_ring_buffer_align(offset
, lttng_ust_rb_alignof(char));
50 size
+= sizeof(char); /* tag */
52 case LTTNG_UST_DYNAMIC_TYPE_NONE
:
54 case LTTNG_UST_DYNAMIC_TYPE_S8
:
55 size
+= lttng_ust_lib_ring_buffer_align(offset
, lttng_ust_rb_alignof(int8_t));
56 size
+= sizeof(int8_t); /* variant */
58 case LTTNG_UST_DYNAMIC_TYPE_S16
:
59 size
+= lttng_ust_lib_ring_buffer_align(offset
, lttng_ust_rb_alignof(int16_t));
60 size
+= sizeof(int16_t); /* variant */
62 case LTTNG_UST_DYNAMIC_TYPE_S32
:
63 size
+= lttng_ust_lib_ring_buffer_align(offset
, lttng_ust_rb_alignof(int32_t));
64 size
+= sizeof(int32_t); /* variant */
66 case LTTNG_UST_DYNAMIC_TYPE_S64
:
67 size
+= lttng_ust_lib_ring_buffer_align(offset
, lttng_ust_rb_alignof(int64_t));
68 size
+= sizeof(int64_t); /* variant */
70 case LTTNG_UST_DYNAMIC_TYPE_U8
:
71 size
+= lttng_ust_lib_ring_buffer_align(offset
, lttng_ust_rb_alignof(uint8_t));
72 size
+= sizeof(uint8_t); /* variant */
74 case LTTNG_UST_DYNAMIC_TYPE_U16
:
75 size
+= lttng_ust_lib_ring_buffer_align(offset
, lttng_ust_rb_alignof(uint16_t));
76 size
+= sizeof(uint16_t); /* variant */
78 case LTTNG_UST_DYNAMIC_TYPE_U32
:
79 size
+= lttng_ust_lib_ring_buffer_align(offset
, lttng_ust_rb_alignof(uint32_t));
80 size
+= sizeof(uint32_t); /* variant */
82 case LTTNG_UST_DYNAMIC_TYPE_U64
:
83 size
+= lttng_ust_lib_ring_buffer_align(offset
, lttng_ust_rb_alignof(uint64_t));
84 size
+= sizeof(uint64_t); /* variant */
86 case LTTNG_UST_DYNAMIC_TYPE_FLOAT
:
87 size
+= lttng_ust_lib_ring_buffer_align(offset
, lttng_ust_rb_alignof(float));
88 size
+= sizeof(float); /* variant */
90 case LTTNG_UST_DYNAMIC_TYPE_DOUBLE
:
91 size
+= lttng_ust_lib_ring_buffer_align(offset
, lttng_ust_rb_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 lttng_chan_buf
->ops
->event_write(ctx
, &sel_char
, sizeof(sel_char
), lttng_ust_rb_alignof(char));
114 case LTTNG_UST_DYNAMIC_TYPE_NONE
:
116 case LTTNG_UST_DYNAMIC_TYPE_S8
:
120 lttng_chan_buf
->ops
->event_write(ctx
, &v
, sizeof(v
), lttng_ust_rb_alignof(v
));
123 case LTTNG_UST_DYNAMIC_TYPE_S16
:
127 lttng_chan_buf
->ops
->event_write(ctx
, &v
, sizeof(v
), lttng_ust_rb_alignof(v
));
130 case LTTNG_UST_DYNAMIC_TYPE_S32
:
134 lttng_chan_buf
->ops
->event_write(ctx
, &v
, sizeof(v
), lttng_ust_rb_alignof(v
));
137 case LTTNG_UST_DYNAMIC_TYPE_S64
:
141 lttng_chan_buf
->ops
->event_write(ctx
, &v
, sizeof(v
), lttng_ust_rb_alignof(v
));
144 case LTTNG_UST_DYNAMIC_TYPE_U8
:
148 lttng_chan_buf
->ops
->event_write(ctx
, &v
, sizeof(v
), lttng_ust_rb_alignof(v
));
151 case LTTNG_UST_DYNAMIC_TYPE_U16
:
155 lttng_chan_buf
->ops
->event_write(ctx
, &v
, sizeof(v
), lttng_ust_rb_alignof(v
));
158 case LTTNG_UST_DYNAMIC_TYPE_U32
:
162 lttng_chan_buf
->ops
->event_write(ctx
, &v
, sizeof(v
), lttng_ust_rb_alignof(v
));
165 case LTTNG_UST_DYNAMIC_TYPE_U64
:
169 lttng_chan_buf
->ops
->event_write(ctx
, &v
, sizeof(v
), lttng_ust_rb_alignof(v
));
172 case LTTNG_UST_DYNAMIC_TYPE_FLOAT
:
176 lttng_chan_buf
->ops
->event_write(ctx
, &f
, sizeof(f
), lttng_ust_rb_alignof(f
));
179 case LTTNG_UST_DYNAMIC_TYPE_DOUBLE
:
183 lttng_chan_buf
->ops
->event_write(ctx
, &d
, sizeof(d
), lttng_ust_rb_alignof(d
));
186 case LTTNG_UST_DYNAMIC_TYPE_STRING
:
188 const char *str
= "teststr";
189 lttng_chan_buf
->ops
->event_write(ctx
, str
, strlen(str
) + 1, 1);
198 void test_get_value(struct lttng_ust_ctx_field
*field
,
199 struct lttng_ust_ctx_value
*value
)
201 int sel
= test_count
% _NR_LTTNG_UST_DYNAMIC_TYPES
;
205 case LTTNG_UST_DYNAMIC_TYPE_NONE
:
207 case LTTNG_UST_DYNAMIC_TYPE_S8
:
210 case LTTNG_UST_DYNAMIC_TYPE_S16
:
213 case LTTNG_UST_DYNAMIC_TYPE_S32
:
216 case LTTNG_UST_DYNAMIC_TYPE_S64
:
219 case LTTNG_UST_DYNAMIC_TYPE_U8
:
222 case LTTNG_UST_DYNAMIC_TYPE_U16
:
225 case LTTNG_UST_DYNAMIC_TYPE_U32
:
228 case LTTNG_UST_DYNAMIC_TYPE_U64
:
231 case LTTNG_UST_DYNAMIC_TYPE_FLOAT
:
232 value
->u
.d
= 22322.0;
234 case LTTNG_UST_DYNAMIC_TYPE_DOUBLE
:
237 case LTTNG_UST_DYNAMIC_TYPE_STRING
:
238 value
->u
.str
= "teststr";
245 struct lttng_ust_context_provider myprovider
= {
246 .struct_size
= sizeof(struct lttng_ust_context_provider
),
247 .name
= "$app.myprovider",
248 .get_size
= test_get_size
,
249 .record
= test_record
,
250 .get_value
= test_get_value
,
253 void inthandler(int sig
)
255 printf("in SIGUSR1 handler\n");
256 tracepoint(ust_tests_hello
, tptest_sighandler
);
259 int init_int_handler(void)
262 struct sigaction act
;
264 memset(&act
, 0, sizeof(act
));
265 result
= sigemptyset(&act
.sa_mask
);
267 perror("sigemptyset");
271 act
.sa_handler
= inthandler
;
272 act
.sa_flags
= SA_RESTART
;
274 /* Only defer ourselves. Also, try to restart interrupted
275 * syscalls to disturb the traced program as little as possible.
277 result
= sigaction(SIGUSR1
, &act
, NULL
);
286 void test_inc_count(void);
288 int main(int argc
, char **argv
)
291 long values
[] = { 1, 2, 3 };
292 char text
[10] = "test";
296 bool mybool
= 123; /* should print "1" */
301 delay
= atoi(argv
[1]);
303 if (lttng_ust_context_provider_register(&myprovider
))
306 fprintf(stderr
, "Hello, World!\n");
310 fprintf(stderr
, "Tracing... ");
311 for (i
= 0; i
< 1000000; i
++) {
313 tracepoint(ust_tests_hello
, tptest
, i
, netint
, values
,
314 text
, strlen(text
), dbl
, flt
, mybool
);
318 lttng_ust_context_provider_unregister(&myprovider
);
319 fprintf(stderr
, " done.\n");