Commit | Line | Data |
---|---|---|
e6af533d DS |
1 | /* |
2 | * bench.c | |
3 | * | |
4 | * LTTng Userspace Tracer (UST) - benchmark tool | |
5 | */ | |
6 | ||
7 | #define _GNU_SOURCE | |
8 | #include <stdio.h> | |
9 | #include <pthread.h> | |
10 | #include <stdlib.h> | |
11 | #include <unistd.h> | |
12 | #include <sched.h> | |
13 | #include <ust/marker.h> | |
e6eed717 | 14 | #include <time.h> |
e6af533d DS |
15 | |
16 | static int nr_cpus; | |
17 | static unsigned long nr_events; | |
e6af533d DS |
18 | |
19 | void do_stuff(void) | |
20 | { | |
21 | int v; | |
22 | FILE *file; | |
e6af533d DS |
23 | |
24 | v = 1; | |
25 | ||
e6eed717 | 26 | file = fopen("/dev/null", "a"); |
e6af533d DS |
27 | fprintf(file, "%d", v); |
28 | fclose(file); | |
e6eed717 | 29 | time(NULL); |
e6af533d DS |
30 | |
31 | #ifdef MARKER | |
686debc3 | 32 | ust_marker(event, "event %d", v); |
e6af533d DS |
33 | #endif |
34 | ||
35 | } | |
36 | ||
37 | ||
38 | void *function(void *arg) | |
39 | { | |
40 | unsigned long i; | |
41 | ||
42 | for(i = 0; i < nr_events; i++) { | |
43 | do_stuff(); | |
44 | } | |
45 | return NULL; | |
46 | } | |
47 | ||
e6af533d DS |
48 | void usage(char **argv) { |
49 | printf("Usage: %s nr_cpus nr_events\n", argv[0]); | |
50 | } | |
51 | ||
52 | ||
53 | int main(int argc, char **argv) | |
54 | { | |
55 | void *retval; | |
56 | int i; | |
57 | ||
58 | if (argc < 3) { | |
59 | usage(argv); | |
60 | exit(1); | |
61 | } | |
62 | ||
63 | nr_cpus = atoi(argv[1]); | |
64 | printf("using %d processor(s)\n", nr_cpus); | |
65 | ||
66 | nr_events = atol(argv[2]); | |
67 | printf("using %ld events per cpu\n", nr_events); | |
68 | ||
69 | pthread_t thread[nr_cpus]; | |
70 | for (i = 0; i < nr_cpus; i++) { | |
71 | if (pthread_create(&thread[i], NULL, function, NULL)) { | |
72 | fprintf(stderr, "thread create %d failed\n", i); | |
73 | exit(1); | |
74 | } | |
75 | } | |
76 | ||
77 | for (i = 0; i < nr_cpus; i++) { | |
78 | if (pthread_join(thread[i], &retval)) { | |
79 | fprintf(stderr, "thread join %d failed\n", i); | |
80 | exit(1); | |
81 | } | |
82 | } | |
83 | return 0; | |
84 | } |