Fix: remove unused event types in MI XML schema
[lttng-tools.git] / tests / utils / testapp / gen-ust-events / gen-ust-events.c
... / ...
CommitLineData
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
40void create_file(const char *path)
41{
42 static bool file_created = false;
43 int ret;
44
45 if (!path || file_created) {
46 return;
47 }
48
49 ret = creat(path, S_IRWXU);
50 if (ret < 0) {
51 fprintf(stderr, "Failed to create file %s\n", path);
52 return;
53 }
54
55 (void) close(ret);
56 file_created = true;
57}
58
59static
60void wait_on_file(const char *path)
61{
62 if (!path) {
63 return;
64 }
65 for (;;) {
66 int ret;
67 struct stat buf;
68
69 ret = stat(path, &buf);
70 if (ret == -1 && errno == ENOENT) {
71 (void) poll(NULL, 0, 10); /* 10 ms delay */
72 continue; /* retry */
73 }
74 if (ret) {
75 perror("stat");
76 exit(EXIT_FAILURE);
77 }
78 break; /* found */
79 }
80}
81
82int main(int argc, char **argv)
83{
84 unsigned int i, netint;
85 long values[] = { 1, 2, 3 };
86 char text[10] = "test";
87 double dbl = 2.0;
88 float flt = 2222.0;
89 int nr_iter = 100, ret = 0;
90 useconds_t nr_usec = 0;
91 char *after_first_event_file_path = NULL;
92 char *before_last_event_file_path = NULL;
93
94 if (set_signal_handler()) {
95 ret = -1;
96 goto end;
97 }
98
99 if (argc >= 2) {
100 /*
101 * If nr_iter is negative, do an infinite tracing loop.
102 */
103 nr_iter = atoi(argv[1]);
104 }
105
106 if (argc >= 3) {
107 /* By default, don't wait unless user specifies. */
108 nr_usec = atoi(argv[2]);
109 }
110
111 if (argc >= 4) {
112 after_first_event_file_path = argv[3];
113 }
114
115 if (argc >= 5) {
116 before_last_event_file_path = argv[4];
117 }
118
119 for (i = 0; nr_iter < 0 || i < nr_iter; i++) {
120 if (nr_iter >= 0 && i == nr_iter - 1) {
121 /*
122 * Wait on synchronization before writing last
123 * event.
124 */
125 wait_on_file(before_last_event_file_path);
126 }
127 netint = htonl(i);
128 tracepoint(tp, tptest, i, netint, values, text,
129 strlen(text), dbl, flt);
130
131 /*
132 * First loop we create the file if asked to indicate
133 * that at least one tracepoint has been hit.
134 */
135 create_file(after_first_event_file_path);
136 if (nr_usec) {
137 if (usleep_safe(nr_usec)) {
138 ret = -1;
139 goto end;
140 }
141 }
142 if (should_quit) {
143 break;
144 }
145 }
146
147end:
148 exit(!ret ? EXIT_SUCCESS : EXIT_FAILURE);
149}
This page took 0.023972 seconds and 5 git commands to generate.