~
~
~
~
~
- //#include "papi.h"
-
#include "/home/zxx/papi-4.2.0/src/papi.h"
-
#include <stdlib.h>
-
#include <stdio.h>
-
-
int main() {
-
-
int EventSet;
-
int i, sum;
-
long_long values[1], values1[1], values2[1];
-
-
/* Initialize the PAPI library */
-
if (PAPI_library_init(PAPI_VER_CURRENT) != PAPI_VER_CURRENT)
-
exit(-1);
-
// exit(-1);
-
-
/* Create an EventSet */
-
EventSet = PAPI_NULL;
-
if (PAPI_create_eventset(&EventSet) != PAPI_OK)
-
exit(-1);
-
-
/* Add an event about Total Instructions Executed (PAPI_TOT_INS) to EventSet */
-
if (PAPI_add_event(EventSet, PAPI_TOT_INS) != PAPI_OK)
-
exit(-1);
-
-
/* Start counting events */
-
if (PAPI_start(EventSet) != PAPI_OK)
-
exit(-1);
-
-
/* Read counters before workload running*/
-
if (PAPI_read(EventSet, values1) != PAPI_OK)
-
exit(-1);
-
-
/* Do some computation here */
-
for (i=0;i<10000;i++)
-
sum+=i;
-
-
/* Stop counting events */
-
/* Stop counting events */
-
if (PAPI_stop(EventSet, values2) != PAPI_OK)
-
exit(-1);
-
-
-
/* Clean up EventSet */
-
if (PAPI_cleanup_eventset(EventSet) != PAPI_OK)
-
exit(-1);
-
-
/* Destroy the EventSet */
-
if (PAPI_destroy_eventset(&EventSet) != PAPI_OK)
-
exit(-1);
-
-
/* Shutdown PAPI */
-
PAPI_shutdown();
-
/* Get value */
-
// values[0] = values2[0] – values1[0];
-
values[0]=values2[0]-values1[0];
-
printf("%d\n",values[0]);
-
return 0;
-
}
- ~
~
~