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 LTTNG_UST_TRACEPOINT_DEFINE
29 #include "ust_tests_hello.h"
31 #include <lttng/ust-events.h>
32 #include <lttng/ust-ringbuffer-context.h>
33 /* Internal header. */
34 #include <common/ust-context-provider.h>
36 static __thread
unsigned int test_count
;
39 void test_inc_count(void)
45 size_t test_get_size(void *priv
__attribute__((unused
)),
46 struct lttng_ust_probe_ctx
*probe_ctx
__attribute__((unused
)),
49 int sel
= test_count
% _NR_LTTNG_UST_DYNAMIC_TYPES
;
52 size
+= lttng_ust_ring_buffer_align(offset
, lttng_ust_rb_alignof(char));
53 size
+= sizeof(char); /* tag */
55 case LTTNG_UST_DYNAMIC_TYPE_NONE
:
57 case LTTNG_UST_DYNAMIC_TYPE_S8
:
58 size
+= lttng_ust_ring_buffer_align(offset
, lttng_ust_rb_alignof(int8_t));
59 size
+= sizeof(int8_t); /* variant */
61 case LTTNG_UST_DYNAMIC_TYPE_S16
:
62 size
+= lttng_ust_ring_buffer_align(offset
, lttng_ust_rb_alignof(int16_t));
63 size
+= sizeof(int16_t); /* variant */
65 case LTTNG_UST_DYNAMIC_TYPE_S32
:
66 size
+= lttng_ust_ring_buffer_align(offset
, lttng_ust_rb_alignof(int32_t));
67 size
+= sizeof(int32_t); /* variant */
69 case LTTNG_UST_DYNAMIC_TYPE_S64
:
70 size
+= lttng_ust_ring_buffer_align(offset
, lttng_ust_rb_alignof(int64_t));
71 size
+= sizeof(int64_t); /* variant */
73 case LTTNG_UST_DYNAMIC_TYPE_U8
:
74 size
+= lttng_ust_ring_buffer_align(offset
, lttng_ust_rb_alignof(uint8_t));
75 size
+= sizeof(uint8_t); /* variant */
77 case LTTNG_UST_DYNAMIC_TYPE_U16
:
78 size
+= lttng_ust_ring_buffer_align(offset
, lttng_ust_rb_alignof(uint16_t));
79 size
+= sizeof(uint16_t); /* variant */
81 case LTTNG_UST_DYNAMIC_TYPE_U32
:
82 size
+= lttng_ust_ring_buffer_align(offset
, lttng_ust_rb_alignof(uint32_t));
83 size
+= sizeof(uint32_t); /* variant */
85 case LTTNG_UST_DYNAMIC_TYPE_U64
:
86 size
+= lttng_ust_ring_buffer_align(offset
, lttng_ust_rb_alignof(uint64_t));
87 size
+= sizeof(uint64_t); /* variant */
89 case LTTNG_UST_DYNAMIC_TYPE_FLOAT
:
90 size
+= lttng_ust_ring_buffer_align(offset
, lttng_ust_rb_alignof(float));
91 size
+= sizeof(float); /* variant */
93 case LTTNG_UST_DYNAMIC_TYPE_DOUBLE
:
94 size
+= lttng_ust_ring_buffer_align(offset
, lttng_ust_rb_alignof(double));
95 size
+= sizeof(double); /* variant */
97 case LTTNG_UST_DYNAMIC_TYPE_STRING
:
98 size
+= strlen("teststr") + 1;
108 void test_record(void *priv
__attribute__((unused
)),
109 struct lttng_ust_probe_ctx
*probe_ctx
__attribute__((unused
)),
110 struct lttng_ust_ring_buffer_ctx
*ctx
,
111 struct lttng_ust_channel_buffer
*lttng_chan_buf
)
113 int sel
= test_count
% _NR_LTTNG_UST_DYNAMIC_TYPES
;
114 char sel_char
= (char) sel
;
116 lttng_chan_buf
->ops
->event_write(ctx
, &sel_char
, sizeof(sel_char
), lttng_ust_rb_alignof(char));
118 case LTTNG_UST_DYNAMIC_TYPE_NONE
:
120 case LTTNG_UST_DYNAMIC_TYPE_S8
:
124 lttng_chan_buf
->ops
->event_write(ctx
, &v
, sizeof(v
), lttng_ust_rb_alignof(v
));
127 case LTTNG_UST_DYNAMIC_TYPE_S16
:
131 lttng_chan_buf
->ops
->event_write(ctx
, &v
, sizeof(v
), lttng_ust_rb_alignof(v
));
134 case LTTNG_UST_DYNAMIC_TYPE_S32
:
138 lttng_chan_buf
->ops
->event_write(ctx
, &v
, sizeof(v
), lttng_ust_rb_alignof(v
));
141 case LTTNG_UST_DYNAMIC_TYPE_S64
:
145 lttng_chan_buf
->ops
->event_write(ctx
, &v
, sizeof(v
), lttng_ust_rb_alignof(v
));
148 case LTTNG_UST_DYNAMIC_TYPE_U8
:
152 lttng_chan_buf
->ops
->event_write(ctx
, &v
, sizeof(v
), lttng_ust_rb_alignof(v
));
155 case LTTNG_UST_DYNAMIC_TYPE_U16
:
159 lttng_chan_buf
->ops
->event_write(ctx
, &v
, sizeof(v
), lttng_ust_rb_alignof(v
));
162 case LTTNG_UST_DYNAMIC_TYPE_U32
:
166 lttng_chan_buf
->ops
->event_write(ctx
, &v
, sizeof(v
), lttng_ust_rb_alignof(v
));
169 case LTTNG_UST_DYNAMIC_TYPE_U64
:
173 lttng_chan_buf
->ops
->event_write(ctx
, &v
, sizeof(v
), lttng_ust_rb_alignof(v
));
176 case LTTNG_UST_DYNAMIC_TYPE_FLOAT
:
180 lttng_chan_buf
->ops
->event_write(ctx
, &f
, sizeof(f
), lttng_ust_rb_alignof(f
));
183 case LTTNG_UST_DYNAMIC_TYPE_DOUBLE
:
187 lttng_chan_buf
->ops
->event_write(ctx
, &d
, sizeof(d
), lttng_ust_rb_alignof(d
));
190 case LTTNG_UST_DYNAMIC_TYPE_STRING
:
192 const char *str
= "teststr";
193 lttng_chan_buf
->ops
->event_write(ctx
, str
, strlen(str
) + 1, 1);
202 void test_get_value(void *priv
__attribute__((unused
)),
203 struct lttng_ust_probe_ctx
*probe_ctx
__attribute__((unused
)),
204 struct lttng_ust_ctx_value
*value
)
206 int sel
= test_count
% _NR_LTTNG_UST_DYNAMIC_TYPES
;
210 case LTTNG_UST_DYNAMIC_TYPE_NONE
:
212 case LTTNG_UST_DYNAMIC_TYPE_S8
:
215 case LTTNG_UST_DYNAMIC_TYPE_S16
:
218 case LTTNG_UST_DYNAMIC_TYPE_S32
:
221 case LTTNG_UST_DYNAMIC_TYPE_S64
:
224 case LTTNG_UST_DYNAMIC_TYPE_U8
:
227 case LTTNG_UST_DYNAMIC_TYPE_U16
:
230 case LTTNG_UST_DYNAMIC_TYPE_U32
:
233 case LTTNG_UST_DYNAMIC_TYPE_U64
:
236 case LTTNG_UST_DYNAMIC_TYPE_FLOAT
:
237 value
->u
.d
= 22322.0;
239 case LTTNG_UST_DYNAMIC_TYPE_DOUBLE
:
242 case LTTNG_UST_DYNAMIC_TYPE_STRING
:
243 value
->u
.str
= "teststr";
250 static char myprovider_name
[] = "$app.myprovider";
251 struct lttng_ust_context_provider myprovider
= {
252 .struct_size
= sizeof(struct lttng_ust_context_provider
),
253 .name
= myprovider_name
,
254 .get_size
= test_get_size
,
255 .record
= test_record
,
256 .get_value
= test_get_value
,
260 void inthandler(int sig
__attribute__((unused
)))
262 printf("in SIGUSR1 handler\n");
263 lttng_ust_tracepoint(ust_tests_hello
, tptest_sighandler
);
267 int init_int_handler(void)
270 struct sigaction act
;
272 memset(&act
, 0, sizeof(act
));
273 result
= sigemptyset(&act
.sa_mask
);
275 perror("sigemptyset");
279 act
.sa_handler
= inthandler
;
280 act
.sa_flags
= SA_RESTART
;
282 /* Only defer ourselves. Also, try to restart interrupted
283 * syscalls to disturb the traced program as little as possible.
285 result
= sigaction(SIGUSR1
, &act
, NULL
);
294 int main(int argc
, char **argv
)
296 struct lttng_ust_registered_context_provider
*reg_provider
;
298 long values
[] = { 1, 2, 3 };
299 char text
[10] = "test";
303 bool mybool
= 123; /* should print "1" */
308 delay
= atoi(argv
[1]);
310 reg_provider
= lttng_ust_context_provider_register(&myprovider
);
314 fprintf(stderr
, "Hello, World!\n");
318 fprintf(stderr
, "Tracing... ");
319 for (i
= 0; i
< 1000000; i
++) {
321 lttng_ust_tracepoint(ust_tests_hello
, tptest
, i
, netint
, values
,
322 text
, strlen(text
), dbl
, flt
, mybool
);
326 lttng_ust_context_provider_unregister(reg_provider
);
327 fprintf(stderr
, " done.\n");