1ce34423b330ab14cccf50597b2fa1d0e469148c
[lttng-tools.git] / tests / utils / testapp / gen-ust-events / gen-ust-events.c
1 /*
2 * Copyright (C) - 2012 David Goulet <dgoulet@efficios.com>
3 *
4 * This library is free software; you can redistribute it and/or modify it
5 * under the terms of the GNU Lesser General Public License as published by the
6 * Free Software Foundation; version 2.1 of the License.
7 *
8 * This library is distributed in the hope that it will be useful, but WITHOUT
9 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
10 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
11 * for more details.
12 *
13 * You should have received a copy of the GNU Lesser General Public License
14 * along with this library; if not, write to the Free Software Foundation,
15 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
16 */
17
18 #define _LGPL_SOURCE
19 #include <assert.h>
20 #include <arpa/inet.h>
21 #include <fcntl.h>
22 #include <stdarg.h>
23 #include <stdio.h>
24 #include <stdlib.h>
25 #include <string.h>
26 #include <sys/mman.h>
27 #include <sys/stat.h>
28 #include <sys/types.h>
29 #include <unistd.h>
30 #include <stdbool.h>
31 #include <signal.h>
32 #include <poll.h>
33 #include <errno.h>
34 #include "utils.h"
35 #include "signal-helper.h"
36
37 #define TRACEPOINT_DEFINE
38 #include "tp.h"
39
40 int main(int argc, char **argv)
41 {
42 unsigned int i, netint;
43 long values[] = { 1, 2, 3 };
44 char text[10] = "test";
45 double dbl = 2.0;
46 float flt = 2222.0;
47 int nr_iter = 100, ret = 0, first_event_file_created = 0;
48 useconds_t nr_usec = 0;
49 char *after_first_event_file_path = NULL;
50 char *before_last_event_file_path = NULL;
51
52 if (set_signal_handler()) {
53 ret = -1;
54 goto end;
55 }
56
57 if (argc >= 2) {
58 /*
59 * If nr_iter is negative, do an infinite tracing loop.
60 */
61 nr_iter = atoi(argv[1]);
62 }
63
64 if (argc >= 3) {
65 /* By default, don't wait unless user specifies. */
66 nr_usec = atoi(argv[2]);
67 }
68
69 if (argc >= 4) {
70 after_first_event_file_path = argv[3];
71 }
72
73 if (argc >= 5) {
74 before_last_event_file_path = argv[4];
75 }
76
77 for (i = 0; nr_iter < 0 || i < nr_iter; i++) {
78 if (nr_iter >= 0 && i == nr_iter - 1) {
79 /*
80 * Wait on synchronization before writing last
81 * event.
82 */
83 if (before_last_event_file_path) {
84 ret = wait_on_file(before_last_event_file_path);
85 if (ret != 0) {
86 goto end;
87 }
88 }
89 }
90 netint = htonl(i);
91 tracepoint(tp, tptest, i, netint, values, text,
92 strlen(text), dbl, flt);
93
94 /*
95 * First loop we create the file if asked to indicate
96 * that at least one tracepoint has been hit.
97 */
98 if (after_first_event_file_path && first_event_file_created == 0) {
99 ret = create_file(after_first_event_file_path);
100
101 if (ret != 0) {
102 goto end;
103 } else {
104 first_event_file_created = 1;
105 }
106 }
107
108 if (nr_usec) {
109 if (usleep_safe(nr_usec)) {
110 ret = -1;
111 goto end;
112 }
113 }
114 if (should_quit) {
115 break;
116 }
117 }
118
119 end:
120 exit(!ret ? EXIT_SUCCESS : EXIT_FAILURE);
121 }
This page took 0.045909 seconds and 4 git commands to generate.