-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbasic-benchmark.c
98 lines (83 loc) · 2.2 KB
/
basic-benchmark.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
/*
* LTTng-UST benchmarks
* Copyright (C) 2013 Samuel Demers <samuel@samdemers.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
#include <stdio.h>
#include <stdlib.h>
#ifdef WITH_UST
#include <lttng/tracepoint.h>
#ifdef USE_GENERATED_TP
#include "generated_tp.h"
#else
#include "sum.tp.h"
#endif
#endif
#include "shared_events.h"
/*
* Add side effect to loop to ensure it is not completely optimized away
* by the compiler. It is _not_ static on purpose, so the compile unit
* cannot assume it is not touched elsewhere. Defined as volatile so the
* compiler does not perform any kind of write-combining.
*/
volatile int side_effect[2];
static
void print_usage(int argc, char **argv)
{
fprintf(stderr, "Usage: %s [<iterations>]\n", argv[0]);
}
int main(int argc, char **argv)
{
long iterations;
int x = 0, y = 1, i;
if (shared_events_add("main")) {
exit(EXIT_FAILURE);
}
if (argc == 1) {
// We may just want to measure process startup time
exit(EXIT_SUCCESS);
}
if (argc > 2) {
print_usage(argc, argv);
exit(EXIT_FAILURE);
}
iterations = strtol(argv[1], (char **) NULL, 10);
if (iterations <= 0) {
print_usage(argc, argv);
exit(EXIT_FAILURE);
}
if (shared_events_add("start")) {
exit(EXIT_FAILURE);
}
for (i = 0; i < iterations; i++) {
int z = x + y;
x = y;
y = z;
side_effect[0] = x;
side_effect[1] = y;
#ifdef WITH_UST
#ifdef USE_GENERATED_TP
GENERATED_TP
#else
tracepoint(benchmark_tracepoint, sum, x, y);
#endif
#endif
}
if (shared_events_add("end")) {
exit(EXIT_FAILURE);
}
exit(EXIT_SUCCESS);
}