Skip to content

Instantly share code, notes, and snippets.

@wrathematics
Created September 21, 2017 13:28
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 wrathematics/c6b374f3c466621c170cc4451f8c34c2 to your computer and use it in GitHub Desktop.
Save wrathematics/c6b374f3c466621c170cc4451f8c34c2 to your computer and use it in GitHub Desktop.
#include <stdio.h>
#include <papi.h>
#include <stdlib.h>
#define NUM_EVENTS 2
int main(int argc, char **argv)
{
int a = atoi(argv[1]);
int b = atoi(argv[2]);
int events[NUM_EVENTS] = {PAPI_L1_DCM, PAPI_L2_DCM};
long long values[NUM_EVENTS];
PAPI_library_init(PAPI_VER_CURRENT);
PAPI_start_counters(events, NUM_EVENTS);
printf("%d+%d=%d\n", a, b, a+b);
PAPI_read_counters(values, NUM_EVENTS);
PAPI_stop_counters(values, NUM_EVENTS);
for (int i=0; i<NUM_EVENTS; i++)
printf("L%d Cache Misses: %lld\n", i+1, values[i]);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment