Update obsolete benchmark test
[lttng-ust.git] / tests / benchmark / bench.c
CommitLineData
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>
e6eed717 29#include <time.h>
e6af533d 30
a44af49d
ZT
31#ifdef TRACING
32#define TRACEPOINT_DEFINE
33#include "ust_tests_benchmark.h"
34#endif
35
e6af533d
DS
36static int nr_cpus;
37static unsigned long nr_events;
e6af533d
DS
38
39void do_stuff(void)
40{
41 int v;
42 FILE *file;
e6af533d
DS
43
44 v = 1;
45
e6eed717 46 file = fopen("/dev/null", "a");
e6af533d
DS
47 fprintf(file, "%d", v);
48 fclose(file);
e6eed717 49 time(NULL);
e6af533d 50
a44af49d
ZT
51#ifdef TRACING
52 tracepoint(ust_tests_benchmark, tpbench, v);
e6af533d
DS
53#endif
54
55}
56
57
58void *function(void *arg)
59{
60 unsigned long i;
61
62 for(i = 0; i < nr_events; i++) {
63 do_stuff();
64 }
65 return NULL;
66}
67
e6af533d
DS
68void usage(char **argv) {
69 printf("Usage: %s nr_cpus nr_events\n", argv[0]);
70}
71
72
73int main(int argc, char **argv)
74{
75 void *retval;
76 int i;
77
78 if (argc < 3) {
79 usage(argv);
80 exit(1);
81 }
82
83 nr_cpus = atoi(argv[1]);
84 printf("using %d processor(s)\n", nr_cpus);
85
86 nr_events = atol(argv[2]);
87 printf("using %ld events per cpu\n", nr_events);
88
89 pthread_t thread[nr_cpus];
90 for (i = 0; i < nr_cpus; i++) {
91 if (pthread_create(&thread[i], NULL, function, NULL)) {
92 fprintf(stderr, "thread create %d failed\n", i);
93 exit(1);
94 }
95 }
96
97 for (i = 0; i < nr_cpus; i++) {
98 if (pthread_join(thread[i], &retval)) {
99 fprintf(stderr, "thread join %d failed\n", i);
100 exit(1);
101 }
102 }
103 return 0;
104}
This page took 0.029488 seconds and 4 git commands to generate.