Privatize headers
[ust.git] / tests / tracepoint / benchmark / tracepoint_benchmark.c
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
32 /* Yes, this is now internal. */
33 #include "../../../libust/type-serializer.h"
34
35 #define NR_EVENTS 10000000
36
37 void tp_probe(void *data, unsigned int p1);
38
39 DEFINE_UST_MARKER_TP(event, ust_event, tp_probe, "p1 %u");
40
41 /*
42 * Probe 1 --> ust_event
43 */
44 void tp_probe(void *data, unsigned int p1)
45 {
46 struct ust_marker *marker;
47
48 marker = &GET_UST_MARKER(event);
49 ltt_specialized_trace(marker, data, &p1, sizeof(p1), sizeof(p1));
50 }
51
52 static void __attribute__((constructor)) init()
53 {
54 __register_tracepoint(ust_event, tp_probe, NULL);
55 }
56
57 void single_trace(unsigned int v)
58 {
59 tracepoint(ust_event, v);
60 }
61
62 void do_trace(void)
63 {
64 long i;
65
66 for (i = 0; i < NR_EVENTS; i++)
67 single_trace(42);
68 }
69
70 void *thr1(void *arg)
71 {
72 do_trace();
73 return ((void*)1);
74 }
75
76 int main(int argc, char **argv)
77 {
78 int err, i;
79 void *tret;
80 pthread_t *tid;
81 int nr_threads;
82
83 if (argc > 1)
84 nr_threads = atoi(argv[1]);
85 else
86 nr_threads = 1;
87 printf("Starting test for %d threads\n", nr_threads);
88
89 tid = malloc(sizeof(*tid) * nr_threads);
90
91 for (i = 0; i < nr_threads; i++) {
92 err = pthread_create(&tid[i], NULL, thr1, NULL);
93 if (err != 0)
94 exit(1);
95 }
96
97 for (i = 0; i < nr_threads; i++) {
98 err = pthread_join(tid[i], &tret);
99 if (err != 0)
100 exit(1);
101 }
102 free(tid);
103 return 0;
104 }
This page took 0.03029 seconds and 4 git commands to generate.