int retval;
int EventSet = PAPI_NULL;
unsigned long start, end, length;
PAPI_exe_info_t *prginfo;
unsigned short *profbuf;
retval = PAPI_library_init(PAPI_VER_CURRENT);
if (retval != PAPI_VER_CURRENT & retval > 0) {
fprintf(stderr,"PAPI library version mismatch!0);
exit(1); }
if (retval < 0)
handle_error(retval);
if ((prginfo = PAPI_get_executable_info()) == NULL)
handle_error(1);
start = (unsigned long)prginfo->text_start;
end = (unsigned long)prginfo->text_end;
length = (end - start)/sizeof(unsigned short) *sizeof(unsigned short);
profbuf = (unsigned short *)malloc(length);
if (profbuf == NULL)
handle_error(1);
memset(profbuf,0x00,length);
if ((retval = PAPI_create_eventset(&EventSet)) != PAPI_OK)
handle_error(retval);
/* Add Total FP Instructions Executed to our EventSet */
if ((retval = PAPI_add_event(EventSet, PAPI_FP_INS)) != PAPI_OK)
handle_error(retval);
if ((retval = PAPI_profil(profbuf, length, start, 65536, EventSet,
PAPI_FP_INS, 1000000, PAPI_PROFIL_POSIX)) != PAPI_OK)
handle_error(retval);
/* Start counting */
if ((retval = PAPI_start(EventSet)) != PAPI_OK)
handle_error(1);