Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
#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