Comparing the scaling of UST and SystemTap
[benchmarks.git] / ust-systemtap-tracepoints / 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* trace_mark :
22 *
23 * 1) tracepoint named : "ust_event"
24 * -) Probe 1 registered and recording the value 42
25 */
26
27 #include <stdio.h>
28 #include "tracepoint_benchmark.h"
29 #include <ust/type-serializer.h>
30 #include "trace.h"
31
32 #define NR_EVENTS 10000000
33
34 DEFINE_TRACE(ust_event);
35
36 void tp_probe(void *data, unsigned int p1);
37
38 DEFINE_MARKER_TP(ust, event, ust_event, tp_probe, "p1 %u");
39
40 /*
41 * Probe 1 --> ust_event
42 */
43 void tp_probe(void *data, unsigned int p1)
44 {
45 struct marker *marker;
46
47 marker = &GET_MARKER(ust, event);
48 ltt_specialized_trace(marker, data, &p1, sizeof(p1), sizeof(p1));
49 }
50
51 static void __attribute__((constructor)) init()
52 {
53 register_trace_ust_event(tp_probe, NULL);
54 }
55
56 void single_trace(unsigned int v)
57 {
58 TRACE(TRACEPOINT_BENCHMARK_SINGLE_TRACE(v));
59 trace_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.056828 seconds and 4 git commands to generate.