X-Git-Url: http://git.lttng.org/?a=blobdiff_plain;f=tests%2Ftracepoint%2Fbenchmark%2Ftracepoint_benchmark.c;fp=tests%2Ftracepoint%2Fbenchmark%2Ftracepoint_benchmark.c;h=8af4b84afc67d6d13afc2eec326fc2c85b3d4359;hb=91594b712729c0d855efeab849c2093706336941;hp=0000000000000000000000000000000000000000;hpb=df39c97f33c65bc39945b5ebe429526fb38f3406;p=ust.git diff --git a/tests/tracepoint/benchmark/tracepoint_benchmark.c b/tests/tracepoint/benchmark/tracepoint_benchmark.c new file mode 100644 index 0000000..8af4b84 --- /dev/null +++ b/tests/tracepoint/benchmark/tracepoint_benchmark.c @@ -0,0 +1,102 @@ +/* + * Copyright (C) 2010 David Goulet + * Copyright (C) 2010 Mathieu Desnoyers + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +/* + * This test is aimed at testing tracepoint *with* trace_mark : + * + * 1) tracepoint named : "ust_event" + * -) Probe 1 registered and recording the value 42 + */ + +#include +#include "tracepoint_benchmark.h" +#include + +#define NR_EVENTS 10000000 + +DEFINE_TRACE(ust_event); + +void tp_probe(void *data, unsigned int p1); + +DEFINE_MARKER_TP(ust, event, ust_event, tp_probe, "p1 %u"); + +/* + * Probe 1 --> ust_event + */ +void tp_probe(void *data, unsigned int p1) +{ + struct marker *marker; + + marker = &GET_MARKER(ust, event); + ltt_specialized_trace(marker, data, &p1, sizeof(p1), sizeof(p1)); +} + +static void __attribute__((constructor)) init() +{ + register_trace_ust_event(tp_probe, NULL); +} + +void single_trace(unsigned int v) +{ + trace_ust_event(v); +} + +void do_trace(void) +{ + long i; + + for (i = 0; i < NR_EVENTS; i++) + single_trace(42); +} + +void *thr1(void *arg) +{ + do_trace(); + return ((void*)1); +} + +int main(int argc, char **argv) +{ + int err, i; + void *tret; + pthread_t *tid; + int nr_threads; + + if (argc > 1) + nr_threads = atoi(argv[1]); + else + nr_threads = 1; + printf("Starting test for %d threads\n", nr_threads); + + tid = malloc(sizeof(*tid) * nr_threads); + + for (i = 0; i < nr_threads; i++) { + err = pthread_create(&tid[i], NULL, thr1, NULL); + if (err != 0) + exit(1); + } + + for (i = 0; i < nr_threads; i++) { + err = pthread_join(tid[i], &tret); + if (err != 0) + exit(1); + } + free(tid); + return 0; +}