4 * LTTng Userspace Tracer (UST) - benchmark tool
6 * Copyright 2010 - Douglas Santos <douglas.santos@polymtl.ca>
7 * Copyright 2021 - Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License along
20 * with this program; if not, write to the Free Software Foundation, Inc.,
21 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
31 #include <urcu/compiler.h>
34 #define TRACEPOINT_DEFINE
35 #include "ust_tests_benchmark.h"
38 #define printf_verbose(fmt, args...) \
41 printf(fmt, ## args); \
44 static int verbose_mode
;
46 struct thread_counter
{
47 unsigned long long nr_loops
;
50 static int nr_threads
;
51 static unsigned long duration
;
53 static volatile int test_go
, test_stop
;
62 for (i
= 0; i
< 100; i
++)
65 tracepoint(ust_tests_benchmark
, tpbench
, v
);
69 void *function(void *arg
)
71 unsigned long long nr_loops
= 0;
72 struct thread_counter
*thread_counter
= arg
;
83 thread_counter
->nr_loops
= nr_loops
;
87 void usage(char **argv
) {
88 printf("Usage: %s nr_threads duration(s) <OPTIONS>\n", argv
[0]);
90 printf(" [-v] (verbose output)\n");
94 int main(int argc
, char **argv
)
96 unsigned long long total_loops
= 0;
106 nr_threads
= atoi(argv
[1]);
107 duration
= atol(argv
[2]);
109 for (i
= 3; i
< argc
; i
++) {
110 if (argv
[i
][0] != '-')
112 switch (argv
[i
][1]) {
119 printf_verbose("using %d thread(s)\n", nr_threads
);
120 printf_verbose("for a duration of %lds\n", duration
);
122 pthread_t thread
[nr_threads
];
123 struct thread_counter thread_counter
[nr_threads
];
125 for (i
= 0; i
< nr_threads
; i
++) {
126 thread_counter
[i
].nr_loops
= 0;
127 if (pthread_create(&thread
[i
], NULL
, function
, &thread_counter
[i
])) {
128 fprintf(stderr
, "thread create %d failed\n", i
);
135 for (i_thr
= 0; i_thr
< duration
; i_thr
++) {
138 fwrite(".", sizeof(char), 1, stdout
);
142 printf_verbose("\n");
146 for (i
= 0; i
< nr_threads
; i
++) {
147 if (pthread_join(thread
[i
], &retval
)) {
148 fprintf(stderr
, "thread join %d failed\n", i
);
151 total_loops
+= thread_counter
[i
].nr_loops
;
153 printf("Number of loops: %llu\n", total_loops
);