SoW-2019-0002: Dynamic Snapshot
[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 * SPDX-License-Identifier: LGPL-2.1-only
6 *
7 */
8
9 #define _LGPL_SOURCE
10 #include <assert.h>
11 #include <fcntl.h>
12 #include <stdarg.h>
13 #include <stdio.h>
14 #include <stdlib.h>
15 #include <string.h>
16 #include <sys/mman.h>
17 #include <sys/stat.h>
18 #include <sys/types.h>
19 #include <unistd.h>
20
21 #include <lttng/tracef.h>
22 #include "signal-helper.h"
23
24 const char *str = "test string";
25
26 static void create_file(const char *path)
27 {
28 int ret;
29
30 assert(path);
31
32 ret = creat(path, S_IRWXU);
33 if (ret < 0) {
34 fprintf(stderr, "Failed to create file %s\n", path);
35 return;
36 }
37
38 (void) close(ret);
39 }
40
41 int main(int argc, char **argv)
42 {
43 int i;
44 unsigned int nr_iter = 100;
45 useconds_t nr_usec = 0;
46 char *tmp_file_path = NULL;
47
48 if (set_signal_handler()) {
49 return 1;
50 }
51
52 if (argc >= 2) {
53 nr_iter = atoi(argv[1]);
54 }
55
56 if (argc >= 3) {
57 /* By default, don't wait unless user specifies. */
58 nr_usec = atoi(argv[2]);
59 }
60
61 if (argc >= 4) {
62 tmp_file_path = argv[3];
63 }
64
65 for (i = 0; i < nr_iter; i++) {
66 tracef("Test message %d with string \"%s\"", i, str);
67
68 /*
69 * First loop we create the file if asked to indicate
70 * that at least one tracepoint has been hit.
71 */
72 if (i == 0 && tmp_file_path) {
73 create_file(tmp_file_path);
74 }
75 usleep(nr_usec);
76 if (should_quit) {
77 break;
78 }
79 }
80
81 return 0;
82 }
This page took 0.048788 seconds and 5 git commands to generate.