-
Notifications
You must be signed in to change notification settings - Fork 2
/
PapiInstance.h
89 lines (71 loc) · 2.28 KB
/
PapiInstance.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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
#ifndef PAPI_INSTANCE_H
#define PAPI_INSTANCE_H
#include "papi.h"
#include <cassert>
#include <cstdio>
#include <iostream>
#include <map>
#include <memory>
#include <vector>
#include "Collector.h"
/**
* This class is the interface to take measurements using the PAPI performance
* counters.
* It let's you add an event you want to capture.
*
*/
class PapiInstance : public Collector {
public:
void addEvent(int event) __attribute__((no_instrument_function));
void start() __attribute__((no_instrument_function));
void stop() __attribute__((no_instrument_function));
void read() __attribute__((no_instrument_function));
void reset() __attribute__((no_instrument_function));
long long getEventValue(int event) __attribute__((no_instrument_function));
~PapiInstance();
private:
void mapValuesToMapEntries(const std::vector<long long> &vals)
__attribute__((no_instrument_function));
friend class Papi;
PapiInstance() __attribute((no_instrument_function));
PapiInstance(const PapiInstance &other) = delete;
PapiInstance operator=(const PapiInstance &other) = delete;
int eventSet;
std::vector<int> eventRegChain;
std::map<int, long long> eventValMap;
};
/**
* The class is used to obtain an instance of the PapiInstance class,
* which gives you access to the PAPI functionality itself.
*/
class Papi {
public:
Papi() __attribute__((no_instrument_function));
PapiInstance *create() __attribute__((no_instrument_function));
private:
std::unique_ptr<PapiInstance> instance;
};
static Papi papi;
extern "C" {
#ifdef _LIB_MONITOR_
#define CTOR_ATTRIBUTE __attribute__((no_instrument_function))
#define DTOR_ATTRIBUTE __attribute__((no_instrument_function))
#elif _NO_CTOR_ATTR
#define CTOR_ATTRIBUTE __attribute__((no_instrument_function))
#define DTOR_ATTRIBUTE __attribute__((no_instrument_function))
#else
#define CTOR_ATTRIBUTE __attribute__((constructor, no_instrument_function))
#define DTOR_ATTRIBUTE __attribute__((destructor, no_instrument_function))
#endif
/**
* These two functions are used in an LD_PRELOAD setting
*/
void PapiW_start() CTOR_ATTRIBUTE;
void PapiW_stopAndPrint() DTOR_ATTRIBUTE;
/** -------- */
#ifdef _LIB_MONITOR_
void *monitor_init_process(int *argc, char **argv, void *data);
void monitor_fini_process(int how, void *data);
#endif
}
#endif