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
28 #include <sys/types.h>
31 * Work-around inet.h missing struct mmsghdr forward declaration, with
32 * triggers a warning when system files warnings are enabled.
35 #include <arpa/inet.h>
40 #define TRACEPOINT_DEFINE
41 #include "ust_tests_hello.h"
43 /* Internal header. */
44 #include <lttng/ust-events.h>
45 #include <lttng/ringbuffer-config.h>
46 #include <lttng/ust-context-provider.h>
48 static __thread
unsigned int test_count
;
50 void test_inc_count(void)
56 size_t test_get_size(struct lttng_ctx_field
*field
, size_t offset
)
58 int sel
= test_count
% _NR_LTTNG_UST_DYNAMIC_TYPES
;
61 size
+= lib_ring_buffer_align(offset
, lttng_alignof(char));
62 size
+= sizeof(char); /* tag */
64 case LTTNG_UST_DYNAMIC_TYPE_NONE
:
66 case LTTNG_UST_DYNAMIC_TYPE_S8
:
67 size
+= lib_ring_buffer_align(offset
, lttng_alignof(int8_t));
68 size
+= sizeof(int8_t); /* variant */
70 case LTTNG_UST_DYNAMIC_TYPE_S16
:
71 size
+= lib_ring_buffer_align(offset
, lttng_alignof(int16_t));
72 size
+= sizeof(int16_t); /* variant */
74 case LTTNG_UST_DYNAMIC_TYPE_S32
:
75 size
+= lib_ring_buffer_align(offset
, lttng_alignof(int32_t));
76 size
+= sizeof(int32_t); /* variant */
78 case LTTNG_UST_DYNAMIC_TYPE_S64
:
79 size
+= lib_ring_buffer_align(offset
, lttng_alignof(int64_t));
80 size
+= sizeof(int64_t); /* variant */
82 case LTTNG_UST_DYNAMIC_TYPE_U8
:
83 size
+= lib_ring_buffer_align(offset
, lttng_alignof(uint8_t));
84 size
+= sizeof(uint8_t); /* variant */
86 case LTTNG_UST_DYNAMIC_TYPE_U16
:
87 size
+= lib_ring_buffer_align(offset
, lttng_alignof(uint16_t));
88 size
+= sizeof(uint16_t); /* variant */
90 case LTTNG_UST_DYNAMIC_TYPE_U32
:
91 size
+= lib_ring_buffer_align(offset
, lttng_alignof(uint32_t));
92 size
+= sizeof(uint32_t); /* variant */
94 case LTTNG_UST_DYNAMIC_TYPE_U64
:
95 size
+= lib_ring_buffer_align(offset
, lttng_alignof(uint64_t));
96 size
+= sizeof(uint64_t); /* variant */
98 case LTTNG_UST_DYNAMIC_TYPE_FLOAT
:
99 size
+= lib_ring_buffer_align(offset
, lttng_alignof(float));
100 size
+= sizeof(float); /* variant */
102 case LTTNG_UST_DYNAMIC_TYPE_DOUBLE
:
103 size
+= lib_ring_buffer_align(offset
, lttng_alignof(double));
104 size
+= sizeof(double); /* variant */
106 case LTTNG_UST_DYNAMIC_TYPE_STRING
:
107 size
+= strlen("teststr") + 1;
117 void test_record(struct lttng_ctx_field
*field
,
118 struct lttng_ust_lib_ring_buffer_ctx
*ctx
,
119 struct lttng_channel
*chan
)
121 int sel
= test_count
% _NR_LTTNG_UST_DYNAMIC_TYPES
;
122 char sel_char
= (char) sel
;
124 lib_ring_buffer_align_ctx(ctx
, lttng_alignof(char));
125 chan
->ops
->event_write(ctx
, &sel_char
, sizeof(sel_char
));
127 case LTTNG_UST_DYNAMIC_TYPE_NONE
:
129 case LTTNG_UST_DYNAMIC_TYPE_S8
:
133 lib_ring_buffer_align_ctx(ctx
, lttng_alignof(v
));
134 chan
->ops
->event_write(ctx
, &v
, sizeof(v
));
137 case LTTNG_UST_DYNAMIC_TYPE_S16
:
141 lib_ring_buffer_align_ctx(ctx
, lttng_alignof(v
));
142 chan
->ops
->event_write(ctx
, &v
, sizeof(v
));
145 case LTTNG_UST_DYNAMIC_TYPE_S32
:
149 lib_ring_buffer_align_ctx(ctx
, lttng_alignof(v
));
150 chan
->ops
->event_write(ctx
, &v
, sizeof(v
));
153 case LTTNG_UST_DYNAMIC_TYPE_S64
:
157 lib_ring_buffer_align_ctx(ctx
, lttng_alignof(v
));
158 chan
->ops
->event_write(ctx
, &v
, sizeof(v
));
161 case LTTNG_UST_DYNAMIC_TYPE_U8
:
165 lib_ring_buffer_align_ctx(ctx
, lttng_alignof(v
));
166 chan
->ops
->event_write(ctx
, &v
, sizeof(v
));
169 case LTTNG_UST_DYNAMIC_TYPE_U16
:
173 lib_ring_buffer_align_ctx(ctx
, lttng_alignof(v
));
174 chan
->ops
->event_write(ctx
, &v
, sizeof(v
));
177 case LTTNG_UST_DYNAMIC_TYPE_U32
:
181 lib_ring_buffer_align_ctx(ctx
, lttng_alignof(v
));
182 chan
->ops
->event_write(ctx
, &v
, sizeof(v
));
185 case LTTNG_UST_DYNAMIC_TYPE_U64
:
189 lib_ring_buffer_align_ctx(ctx
, lttng_alignof(v
));
190 chan
->ops
->event_write(ctx
, &v
, sizeof(v
));
193 case LTTNG_UST_DYNAMIC_TYPE_FLOAT
:
197 lib_ring_buffer_align_ctx(ctx
, lttng_alignof(f
));
198 chan
->ops
->event_write(ctx
, &f
, sizeof(f
));
201 case LTTNG_UST_DYNAMIC_TYPE_DOUBLE
:
205 lib_ring_buffer_align_ctx(ctx
, lttng_alignof(d
));
206 chan
->ops
->event_write(ctx
, &d
, sizeof(d
));
209 case LTTNG_UST_DYNAMIC_TYPE_STRING
:
211 const char *str
= "teststr";
212 chan
->ops
->event_write(ctx
, str
, strlen(str
) + 1);
221 void test_get_value(struct lttng_ctx_field
*field
,
222 struct lttng_ctx_value
*value
)
224 int sel
= test_count
% _NR_LTTNG_UST_DYNAMIC_TYPES
;
228 case LTTNG_UST_DYNAMIC_TYPE_NONE
:
230 case LTTNG_UST_DYNAMIC_TYPE_S8
:
233 case LTTNG_UST_DYNAMIC_TYPE_S16
:
236 case LTTNG_UST_DYNAMIC_TYPE_S32
:
239 case LTTNG_UST_DYNAMIC_TYPE_S64
:
242 case LTTNG_UST_DYNAMIC_TYPE_U8
:
245 case LTTNG_UST_DYNAMIC_TYPE_U16
:
248 case LTTNG_UST_DYNAMIC_TYPE_U32
:
251 case LTTNG_UST_DYNAMIC_TYPE_U64
:
254 case LTTNG_UST_DYNAMIC_TYPE_FLOAT
:
255 value
->u
.d
= 22322.0;
257 case LTTNG_UST_DYNAMIC_TYPE_DOUBLE
:
260 case LTTNG_UST_DYNAMIC_TYPE_STRING
:
261 value
->u
.str
= "teststr";
268 struct lttng_ust_context_provider myprovider
= {
269 .name
= "$app.myprovider",
270 .get_size
= test_get_size
,
271 .record
= test_record
,
272 .get_value
= test_get_value
,
275 void inthandler(int sig
)
277 printf("in SIGUSR1 handler\n");
278 tracepoint(ust_tests_hello
, tptest_sighandler
);
281 int init_int_handler(void)
284 struct sigaction act
;
286 memset(&act
, 0, sizeof(act
));
287 result
= sigemptyset(&act
.sa_mask
);
289 perror("sigemptyset");
293 act
.sa_handler
= inthandler
;
294 act
.sa_flags
= SA_RESTART
;
296 /* Only defer ourselves. Also, try to restart interrupted
297 * syscalls to disturb the traced program as little as possible.
299 result
= sigaction(SIGUSR1
, &act
, NULL
);
308 void test_inc_count(void);
310 int main(int argc
, char **argv
)
313 long values
[] = { 1, 2, 3 };
314 char text
[10] = "test";
318 bool mybool
= 123; /* should print "1" */
323 delay
= atoi(argv
[1]);
325 if (lttng_ust_context_provider_register(&myprovider
))
328 fprintf(stderr
, "Hello, World!\n");
332 fprintf(stderr
, "Tracing... ");
333 for (i
= 0; i
< 1000000; i
++) {
335 tracepoint(ust_tests_hello
, tptest
, i
, netint
, values
,
336 text
, strlen(text
), dbl
, flt
, mybool
);
340 lttng_ust_context_provider_unregister(&myprovider
);
341 fprintf(stderr
, " done.\n");