|
Packit |
577717 |
/*****************************************************************************
|
|
Packit |
577717 |
* PAPI_perror converts PAPI error codes to strings,it fills the string *
|
|
Packit |
577717 |
* destination with the error message corresponding to the error code. *
|
|
Packit |
577717 |
* The function copies length worth of the error description string *
|
|
Packit |
577717 |
* corresponding to code into destination. The resulting string is always *
|
|
Packit |
577717 |
* null terminated. If length is 0, then the string is printed on stderr. *
|
|
Packit |
577717 |
* PAPI_strerror does similar but it just returns the corresponding *
|
|
Packit |
577717 |
* error string from the code. *
|
|
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 |
|
|
Packit |
577717 |
int main()
|
|
Packit |
577717 |
{
|
|
Packit |
577717 |
|
|
Packit |
577717 |
int retval;
|
|
Packit |
577717 |
int EventSet = PAPI_NULL;
|
|
Packit |
577717 |
char error_str[PAPI_MAX_STR_LEN];
|
|
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 |
exit(1);
|
|
Packit |
577717 |
}
|
|
Packit |
577717 |
|
|
Packit |
577717 |
if ((retval = PAPI_create_eventset(&EventSet)) != PAPI_OK)
|
|
Packit |
577717 |
{
|
|
Packit |
577717 |
fprintf(stderr, "PAPI error %d: %s\n",retval,PAPI_strerror(retval));
|
|
Packit |
577717 |
exit(1);
|
|
Packit |
577717 |
}
|
|
Packit |
577717 |
|
|
Packit |
577717 |
/* Add Total Instructions Executed to our EventSet */
|
|
Packit |
577717 |
|
|
Packit |
577717 |
if ((retval = PAPI_add_event(EventSet, PAPI_TOT_INS)) != PAPI_OK)
|
|
Packit |
577717 |
{
|
|
Packit |
577717 |
PAPI_perror( "PAPI_add_event" );
|
|
Packit |
577717 |
exit(1);
|
|
Packit |
577717 |
}
|
|
Packit |
577717 |
|
|
Packit |
577717 |
/* Start counting */
|
|
Packit |
577717 |
|
|
Packit |
577717 |
if ((retval = PAPI_start(EventSet)) != PAPI_OK)
|
|
Packit |
577717 |
{
|
|
Packit |
577717 |
PAPI_perror( "PAPI_start" );
|
|
Packit |
577717 |
exit(1);
|
|
Packit |
577717 |
}
|
|
Packit |
577717 |
|
|
Packit |
577717 |
/* We are trying to start the counter which has already been started,
|
|
Packit |
577717 |
and this will give an error which will be passed to PAPI_perror via
|
|
Packit |
577717 |
retval and the function will then display the error string on the
|
|
Packit |
577717 |
screen.
|
|
Packit |
577717 |
*/
|
|
Packit |
577717 |
|
|
Packit |
577717 |
if ((retval = PAPI_start(EventSet)) != PAPI_OK)
|
|
Packit |
577717 |
{
|
|
Packit |
577717 |
PAPI_perror( "PAPI_start" );
|
|
Packit |
577717 |
}
|
|
Packit |
577717 |
|
|
Packit |
577717 |
/* The function PAPI_strerror returns the corresponding error string
|
|
Packit |
577717 |
from the error code */
|
|
Packit |
577717 |
if ((retval = PAPI_start(EventSet)) != PAPI_OK)
|
|
Packit |
577717 |
{
|
|
Packit |
577717 |
printf("%s\n",PAPI_strerror(retval));
|
|
Packit |
577717 |
}
|
|
Packit |
577717 |
|
|
Packit |
577717 |
/* finish using PAPI and free all related resources
|
|
Packit |
577717 |
(this is optional, you don't have to use it
|
|
Packit |
577717 |
*/
|
|
Packit |
577717 |
PAPI_shutdown ();
|
|
Packit |
577717 |
|
|
Packit |
577717 |
exit(0);
|
|
Packit |
577717 |
}
|