| 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 | #include <assert.h> |
| 19 | #include <arpa/inet.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 | #define TRACEPOINT_DEFINE |
| 31 | #include "tp.h" |
| 32 | |
| 33 | void create_file(const char *path) |
| 34 | { |
| 35 | int ret; |
| 36 | |
| 37 | assert(path); |
| 38 | |
| 39 | ret = creat(path, S_IRWXU); |
| 40 | if (ret < 0) { |
| 41 | fprintf(stderr, "Failed to create file %s\n", path); |
| 42 | return; |
| 43 | } |
| 44 | |
| 45 | (void) close(ret); |
| 46 | } |
| 47 | |
| 48 | int main(int argc, char **argv) |
| 49 | { |
| 50 | int i, netint; |
| 51 | long values[] = { 1, 2, 3 }; |
| 52 | char text[10] = "test"; |
| 53 | double dbl = 2.0; |
| 54 | float flt = 2222.0; |
| 55 | unsigned int nr_iter = 100; |
| 56 | useconds_t nr_usec = 0; |
| 57 | char *tmp_file_path = NULL; |
| 58 | |
| 59 | if (argc >= 2) { |
| 60 | nr_iter = atoi(argv[1]); |
| 61 | } |
| 62 | |
| 63 | if (argc >= 3) { |
| 64 | /* By default, don't wait unless user specifies. */ |
| 65 | nr_usec = atoi(argv[2]); |
| 66 | } |
| 67 | |
| 68 | if (argc >= 4) { |
| 69 | tmp_file_path = argv[3]; |
| 70 | } |
| 71 | |
| 72 | for (i = 0; i < nr_iter; i++) { |
| 73 | netint = htonl(i); |
| 74 | tracepoint(tp, tptest, i, netint, values, text, strlen(text), dbl, |
| 75 | flt); |
| 76 | |
| 77 | /* |
| 78 | * First loop we create the file if asked to indicate that at least one |
| 79 | * tracepoint has been hit. |
| 80 | */ |
| 81 | if (i == 0 && tmp_file_path) { |
| 82 | create_file(tmp_file_path); |
| 83 | } |
| 84 | usleep(nr_usec); |
| 85 | } |
| 86 | |
| 87 | return 0; |
| 88 | } |