| 1 | /* |
| 2 | * Copyright (C) 2010 David Goulet <david.goulet@polymtl.ca> |
| 3 | * Copyright (C) 2010 Mathieu Desnoyers <mathieu.desnoyers@efficios.com> |
| 4 | * |
| 5 | * This library is free software; you can redistribute it and/or |
| 6 | * modify it under the terms of the GNU Lesser General Public |
| 7 | * License as published by the Free Software Foundation; either |
| 8 | * version 2.1 of the License, or (at your option) any later version. |
| 9 | * |
| 10 | * This library is distributed in the hope that it will be useful, |
| 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 13 | * Lesser General Public License for more details. |
| 14 | * |
| 15 | * You should have received a copy of the GNU Lesser General Public |
| 16 | * License along with this library; if not, write to the Free Software |
| 17 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
| 18 | */ |
| 19 | |
| 20 | /* |
| 21 | * This test is aimed at testing tracepoint *with* ust_marker : |
| 22 | * |
| 23 | * 1) tracepoint named : "ust_event" |
| 24 | * -) Probe 1 registered and recording the value 42 |
| 25 | */ |
| 26 | |
| 27 | #include <stdio.h> |
| 28 | |
| 29 | #define TRACEPOINT_CREATE_PROBES |
| 30 | #include "tracepoint_benchmark.h" |
| 31 | #include <ust/type-serializer.h> |
| 32 | |
| 33 | #define NR_EVENTS 10000000 |
| 34 | |
| 35 | void tp_probe(void *data, unsigned int p1); |
| 36 | |
| 37 | DEFINE_UST_MARKER_TP(event, ust_event, tp_probe, "p1 %u"); |
| 38 | |
| 39 | /* |
| 40 | * Probe 1 --> ust_event |
| 41 | */ |
| 42 | void tp_probe(void *data, unsigned int p1) |
| 43 | { |
| 44 | struct ust_marker *marker; |
| 45 | |
| 46 | marker = &GET_UST_MARKER(event); |
| 47 | ltt_specialized_trace(marker, data, &p1, sizeof(p1), sizeof(p1)); |
| 48 | } |
| 49 | |
| 50 | static void __attribute__((constructor)) init() |
| 51 | { |
| 52 | __register_tracepoint(ust_event, tp_probe, NULL); |
| 53 | } |
| 54 | |
| 55 | void single_trace(unsigned int v) |
| 56 | { |
| 57 | tracepoint(ust_event, v); |
| 58 | } |
| 59 | |
| 60 | void do_trace(void) |
| 61 | { |
| 62 | long i; |
| 63 | |
| 64 | for (i = 0; i < NR_EVENTS; i++) |
| 65 | single_trace(42); |
| 66 | } |
| 67 | |
| 68 | void *thr1(void *arg) |
| 69 | { |
| 70 | do_trace(); |
| 71 | return ((void*)1); |
| 72 | } |
| 73 | |
| 74 | int main(int argc, char **argv) |
| 75 | { |
| 76 | int err, i; |
| 77 | void *tret; |
| 78 | pthread_t *tid; |
| 79 | int nr_threads; |
| 80 | |
| 81 | if (argc > 1) |
| 82 | nr_threads = atoi(argv[1]); |
| 83 | else |
| 84 | nr_threads = 1; |
| 85 | printf("Starting test for %d threads\n", nr_threads); |
| 86 | |
| 87 | tid = malloc(sizeof(*tid) * nr_threads); |
| 88 | |
| 89 | for (i = 0; i < nr_threads; i++) { |
| 90 | err = pthread_create(&tid[i], NULL, thr1, NULL); |
| 91 | if (err != 0) |
| 92 | exit(1); |
| 93 | } |
| 94 | |
| 95 | for (i = 0; i < nr_threads; i++) { |
| 96 | err = pthread_join(tid[i], &tret); |
| 97 | if (err != 0) |
| 98 | exit(1); |
| 99 | } |
| 100 | free(tid); |
| 101 | return 0; |
| 102 | } |