-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathPapiProfiler.h
68 lines (63 loc) · 2.79 KB
/
PapiProfiler.h
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
#ifndef __PAPI_PROFILER_H__
#define __PAPI_PROFILER_H__
#if defined(PAPI_PROFILE)
#include <papi.h>
#include <iostream>
class PapiProfiler{
public:
static void InitPapiProfiler(){
// l1_dcm(conflict with lst_ins), l2_dcm, l2_dca, l2_tcm, l2_tca, l3_tcm, l3_tca / res_stl,tot_cyc
// L2 cache miss ratio: PAPI_L2_TCM / PAPI_L2_TCA
// graduated instructions per cycle = PAPI_TOT_INS / PAPI_TOT_CYC
// percentage of cycles stalled on any resource = PAPI_RES_STL / PAPI_TOT_CYC
InitPapiProfiler1();
}
static void InitPapiProfiler1(){
papi_events[0] = PAPI_L2_DCM;
papi_events[1] = PAPI_L2_DCA;
papi_events[2] = PAPI_L3_TCM;
papi_events[3] = PAPI_L3_TCA;
}
static void InitPapiProfiler2(){
papi_events[0] = PAPI_TOT_INS;
papi_events[1] = PAPI_TOT_CYC;
papi_events[2] = PAPI_RES_STL;
}
static void BeginProfile(){
if (PAPI_start_counters(papi_events, kPapiEventsNum) != PAPI_OK){
std::cerr << "PAPI start counters fail!" << std::endl;
exit(-1);
}
}
static void EndProfile(){
if (PAPI_stop_counters(papi_temp_values, kPapiEventsNum) != PAPI_OK){
std::cerr << "PAPI end counters fail!" << std::endl;
exit(-1);
}
for (size_t i = 0; i < kPapiEventsNum; ++i){
papi_values[i] += papi_temp_values[i];
}
}
static void ReportProfile(){
ReportProfile1();
}
static void ReportProfile1(){
std::cout << "L2_data_cache_miss " << papi_values[0] << " L2_data_cache_hit " << papi_values[1] << std::endl;
std::cout << "L2_data_cache_miss_rate " << papi_values[0] * 1.0 / (papi_values[0]+papi_values[1]) << std::endl;
std::cout << "L3_cache_miss " << papi_values[2] << " L3_cache_hit " << papi_values[3] << std::endl;
std::cout << "L3_cache_miss_rate " << papi_values[2] * 1.0 / (papi_values[2]+papi_values[3]) << std::endl;
}
static void ReportProfile2(){
std::cout << "total_instruction " << papi_values[0] << " total_cycles " << papi_values[1] << " resource_stall_cycles " << papi_values[2] << std::endl; \
std::cout << "instruction_per_cycle " << papi_values[0] * 1.0 / papi_values[1] << std::endl;\
std::cout << "percentage_resource_stall_cycles " << papi_values[2] * 1.0 / papi_values[1] << std::endl;
}
public:
static const size_t kPapiEventsNum = 4;
//const static kPapiEventsNum = 3;
static int papi_events[kPapiEventsNum];
static long_long papi_temp_values[kPapiEventsNum];
static long_long papi_values[kPapiEventsNum];
};
#endif
#endif