{
int i , PAPI_event;
int EventSet = PAPI_NULL;
unsigned short *profbuf;
unsigned short *profbuf2;
unsigned short *profbuf3;
unsigned long length;
caddr_t start, end;
long long values[2];
const PAPI_exe_info_t *prginfo = NULL;
PAPI_sprofil_t sprof[3];
int retval;
if ((retval = PAPI_library_init(PAPI_VER_CURRENT)) != PAPI_VER_CURRENT)
{
printf("Library initialization error! \n");
exit(1);
}
if ((prginfo = PAPI_get_executable_info()) == NULL)
ERROR_RETURN(1);
start = prginfo->address_info.text_start;
end = prginfo->address_info.text_end;
length = (end - start)/sizeof(unsigned short) * sizeof(unsigned short);
printf("start= %p end =%p \n", start, end);
profbuf = (unsigned short *) malloc(length);
if (profbuf == NULL)
ERROR_RETURN(PAPI_ESYS);
memset(profbuf, 0x00, length );
profbuf2 = (unsigned short *) malloc(length);
if (profbuf2 == NULL)
ERROR_RETURN(PAPI_ESYS);
memset(profbuf2, 0x00, length );
profbuf3 = (unsigned short *) malloc(1 * sizeof(unsigned short));
if (profbuf3 == NULL)
ERROR_RETURN(PAPI_ESYS);
memset(profbuf3, 0x00, 1 * sizeof(unsigned short));
sprof[0].pr_base = profbuf;
sprof[0].pr_size = length / 2;
sprof[0].pr_off = DO_FLOPS2;
fprintf(stderr, "do_flops is at %p %lx\n", &do_flops2, strtoul(sprof[0].pr_off,NULL,0));
sprof[0].pr_scale = 65536;
sprof[1].pr_base = profbuf2;
sprof[1].pr_size = length / 2;
sprof[1].pr_off = DO_FLOPS1;
fprintf(stderr, "do_flops1 is at %p %lx\n", &do_flops1, strtoul(sprof[1].pr_off,NULL,0));
sprof[1].pr_scale = 65536;
sprof[2].pr_base = profbuf3;
sprof[2].pr_size = 1;
sprof[2].pr_off = 0;
sprof[2].pr_scale = 0x2;
if ( (retval = PAPI_create_eventset(&EventSet)) != PAPI_OK)
ERROR_RETURN(retval);
PAPI_event = PAPI_TOT_CYC;
if ( (retval = PAPI_add_event(EventSet, PAPI_event)) != PAPI_OK)
ERROR_RETURN(retval);
if ( (retval = PAPI_add_event(EventSet, PAPI_TOT_INS)) != PAPI_OK)
ERROR_RETURN(retval);
if ((retval = PAPI_sprofil(sprof, 3, EventSet, PAPI_event, THRESHOLD,
PAPI_PROFIL_POSIX)) != PAPI_OK)
ERROR_RETURN(retval);
if ((retval = PAPI_start(EventSet)) != PAPI_OK)
ERROR_RETURN(retval);
do_both(NUM_ITERS);
if ((retval = PAPI_stop(EventSet, values)) != PAPI_OK)
ERROR_RETURN(retval);
if ((retval = PAPI_sprofil(sprof, 3, EventSet, PAPI_event, 0,
PAPI_PROFIL_POSIX)) != PAPI_OK)
ERROR_RETURN(retval);
PAPI_shutdown();
printf("Test case: PAPI_sprofil()\n");
printf("---------Buffer 1--------\n");
for (i = 0; i < length / 2; i++)
{
if (profbuf[i])
printf("0x%lx\t%d\n", strtoul(DO_FLOPS2,NULL,0) + 2 * i, profbuf[i]);
}
printf("---------Buffer 2--------\n");
for (i = 0; i < length / 2; i++)
{
if (profbuf2[i])
printf("0x%lx\t%d\n", strtoul(DO_FLOPS1,NULL,0) + 2 * i, profbuf2[i]);
}
printf("-------------------------\n");
printf("%u samples fell outside the regions.\n", *profbuf3);
exit(0);
}