2 * SPDX-License-Identifier: GPL-2.0-or-later
4 * Copyright 2010 Douglas Santos <douglas.santos@polymtl.ca>
5 * Copyright 2021 Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
7 * LTTng Userspace Tracer (UST) - benchmark tool
16 #include <urcu/compiler.h>
19 #define TRACEPOINT_DEFINE
20 #include "ust_tests_benchmark.h"
23 #define printf_verbose(fmt, args...) \
26 printf(fmt, ## args); \
29 static int verbose_mode
;
31 struct thread_counter
{
32 unsigned long long nr_loops
;
35 static int nr_threads
;
36 static unsigned long duration
;
38 static volatile int test_go
, test_stop
;
47 for (i
= 0; i
< 100; i
++)
50 tracepoint(ust_tests_benchmark
, tpbench
, v
);
54 void *function(void *arg
)
56 unsigned long long nr_loops
= 0;
57 struct thread_counter
*thread_counter
= arg
;
68 thread_counter
->nr_loops
= nr_loops
;
72 void usage(char **argv
) {
73 printf("Usage: %s nr_threads duration(s) <OPTIONS>\n", argv
[0]);
75 printf(" [-v] (verbose output)\n");
79 int main(int argc
, char **argv
)
81 unsigned long long total_loops
= 0;
91 nr_threads
= atoi(argv
[1]);
92 duration
= atol(argv
[2]);
94 for (i
= 3; i
< argc
; i
++) {
95 if (argv
[i
][0] != '-')
104 printf_verbose("using %d thread(s)\n", nr_threads
);
105 printf_verbose("for a duration of %lds\n", duration
);
107 pthread_t thread
[nr_threads
];
108 struct thread_counter thread_counter
[nr_threads
];
110 for (i
= 0; i
< nr_threads
; i
++) {
111 thread_counter
[i
].nr_loops
= 0;
112 if (pthread_create(&thread
[i
], NULL
, function
, &thread_counter
[i
])) {
113 fprintf(stderr
, "thread create %d failed\n", i
);
120 for (i_thr
= 0; i_thr
< duration
; i_thr
++) {
123 fwrite(".", sizeof(char), 1, stdout
);
127 printf_verbose("\n");
131 for (i
= 0; i
< nr_threads
; i
++) {
132 if (pthread_join(thread
[i
], &retval
)) {
133 fprintf(stderr
, "thread join %d failed\n", i
);
136 total_loops
+= thread_counter
[i
].nr_loops
;
138 printf("Number of loops: %llu\n", total_loops
);