Implement tracef test application "gen-ust-tracef"
[lttng-tools.git] / tests / utils / testapp / gen-ust-tracef / gen-ust-tracef.c
1 /*
2 * Copyright (C) - 2012 David Goulet <dgoulet@efficios.com>
3 * Copyright (C) - 2014 Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
4 *
5 * This library is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU Lesser General Public License as published by the
7 * Free Software Foundation; version 2.1 of the License.
8 *
9 * This library is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
12 * for more details.
13 *
14 * You should have received a copy of the GNU Lesser General Public License
15 * along with this library; if not, write to the Free Software Foundation,
16 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17 */
18
19 #include <assert.h>
20 #include <fcntl.h>
21 #include <stdarg.h>
22 #include <stdio.h>
23 #include <stdlib.h>
24 #include <string.h>
25 #include <sys/mman.h>
26 #include <sys/stat.h>
27 #include <sys/types.h>
28 #include <unistd.h>
29
30 #include <lttng/tracef.h>
31
32 const char *str = "test string";
33
34 void create_file(const char *path)
35 {
36 int ret;
37
38 assert(path);
39
40 ret = creat(path, S_IRWXU);
41 if (ret < 0) {
42 fprintf(stderr, "Failed to create file %s\n", path);
43 return;
44 }
45
46 (void) close(ret);
47 }
48
49 int main(int argc, char **argv)
50 {
51 int i;
52 unsigned int nr_iter = 100;
53 useconds_t nr_usec = 0;
54 char *tmp_file_path = NULL;
55
56 if (argc >= 2) {
57 nr_iter = atoi(argv[1]);
58 }
59
60 if (argc >= 3) {
61 /* By default, don't wait unless user specifies. */
62 nr_usec = atoi(argv[2]);
63 }
64
65 if (argc >= 4) {
66 tmp_file_path = argv[3];
67 }
68
69 for (i = 0; i < nr_iter; i++) {
70 tracef("Test message %d with string \"%s\"", i, str);
71
72 /*
73 * First loop we create the file if asked to indicate
74 * that at least one tracepoint has been hit.
75 */
76 if (i == 0 && tmp_file_path) {
77 create_file(tmp_file_path);
78 }
79 usleep(nr_usec);
80 }
81
82 return 0;
83 }
This page took 0.032429 seconds and 5 git commands to generate.