6#if defined(__cplusplus) && defined(PERF_COUNTERS)
14#include "cpucounters.h"
20static PCM * pcmInstance;
23static CoreCounterState before_state;
24static CoreCounterState after_state;
26static SocketCounterState before_state;
27static SocketCounterState after_state;
29static SystemCounterState before_state;
30static SystemCounterState after_state;
36static PCM::CustomCoreEventDescription MyEvents[4];
37static std::string MyEventNames[4];
40static double eventAcc[12] = {0.0};
50mystrdup (
const char *s)
52 char *ss = (
char*) malloc (strlen (s) + 1);
55 memcpy (ss, s, strlen(s) + 1);
63 PCM * m = PCM::getInstance();
64 PCM::ErrorCode status;
94 while (!inpf.eof() && numEvents < 4) {
95 inpf >> MyEventNames[numEvents]
96 >> hex >> MyEvents[numEvents].event_number
97 >> hex >> MyEvents[numEvents].umask_value;
102 if (pcmInstance->good())
103 status = pcmInstance->program(PCM::CUSTOM_CORE_EVENTS, MyEvents);
106 status = pcmInstance->program();
113 case PCM::MSRAccessDenied:
114 cout <<
"Access to Intel(r) Performance Counter Monitor has denied "
115 <<
"(no MSR or PCI CFG space access)." << endl;
118 cout <<
"Access to Intel(r) Performance Counter Monitor has denied "
119 <<
"(Performance Monitoring Unit is occupied by other application)."
120 <<
"Try to stop the application that uses PMU." << endl;
121 cout <<
"Alternatively you can try to reset PMU configuration at your"
122 <<
" own risk. Try to reset? (y/n)" << endl;
128 cout <<
"PMU configuration has been reset. Try to rerun the "
129 <<
"program again." << endl;
133 cout <<
"Access to Intel(r) Performance Counter Monitor has denied "
134 <<
"(Unknown error)." << endl;
144 before_state = getCoreCounterState(0);
146 before_state = getSocketCounterState(0);
148 before_state = getSystemCounterState();
156 after_state = getCoreCounterState(0);
158 after_state = getSocketCounterState(0);
160 after_state = getSystemCounterState();
178 (*out) <<
"Instructions-retired "
179 << getInstructionsRetired(before_state, after_state) << endl;
180 (*out) <<
"Active-cycles "
181 << getCycles(before_state, after_state) << endl;
183 << getIPC(before_state, after_state) << endl;
186 (*out) <<
"L2Misses "
187 << getL2CacheMisses(before_state, after_state) << endl;
188 (*out) <<
"L3Misses "
189 << getL3CacheMisses(before_state, after_state) << endl;
190 (*out) <<
"L2HitRatio "
191 << getL2CacheHitRatio(before_state, after_state) << endl;
192 (*out) <<
"L3HitRatio "
193 << getL3CacheHitRatio(before_state, after_state) << endl;
195 (*out) <<
"CyclesLostDueL2CacheMisses "
196 << getCyclesLostDueL2CacheMisses(before_state, after_state) << endl;
197 (*out) <<
"CyclesLostDueL3CacheMisses "
198 << getCyclesLostDueL3CacheMisses(before_state, after_state) << endl;
200 (*out) <<
"BytesFromMC " << getBytesReadFromMC(before_state, after_state) << endl;
201 (*out) <<
"BytesWrittenToMC " << getBytesWrittenToMC(before_state, after_state) << endl;
205 for(
int i = 0; i < numEvents; i++) {
206 (*out) << MyEventNames[i] <<
" "
207 << getNumberOfCustomEvents(i, before_state, after_state)
219 eventAcc[0] += getInstructionsRetired(before_state, after_state);
221 eventAcc[1] += getCycles(before_state, after_state);
223 eventAcc[2] += getIPC(before_state, after_state);
227 eventAcc[3] += getL2CacheMisses(before_state, after_state);
229 eventAcc[4] += getL3CacheMisses(before_state, after_state);
231 eventAcc[5] += getL2CacheHitRatio(before_state, after_state);
233 eventAcc[6] += getL3CacheHitRatio(before_state, after_state);
236 eventAcc[7] += getCyclesLostDueL2CacheMisses(before_state, after_state);
238 eventAcc[8] += getCyclesLostDueL3CacheMisses(before_state, after_state);
242 eventAcc[9] += getBytesReadFromMC(before_state, after_state);
244 eventAcc[10] += getBytesWrittenToMC(before_state, after_state);
248 for(
int i = 0; i < numEvents; i++) {
250 eventAcc[i+3] = getNumberOfCustomEvents(i, before_state, after_state);
268 (*out) <<
"Instructions-retired " << eventAcc[0] << endl;
269 (*out) <<
"Active-cycles " << eventAcc[1] << endl;
270 (*out) <<
"IPC " << eventAcc[2] << endl;
273 (*out) <<
"L2Misses " << eventAcc[3] << endl;
274 (*out) <<
"L3Misses " << eventAcc[4] << endl;
275 (*out) <<
"L2HitRatio "<< eventAcc[5] << endl;
276 (*out) <<
"L3HitRatio "<< eventAcc[6] << endl;
278 (*out) <<
"CyclesLostDueL2CacheMisses "
279 << eventAcc[7] << endl;
280 (*out) <<
"CyclesLostDueL3CacheMisses "
281 << eventAcc[8] << endl;
283 (*out) <<
"BytesFromMC " << eventAcc[9] << endl;
284 (*out) <<
"BytesWrittenToMC " << eventAcc[10] << endl;
287 for(
int i = 0; i < numEvents; i++) {
288 (*out) << MyEventNames[i] <<
" " << eventAcc[i+3] << endl;
298 pcmInstance->cleanup();
321 (*out) << msg << std::endl;
An interface to the Intel Performance Counters Monitoring.