SoW-2019-0002: Dynamic Snapshot
[lttng-tools.git] / tests / utils / testapp / gen-ust-tracef / gen-ust-tracef.c
CommitLineData
b02dcdb8 1/*
9d16b343
MJ
2 * Copyright (C) 2012 David Goulet <dgoulet@efficios.com>
3 * Copyright (C) 2014 Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
b02dcdb8 4 *
9d16b343 5 * SPDX-License-Identifier: LGPL-2.1-only
b02dcdb8 6 *
b02dcdb8
MD
7 */
8
70dac0d7 9#define _LGPL_SOURCE
b02dcdb8
MD
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>
95983a02 22#include "signal-helper.h"
b02dcdb8
MD
23
24const char *str = "test string";
25
1831ae68 26static void create_file(const char *path)
b02dcdb8
MD
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
41int 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
95983a02
JG
48 if (set_signal_handler()) {
49 return 1;
50 }
51
b02dcdb8
MD
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);
95983a02
JG
76 if (should_quit) {
77 break;
78 }
b02dcdb8
MD
79 }
80
81 return 0;
82}
This page took 0.050292 seconds and 5 git commands to generate.