Skip to content

Instantly share code, notes, and snippets.

@kumagi
Created May 16, 2017 03:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kumagi/11b60087f068a1703ccb358cac3ed9a2 to your computer and use it in GitHub Desktop.
Save kumagi/11b60087f068a1703ccb358cac3ed9a2 to your computer and use it in GitHub Desktop.
#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