| 1 | /* |
| 2 | * Copyright (C) 2012 David Goulet <dgoulet@efficios.com> |
| 3 | * |
| 4 | * SPDX-License-Identifier: LGPL-2.1-only |
| 5 | * |
| 6 | */ |
| 7 | |
| 8 | #define _LGPL_SOURCE |
| 9 | #include <arpa/inet.h> |
| 10 | #include <getopt.h> |
| 11 | #include <stdarg.h> |
| 12 | #include <stdio.h> |
| 13 | #include <stdlib.h> |
| 14 | #include <string.h> |
| 15 | #include <sys/mman.h> |
| 16 | #include <sys/stat.h> |
| 17 | #include <sys/types.h> |
| 18 | #include <unistd.h> |
| 19 | #include "utils.h" |
| 20 | #include "signal-helper.h" |
| 21 | |
| 22 | #define TRACEPOINT_DEFINE |
| 23 | #include "tp.h" |
| 24 | |
| 25 | static struct option long_options[] = |
| 26 | { |
| 27 | /* These options set a flag. */ |
| 28 | {"iter", required_argument, 0, 'i'}, |
| 29 | {"wait", required_argument, 0, 'w'}, |
| 30 | {0, 0, 0, 0} |
| 31 | }; |
| 32 | |
| 33 | int main(int argc, char **argv) |
| 34 | { |
| 35 | int i, netint, ret = 0, option_index, option; |
| 36 | long values[] = { 1, 2, 3 }; |
| 37 | char text[10] = "test"; |
| 38 | double dbl = 2.0; |
| 39 | float flt = 2222.0; |
| 40 | unsigned int nr_iter = 100; |
| 41 | useconds_t nr_usec = 0; |
| 42 | |
| 43 | while ((option = getopt_long(argc, argv, "i:w:", |
| 44 | long_options, &option_index)) != -1) { |
| 45 | switch (option) { |
| 46 | case 'i': |
| 47 | nr_iter = atoi(optarg); |
| 48 | break; |
| 49 | case 'w': |
| 50 | nr_usec = atoi(optarg); |
| 51 | break; |
| 52 | case '?': |
| 53 | /* getopt_long already printed an error message. */ |
| 54 | break; |
| 55 | default: |
| 56 | ret = -1; |
| 57 | goto end; |
| 58 | } |
| 59 | } |
| 60 | |
| 61 | if (set_signal_handler()) { |
| 62 | ret = -1; |
| 63 | goto end; |
| 64 | } |
| 65 | |
| 66 | |
| 67 | for (i = 0; i < nr_iter; i++) { |
| 68 | netint = htonl(i); |
| 69 | tracepoint(tp, tptest1, i, netint, values, text, strlen(text), |
| 70 | dbl, flt); |
| 71 | tracepoint(tp, tptest2, i, netint, values, text, strlen(text), |
| 72 | dbl, flt); |
| 73 | tracepoint(tp, tptest3, i, netint, values, text, strlen(text), |
| 74 | dbl, flt); |
| 75 | tracepoint(tp, tptest4, i, netint, values, text, strlen(text), |
| 76 | dbl, flt); |
| 77 | tracepoint(tp, tptest5, i, netint, values, text, strlen(text), |
| 78 | dbl, flt); |
| 79 | if (nr_usec) { |
| 80 | if (usleep_safe(nr_usec)) { |
| 81 | ret = -1; |
| 82 | goto end; |
| 83 | } |
| 84 | } |
| 85 | if (should_quit) { |
| 86 | break; |
| 87 | } |
| 88 | } |
| 89 | |
| 90 | end: |
| 91 | exit(!ret ? EXIT_SUCCESS : EXIT_FAILURE); |
| 92 | } |