Commit | Line | Data |
---|---|---|
e6af533d DS |
1 | /* |
2 | * bench.c | |
3 | * | |
4 | * LTTng Userspace Tracer (UST) - benchmark tool | |
046975d0 MD |
5 | * |
6 | * Copyright 2010 - Douglas Santos <douglas.santos@polymtl.ca> | |
7 | * | |
8 | * This program is free software; you can redistribute it and/or modify | |
9 | * it under the terms of the GNU General Public License as published by | |
10 | * the Free Software Foundation; either version 2 of the License, or | |
11 | * (at your option) any later version. | |
12 | * | |
13 | * This program is distributed in the hope that it will be useful, | |
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
16 | * GNU General Public License for more details. | |
17 | * | |
18 | * You should have received a copy of the GNU General Public License along | |
19 | * with this program; if not, write to the Free Software Foundation, Inc., | |
20 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. | |
e6af533d DS |
21 | */ |
22 | ||
e6af533d DS |
23 | #include <stdio.h> |
24 | #include <pthread.h> | |
25 | #include <stdlib.h> | |
26 | #include <unistd.h> | |
27 | #include <sched.h> | |
e6eed717 | 28 | #include <time.h> |
e6af533d | 29 | |
a44af49d ZT |
30 | #ifdef TRACING |
31 | #define TRACEPOINT_DEFINE | |
32 | #include "ust_tests_benchmark.h" | |
33 | #endif | |
34 | ||
e6af533d DS |
35 | static int nr_cpus; |
36 | static unsigned long nr_events; | |
e6af533d DS |
37 | |
38 | void do_stuff(void) | |
39 | { | |
40 | int v; | |
41 | FILE *file; | |
e6af533d DS |
42 | |
43 | v = 1; | |
44 | ||
e6eed717 | 45 | file = fopen("/dev/null", "a"); |
e6af533d DS |
46 | fprintf(file, "%d", v); |
47 | fclose(file); | |
e6eed717 | 48 | time(NULL); |
e6af533d | 49 | |
a44af49d ZT |
50 | #ifdef TRACING |
51 | tracepoint(ust_tests_benchmark, tpbench, v); | |
e6af533d DS |
52 | #endif |
53 | ||
54 | } | |
55 | ||
56 | ||
57 | void *function(void *arg) | |
58 | { | |
59 | unsigned long i; | |
60 | ||
61 | for(i = 0; i < nr_events; i++) { | |
62 | do_stuff(); | |
63 | } | |
64 | return NULL; | |
65 | } | |
66 | ||
e6af533d DS |
67 | void usage(char **argv) { |
68 | printf("Usage: %s nr_cpus nr_events\n", argv[0]); | |
69 | } | |
70 | ||
71 | ||
72 | int main(int argc, char **argv) | |
73 | { | |
74 | void *retval; | |
75 | int i; | |
76 | ||
77 | if (argc < 3) { | |
78 | usage(argv); | |
79 | exit(1); | |
80 | } | |
81 | ||
82 | nr_cpus = atoi(argv[1]); | |
83 | printf("using %d processor(s)\n", nr_cpus); | |
84 | ||
85 | nr_events = atol(argv[2]); | |
86 | printf("using %ld events per cpu\n", nr_events); | |
87 | ||
88 | pthread_t thread[nr_cpus]; | |
89 | for (i = 0; i < nr_cpus; i++) { | |
90 | if (pthread_create(&thread[i], NULL, function, NULL)) { | |
91 | fprintf(stderr, "thread create %d failed\n", i); | |
92 | exit(1); | |
93 | } | |
94 | } | |
95 | ||
96 | for (i = 0; i < nr_cpus; i++) { | |
97 | if (pthread_join(thread[i], &retval)) { | |
98 | fprintf(stderr, "thread join %d failed\n", i); | |
99 | exit(1); | |
100 | } | |
101 | } | |
102 | return 0; | |
103 | } |