|
Packit |
577717 |
/*****************************************************************************
|
|
Packit |
577717 |
* We use PAPI_state to get the counting state of an EventSet.This function *
|
|
Packit |
577717 |
* returns the state of the entire EventSet. *
|
|
Packit |
577717 |
*****************************************************************************/
|
|
Packit |
577717 |
|
|
Packit |
577717 |
|
|
Packit |
577717 |
|
|
Packit |
577717 |
#include <stdio.h>
|
|
Packit |
577717 |
#include <stdlib.h>
|
|
Packit |
577717 |
#include "papi.h" /* This needs to be included every time you use PAPI */
|
|
Packit |
577717 |
|
|
Packit |
577717 |
#define ERROR_RETURN(retval) { fprintf(stderr, "Error %d %s:line %d: \n", retval,__FILE__,__LINE__); exit(retval); }
|
|
Packit |
577717 |
|
|
Packit |
577717 |
|
|
Packit |
577717 |
int main()
|
|
Packit |
577717 |
{
|
|
Packit |
577717 |
|
|
Packit |
577717 |
int retval;
|
|
Packit |
577717 |
int status = 0;
|
|
Packit |
577717 |
int EventSet = PAPI_NULL;
|
|
Packit |
577717 |
|
|
Packit |
577717 |
/****************************************************************************
|
|
Packit |
577717 |
* This part initializes the library and compares the version number of the *
|
|
Packit |
577717 |
* header file, to the version of the library, if these don't match then it *
|
|
Packit |
577717 |
* is likely that PAPI won't work correctly.If there is an error, retval *
|
|
Packit |
577717 |
* keeps track of the version number. *
|
|
Packit |
577717 |
****************************************************************************/
|
|
Packit |
577717 |
|
|
Packit |
577717 |
if((retval = PAPI_library_init(PAPI_VER_CURRENT)) != PAPI_VER_CURRENT )
|
|
Packit |
577717 |
{
|
|
Packit |
577717 |
printf("Library initialization error! \n");
|
|
Packit |
577717 |
exit(-1);
|
|
Packit |
577717 |
}
|
|
Packit |
577717 |
|
|
Packit |
577717 |
/*Creating the Eventset */
|
|
Packit |
577717 |
if((retval = PAPI_create_eventset(&EventSet)) != PAPI_OK)
|
|
Packit |
577717 |
ERROR_RETURN(retval);
|
|
Packit |
577717 |
|
|
Packit |
577717 |
/* Add Total Instructions Executed to our EventSet */
|
|
Packit |
577717 |
if ((retval=PAPI_add_event(EventSet, PAPI_TOT_INS)) != PAPI_OK)
|
|
Packit |
577717 |
ERROR_RETURN(retval);
|
|
Packit |
577717 |
|
|
Packit |
577717 |
if ((retval=PAPI_state(EventSet, &status)) != PAPI_OK)
|
|
Packit |
577717 |
ERROR_RETURN(retval);
|
|
Packit |
577717 |
|
|
Packit |
577717 |
printstate(status);
|
|
Packit |
577717 |
|
|
Packit |
577717 |
/* Start counting */
|
|
Packit |
577717 |
if ((retval=PAPI_start(EventSet)) != PAPI_OK)
|
|
Packit |
577717 |
ERROR_RETURN(retval);
|
|
Packit |
577717 |
|
|
Packit |
577717 |
if (PAPI_state(EventSet, &status) != PAPI_OK)
|
|
Packit |
577717 |
ERROR_RETURN(retval);
|
|
Packit |
577717 |
|
|
Packit |
577717 |
printstate(status);
|
|
Packit |
577717 |
|
|
Packit |
577717 |
/* free the resources used by PAPI */
|
|
Packit |
577717 |
PAPI_shutdown();
|
|
Packit |
577717 |
|
|
Packit |
577717 |
exit(0);
|
|
Packit |
577717 |
}
|
|
Packit |
577717 |
|
|
Packit |
577717 |
int printstate(int status)
|
|
Packit |
577717 |
{
|
|
Packit |
577717 |
if(status & PAPI_STOPPED)
|
|
Packit |
577717 |
printf("Eventset is currently stopped or inactive \n");
|
|
Packit |
577717 |
if(status & PAPI_RUNNING)
|
|
Packit |
577717 |
printf("Eventset is currently running \n");
|
|
Packit |
577717 |
if(status & PAPI_PAUSED)
|
|
Packit |
577717 |
printf("Eventset is currently Paused \n");
|
|
Packit |
577717 |
if(status & PAPI_NOT_INIT)
|
|
Packit |
577717 |
printf(" Eventset defined but not initialized \n");
|
|
Packit |
577717 |
if(status & PAPI_OVERFLOWING)
|
|
Packit |
577717 |
printf(" Eventset has overflowing enabled \n");
|
|
Packit |
577717 |
if(status & PAPI_PROFILING)
|
|
Packit |
577717 |
printf(" Eventset has profiling enabled \n");
|
|
Packit |
577717 |
if(status & PAPI_MULTIPLEXING)
|
|
Packit |
577717 |
printf(" Eventset has multiplexing enabled \n");
|
|
Packit |
577717 |
return 0;
|
|
Packit |
577717 |
}
|