-
Notifications
You must be signed in to change notification settings - Fork 69
/
Copy pathcali-regionprofile.cpp
86 lines (62 loc) · 2.72 KB
/
cali-regionprofile.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
86
// Copyright (c) 2019, Lawrence Livermore National Security, LLC.
// See top-level LICENSE file for details.
// Example of the RegionProfile channel class
#include <caliper/cali.h>
#include <caliper/RegionProfile.h>
void foo()
{
CALI_CXX_MARK_FUNCTION;
}
int main()
{
cali_config_preset("CALI_LOG_VERBOSITY", "0");
// The RegionProfile channel controller computes the total time spent
// in annotated regions
cali::RegionProfile rp;
// Activate recording
rp.start();
CALI_MARK_FUNCTION_BEGIN;
CALI_MARK_BEGIN("init");
int count = 4;
CALI_MARK_END("init");
CALI_CXX_MARK_LOOP_BEGIN(mainloop, "mainloop");
for (int i = 0; i < count; ++i)
foo();
CALI_CXX_MARK_LOOP_END(mainloop);
CALI_MARK_FUNCTION_END;
// Stop recording
rp.stop();
// Get and print the inclusive time spent in each region
{
std::map<std::string, double> region_times;
double total_time;
std::tie(region_times, std::ignore, total_time) = rp.inclusive_region_times();
std::cerr << "Inclusive time per region:"
<< "\n main: " << region_times["main"] << "\n init: " << region_times["init"]
<< "\n mainloop: " << region_times["mainloop"] << "\n foo: " << region_times["foo"]
<< "\n(Total profiling time: " << total_time << " sec)\n"
<< std::endl;
}
// Get and print the exclusive time spent in each region
{
std::map<std::string, double> region_times;
double total_time;
std::tie(region_times, std::ignore, total_time) = rp.exclusive_region_times();
std::cerr << "Exclusive time per region:"
<< "\n main: " << region_times["main"] << "\n init: " << region_times["init"]
<< "\n mainloop: " << region_times["mainloop"] << "\n foo: " << region_times["foo"]
<< "\n(Total profiling time: " << total_time << " sec)\n"
<< std::endl;
}
// Get and print the exclusive time in function regions
{
std::map<std::string, double> region_times;
double total_function_time;
double total_time;
std::tie(region_times, total_function_time, total_time) = rp.exclusive_region_times("function");
std::cerr << "Exclusive time per region (functions only):"
<< "\n main: " << region_times["main"] << "\n foo: " << region_times["foo"]
<< "\n(Total exclusive time in functions: " << total_function_time << " of " << total_time << " sec)"
<< std::endl;
}
}