Move to kernel style SPDX license identifiers
[lttng-ust.git] / tests / benchmark / bench.c
1 /*
2 * SPDX-License-Identifier: GPL-2.0-or-later
3 *
4 * Copyright 2010 Douglas Santos <douglas.santos@polymtl.ca>
5 *
6 * LTTng Userspace Tracer (UST) - benchmark tool
7 */
8
9 #include <stdio.h>
10 #include <pthread.h>
11 #include <stdlib.h>
12 #include <unistd.h>
13 #include <sched.h>
14 #include <time.h>
15
16 #ifdef TRACING
17 #define TRACEPOINT_DEFINE
18 #include "ust_tests_benchmark.h"
19 #endif
20
21 static int nr_cpus;
22 static unsigned long nr_events;
23
24 void do_stuff(void)
25 {
26 int v;
27 FILE *file;
28
29 v = 1;
30
31 file = fopen("/dev/null", "a");
32 fprintf(file, "%d", v);
33 fclose(file);
34 time(NULL);
35
36 #ifdef TRACING
37 tracepoint(ust_tests_benchmark, tpbench, v);
38 #endif
39
40 }
41
42
43 void *function(void *arg)
44 {
45 unsigned long i;
46
47 for(i = 0; i < nr_events; i++) {
48 do_stuff();
49 }
50 return NULL;
51 }
52
53 void usage(char **argv) {
54 printf("Usage: %s nr_cpus nr_events\n", argv[0]);
55 }
56
57
58 int main(int argc, char **argv)
59 {
60 void *retval;
61 int i;
62
63 if (argc < 3) {
64 usage(argv);
65 exit(1);
66 }
67
68 nr_cpus = atoi(argv[1]);
69 printf("using %d processor(s)\n", nr_cpus);
70
71 nr_events = atol(argv[2]);
72 printf("using %ld events per cpu\n", nr_events);
73
74 pthread_t thread[nr_cpus];
75 for (i = 0; i < nr_cpus; i++) {
76 if (pthread_create(&thread[i], NULL, function, NULL)) {
77 fprintf(stderr, "thread create %d failed\n", i);
78 exit(1);
79 }
80 }
81
82 for (i = 0; i < nr_cpus; i++) {
83 if (pthread_join(thread[i], &retval)) {
84 fprintf(stderr, "thread join %d failed\n", i);
85 exit(1);
86 }
87 }
88 return 0;
89 }
This page took 0.030906 seconds and 4 git commands to generate.