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 | ||
23 | #define _GNU_SOURCE | |
24 | #include <stdio.h> | |
25 | #include <pthread.h> | |
26 | #include <stdlib.h> | |
27 | #include <unistd.h> | |
28 | #include <sched.h> | |
29 | #include <ust/marker.h> | |
e6eed717 | 30 | #include <time.h> |
e6af533d DS |
31 | |
32 | static int nr_cpus; | |
33 | static unsigned long nr_events; | |
e6af533d DS |
34 | |
35 | void do_stuff(void) | |
36 | { | |
37 | int v; | |
38 | FILE *file; | |
e6af533d DS |
39 | |
40 | v = 1; | |
41 | ||
e6eed717 | 42 | file = fopen("/dev/null", "a"); |
e6af533d DS |
43 | fprintf(file, "%d", v); |
44 | fclose(file); | |
e6eed717 | 45 | time(NULL); |
e6af533d DS |
46 | |
47 | #ifdef MARKER | |
686debc3 | 48 | ust_marker(event, "event %d", v); |
e6af533d DS |
49 | #endif |
50 | ||
51 | } | |
52 | ||
53 | ||
54 | void *function(void *arg) | |
55 | { | |
56 | unsigned long i; | |
57 | ||
58 | for(i = 0; i < nr_events; i++) { | |
59 | do_stuff(); | |
60 | } | |
61 | return NULL; | |
62 | } | |
63 | ||
e6af533d DS |
64 | void usage(char **argv) { |
65 | printf("Usage: %s nr_cpus nr_events\n", argv[0]); | |
66 | } | |
67 | ||
68 | ||
69 | int main(int argc, char **argv) | |
70 | { | |
71 | void *retval; | |
72 | int i; | |
73 | ||
74 | if (argc < 3) { | |
75 | usage(argv); | |
76 | exit(1); | |
77 | } | |
78 | ||
79 | nr_cpus = atoi(argv[1]); | |
80 | printf("using %d processor(s)\n", nr_cpus); | |
81 | ||
82 | nr_events = atol(argv[2]); | |
83 | printf("using %ld events per cpu\n", nr_events); | |
84 | ||
85 | pthread_t thread[nr_cpus]; | |
86 | for (i = 0; i < nr_cpus; i++) { | |
87 | if (pthread_create(&thread[i], NULL, function, NULL)) { | |
88 | fprintf(stderr, "thread create %d failed\n", i); | |
89 | exit(1); | |
90 | } | |
91 | } | |
92 | ||
93 | for (i = 0; i < nr_cpus; i++) { | |
94 | if (pthread_join(thread[i], &retval)) { | |
95 | fprintf(stderr, "thread join %d failed\n", i); | |
96 | exit(1); | |
97 | } | |
98 | } | |
99 | return 0; | |
100 | } |