2 * Copyright (C) - 2012 David Goulet <dgoulet@efficios.com>
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.
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
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
19 #include <arpa/inet.h>
27 #include <sys/types.h>
34 #define TRACEPOINT_DEFINE
37 void create_file(const char *path
)
39 static bool file_created
= false;
42 if (!path
|| file_created
) {
46 ret
= creat(path
, S_IRWXU
);
48 fprintf(stderr
, "Failed to create file %s\n", path
);
57 void wait_on_file(const char *path
)
66 ret
= stat(path
, &buf
);
67 if (ret
== -1 && errno
== ENOENT
) {
68 (void) poll(NULL
, 0, 10); /* 10 ms delay */
79 int main(int argc
, char **argv
)
81 unsigned int i
, netint
;
82 long values
[] = { 1, 2, 3 };
83 char text
[10] = "test";
87 useconds_t nr_usec
= 0;
88 char *after_first_event_file_path
= NULL
;
89 char *before_last_event_file_path
= NULL
;
93 * If nr_iter is negative, do an infinite tracing loop.
95 nr_iter
= atoi(argv
[1]);
99 /* By default, don't wait unless user specifies. */
100 nr_usec
= atoi(argv
[2]);
104 after_first_event_file_path
= argv
[3];
108 before_last_event_file_path
= argv
[4];
111 for (i
= 0; nr_iter
< 0 || i
< nr_iter
; i
++) {
112 if (nr_iter
>= 0 && i
== nr_iter
- 1) {
114 * Wait on synchronization before writing last
117 wait_on_file(before_last_event_file_path
);
120 tracepoint(tp
, tptest
, i
, netint
, values
, text
,
121 strlen(text
), dbl
, flt
);
124 * First loop we create the file if asked to indicate
125 * that at least one tracepoint has been hit.
127 create_file(after_first_event_file_path
);