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
;
48 for (i
= 0; i
< 100; i
++)
51 tracepoint(ust_tests_benchmark
, tpbench
, v
);
57 void *function(void *arg
)
59 unsigned long long nr_loops
= 0;
60 struct thread_counter
*thread_counter
= arg
;
71 thread_counter
->nr_loops
= nr_loops
;
76 void usage(char **argv
) {
77 printf("Usage: %s nr_threads duration(s) <OPTIONS>\n", argv
[0]);
79 printf(" [-v] (verbose output)\n");
83 int main(int argc
, char **argv
)
85 unsigned long long total_loops
= 0;
95 nr_threads
= atoi(argv
[1]);
96 duration
= atol(argv
[2]);
98 for (i
= 3; i
< argc
; i
++) {
99 if (argv
[i
][0] != '-')
101 switch (argv
[i
][1]) {
108 printf_verbose("using %d thread(s)\n", nr_threads
);
109 printf_verbose("for a duration of %lds\n", duration
);
111 pthread_t thread
[nr_threads
];
112 struct thread_counter thread_counter
[nr_threads
];
114 for (i
= 0; i
< nr_threads
; i
++) {
115 thread_counter
[i
].nr_loops
= 0;
116 if (pthread_create(&thread
[i
], NULL
, function
, &thread_counter
[i
])) {
117 fprintf(stderr
, "thread create %d failed\n", i
);
124 for (i_thr
= 0; i_thr
< duration
; i_thr
++) {
127 fwrite(".", sizeof(char), 1, stdout
);
131 printf_verbose("\n");
135 for (i
= 0; i
< nr_threads
; i
++) {
136 if (pthread_join(thread
[i
], &retval
)) {
137 fprintf(stderr
, "thread join %d failed\n", i
);
140 total_loops
+= thread_counter
[i
].nr_loops
;
142 printf("Number of loops: %llu\n", total_loops
);