forked from LLNL/Caliper
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathci_test_macros.cpp
85 lines (60 loc) · 1.66 KB
/
ci_test_macros.cpp
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
// --- Caliper continuous integration test app for basic trace test
#define _XOPEN_SOURCE
#include <unistd.h> /* usleep */
#include "caliper/cali.h"
#include "caliper/cali-manager.h"
#include <string>
// test C and C++ macros
void foo(int count, int sleep_usec)
{
CALI_CXX_MARK_FUNCTION;
CALI_MARK_BEGIN("pre-loop");
CALI_WRAP_STATEMENT("foo.init", count = std::max(1, count));
CALI_MARK_END("pre-loop");
CALI_MARK_LOOP_BEGIN(fooloop, "fooloop");
for (int i = 0; i < count; ++i) {
CALI_MARK_ITERATION_BEGIN(fooloop, i);
if (sleep_usec > 0)
usleep(sleep_usec);
CALI_MARK_ITERATION_END(fooloop);
}
CALI_MARK_LOOP_END(fooloop);
}
void bar()
{
CALI_CXX_MARK_FUNCTION;
}
int main(int argc, char* argv[])
{
int sleep_usec = 0;
if (argc > 1)
sleep_usec = std::stoi(argv[1]);
cali::ConfigManager mgr;
if (argc > 2)
if (std::string(argv[2]) != "none")
mgr.add(argv[2]);
if (mgr.error()) {
std::cerr << mgr.error_msg() << std::endl;
return -1;
}
mgr.start();
CALI_MARK_FUNCTION_BEGIN;
int count = 4;
{
CALI_CXX_MARK_SCOPE("before_loop");
CALI_CXX_MARK_SCOPE("inner_before_loop");
if (argc > 3)
count = std::max(1, std::stoi(argv[3]));
}
CALI_CXX_MARK_LOOP_BEGIN(mainloop, "main loop");
for (int i = 0; i < count; ++i) {
CALI_CXX_MARK_LOOP_ITERATION(mainloop, i);
foo(count, sleep_usec);
}
CALI_CXX_MARK_LOOP_END(mainloop);
CALI_MARK_PHASE_BEGIN("after_loop");
bar();
CALI_MARK_PHASE_END("after_loop");
CALI_MARK_FUNCTION_END;
mgr.flush();
}