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
24 #include <sys/types.h>
30 * Work-around inet.h missing struct mmsghdr forward declaration, with
31 * triggers a warning when system files warnings are enabled.
34 #include <arpa/inet.h>
39 #define TRACEPOINT_DEFINE
40 #include "ust_tests_hello.h"
42 /* Internal header. */
43 #include <lttng/ust-events.h>
44 #include <lttng/ringbuffer-config.h>
45 #include <lttng/ust-context-provider.h>
47 static __thread
unsigned int test_count
;
49 void test_inc_count(void)
55 size_t test_get_size(struct lttng_ctx_field
*field
, size_t offset
)
57 int sel
= test_count
% _NR_LTTNG_UST_DYNAMIC_TYPES
;
60 size
+= lib_ring_buffer_align(offset
, lttng_alignof(char));
61 size
+= sizeof(char); /* tag */
63 case LTTNG_UST_DYNAMIC_TYPE_NONE
:
65 case LTTNG_UST_DYNAMIC_TYPE_S8
:
66 size
+= lib_ring_buffer_align(offset
, lttng_alignof(int8_t));
67 size
+= sizeof(int8_t); /* variant */
69 case LTTNG_UST_DYNAMIC_TYPE_S16
:
70 size
+= lib_ring_buffer_align(offset
, lttng_alignof(int16_t));
71 size
+= sizeof(int16_t); /* variant */
73 case LTTNG_UST_DYNAMIC_TYPE_S32
:
74 size
+= lib_ring_buffer_align(offset
, lttng_alignof(int32_t));
75 size
+= sizeof(int32_t); /* variant */
77 case LTTNG_UST_DYNAMIC_TYPE_S64
:
78 size
+= lib_ring_buffer_align(offset
, lttng_alignof(int64_t));
79 size
+= sizeof(int64_t); /* variant */
81 case LTTNG_UST_DYNAMIC_TYPE_U8
:
82 size
+= lib_ring_buffer_align(offset
, lttng_alignof(uint8_t));
83 size
+= sizeof(uint8_t); /* variant */
85 case LTTNG_UST_DYNAMIC_TYPE_U16
:
86 size
+= lib_ring_buffer_align(offset
, lttng_alignof(uint16_t));
87 size
+= sizeof(uint16_t); /* variant */
89 case LTTNG_UST_DYNAMIC_TYPE_U32
:
90 size
+= lib_ring_buffer_align(offset
, lttng_alignof(uint32_t));
91 size
+= sizeof(uint32_t); /* variant */
93 case LTTNG_UST_DYNAMIC_TYPE_U64
:
94 size
+= lib_ring_buffer_align(offset
, lttng_alignof(uint64_t));
95 size
+= sizeof(uint64_t); /* variant */
97 case LTTNG_UST_DYNAMIC_TYPE_FLOAT
:
98 size
+= lib_ring_buffer_align(offset
, lttng_alignof(float));
99 size
+= sizeof(float); /* variant */
101 case LTTNG_UST_DYNAMIC_TYPE_DOUBLE
:
102 size
+= lib_ring_buffer_align(offset
, lttng_alignof(double));
103 size
+= sizeof(double); /* variant */
105 case LTTNG_UST_DYNAMIC_TYPE_STRING
:
106 size
+= strlen("teststr") + 1;
116 void test_record(struct lttng_ctx_field
*field
,
117 struct lttng_ust_lib_ring_buffer_ctx
*ctx
,
118 struct lttng_channel
*chan
)
120 int sel
= test_count
% _NR_LTTNG_UST_DYNAMIC_TYPES
;
121 char sel_char
= (char) sel
;
123 lib_ring_buffer_align_ctx(ctx
, lttng_alignof(char));
124 chan
->ops
->event_write(ctx
, &sel_char
, sizeof(sel_char
));
126 case LTTNG_UST_DYNAMIC_TYPE_NONE
:
128 case LTTNG_UST_DYNAMIC_TYPE_S8
:
132 lib_ring_buffer_align_ctx(ctx
, lttng_alignof(v
));
133 chan
->ops
->event_write(ctx
, &v
, sizeof(v
));
136 case LTTNG_UST_DYNAMIC_TYPE_S16
:
140 lib_ring_buffer_align_ctx(ctx
, lttng_alignof(v
));
141 chan
->ops
->event_write(ctx
, &v
, sizeof(v
));
144 case LTTNG_UST_DYNAMIC_TYPE_S32
:
148 lib_ring_buffer_align_ctx(ctx
, lttng_alignof(v
));
149 chan
->ops
->event_write(ctx
, &v
, sizeof(v
));
152 case LTTNG_UST_DYNAMIC_TYPE_S64
:
156 lib_ring_buffer_align_ctx(ctx
, lttng_alignof(v
));
157 chan
->ops
->event_write(ctx
, &v
, sizeof(v
));
160 case LTTNG_UST_DYNAMIC_TYPE_U8
:
164 lib_ring_buffer_align_ctx(ctx
, lttng_alignof(v
));
165 chan
->ops
->event_write(ctx
, &v
, sizeof(v
));
168 case LTTNG_UST_DYNAMIC_TYPE_U16
:
172 lib_ring_buffer_align_ctx(ctx
, lttng_alignof(v
));
173 chan
->ops
->event_write(ctx
, &v
, sizeof(v
));
176 case LTTNG_UST_DYNAMIC_TYPE_U32
:
180 lib_ring_buffer_align_ctx(ctx
, lttng_alignof(v
));
181 chan
->ops
->event_write(ctx
, &v
, sizeof(v
));
184 case LTTNG_UST_DYNAMIC_TYPE_U64
:
188 lib_ring_buffer_align_ctx(ctx
, lttng_alignof(v
));
189 chan
->ops
->event_write(ctx
, &v
, sizeof(v
));
192 case LTTNG_UST_DYNAMIC_TYPE_FLOAT
:
196 lib_ring_buffer_align_ctx(ctx
, lttng_alignof(f
));
197 chan
->ops
->event_write(ctx
, &f
, sizeof(f
));
200 case LTTNG_UST_DYNAMIC_TYPE_DOUBLE
:
204 lib_ring_buffer_align_ctx(ctx
, lttng_alignof(d
));
205 chan
->ops
->event_write(ctx
, &d
, sizeof(d
));
208 case LTTNG_UST_DYNAMIC_TYPE_STRING
:
210 const char *str
= "teststr";
211 chan
->ops
->event_write(ctx
, str
, strlen(str
) + 1);
220 void test_get_value(struct lttng_ctx_field
*field
,
221 struct lttng_ctx_value
*value
)
223 int sel
= test_count
% _NR_LTTNG_UST_DYNAMIC_TYPES
;
227 case LTTNG_UST_DYNAMIC_TYPE_NONE
:
229 case LTTNG_UST_DYNAMIC_TYPE_S8
:
232 case LTTNG_UST_DYNAMIC_TYPE_S16
:
235 case LTTNG_UST_DYNAMIC_TYPE_S32
:
238 case LTTNG_UST_DYNAMIC_TYPE_S64
:
241 case LTTNG_UST_DYNAMIC_TYPE_U8
:
244 case LTTNG_UST_DYNAMIC_TYPE_U16
:
247 case LTTNG_UST_DYNAMIC_TYPE_U32
:
250 case LTTNG_UST_DYNAMIC_TYPE_U64
:
253 case LTTNG_UST_DYNAMIC_TYPE_FLOAT
:
254 value
->u
.d
= 22322.0;
256 case LTTNG_UST_DYNAMIC_TYPE_DOUBLE
:
259 case LTTNG_UST_DYNAMIC_TYPE_STRING
:
260 value
->u
.str
= "teststr";
267 struct lttng_ust_context_provider myprovider
= {
268 .name
= "$app.myprovider",
269 .get_size
= test_get_size
,
270 .record
= test_record
,
271 .get_value
= test_get_value
,
274 void inthandler(int sig
)
276 printf("in SIGUSR1 handler\n");
277 tracepoint(ust_tests_hello
, tptest_sighandler
);
280 int init_int_handler(void)
283 struct sigaction act
;
285 memset(&act
, 0, sizeof(act
));
286 result
= sigemptyset(&act
.sa_mask
);
288 perror("sigemptyset");
292 act
.sa_handler
= inthandler
;
293 act
.sa_flags
= SA_RESTART
;
295 /* Only defer ourselves. Also, try to restart interrupted
296 * syscalls to disturb the traced program as little as possible.
298 result
= sigaction(SIGUSR1
, &act
, NULL
);
307 void test_inc_count(void);
309 int main(int argc
, char **argv
)
312 long values
[] = { 1, 2, 3 };
313 char text
[10] = "test";
317 bool mybool
= 123; /* should print "1" */
322 delay
= atoi(argv
[1]);
324 if (lttng_ust_context_provider_register(&myprovider
))
327 fprintf(stderr
, "Hello, World!\n");
331 fprintf(stderr
, "Tracing... ");
332 for (i
= 0; i
< 1000000; i
++) {
334 tracepoint(ust_tests_hello
, tptest
, i
, netint
, values
,
335 text
, strlen(text
), dbl
, flt
, mybool
);
339 lttng_ust_context_provider_unregister(&myprovider
);
340 fprintf(stderr
, " done.\n");