Created
May 16, 2017 03:04
-
-
Save kumagi/11b60087f068a1703ccb358cac3ed9a2 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <papi.h> | |
#include <stdio.h> | |
#include <iostream> | |
#include <vector> | |
int main() { | |
std::vector<int> Events = { | |
PAPI_BR_MSP, | |
PAPI_BR_NTK, | |
PAPI_TLB_IM | |
}; | |
std::vector<long long int> values(Events.size()); | |
if (PAPI_start_counters(Events.data(), Events.size()) != PAPI_OK) { | |
std::cout << "start_counter failed" << std::endl; | |
perror("start"); | |
return 1; | |
} | |
int sum = 0; | |
for (int i = 0; i < 10000; ++i) { | |
if (i % 10 == 0) { | |
sum += i * i; | |
} | |
} | |
if (PAPI_read_counters(values.data(), values.size()) != PAPI_OK) { | |
std::cout << "read counter failed" << std::endl; | |
return 1; | |
} | |
if (PAPI_stop_counters(values.data(), values.size()) != PAPI_OK) { | |
std::cout << "stop counter failed" << std::endl; | |
return 1; | |
}; | |
for (auto& v : values) { | |
std::cout << v << std::endl; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment