Markers: remove channel name from trace_mark()
[ust.git] / tests / benchmark / bench.c
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>
14 #include <time.h>
15
16 static int nr_cpus;
17 static unsigned long nr_events;
18
19 void do_stuff(void)
20 {
21 int v;
22 FILE *file;
23
24 v = 1;
25
26 file = fopen("/dev/null", "a");
27 fprintf(file, "%d", v);
28 fclose(file);
29 time(NULL);
30
31 #ifdef MARKER
32 trace_mark(event, "event %d", v);
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
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 }
This page took 0.030429 seconds and 4 git commands to generate.