int main(int argc, char **argv)
{
   int i, num_events, num_tests = 6, mask = 0x1;
   int EventSet = PAPI_NULL;
   unsigned short **buf = (unsigned short **)profbuf;
   unsigned long length, blength;
   int num_buckets;
   PAPI_sprofil_t sprof[3];
   int retval;
   const PAPI_hw_info_t *hw_info;
   const PAPI_exe_info_t *prginfo;
   caddr_t start, end;

   prof_init(argc, argv, &hw_info, &prginfo);

   start = prginfo->address_info.text_start;
   end = prginfo->address_info.text_end;
   if (start > end)
      test_fail(__FILE__, __LINE__, "Profile length < 0!", PAPI_ESBSTR);
   length = end - start;
   prof_print_address("Test case sprofile: POSIX compatible profiling over multiple regions.\n",prginfo);
   blength = prof_size(length, FULL_SCALE, PAPI_PROFIL_BUCKET_16, &num_buckets);
   prof_alloc(3, blength);

   /* First half */
   sprof[0].pr_base = buf[0];
   sprof[0].pr_size = blength;
   sprof[0].pr_off = (caddr_t) DO_FLOPS;
#if defined(linux) && defined(__ia64__)
   if (!TESTS_QUIET)
      fprintf(stderr, "do_flops is at %p %p\n", &do_flops, sprof[0].pr_off);
#endif
   sprof[0].pr_scale = FULL_SCALE;
   /* Second half */
   sprof[1].pr_base = buf[1];
   sprof[1].pr_size = blength;
   sprof[1].pr_off = (caddr_t) DO_READS;
#if defined(linux) && defined(__ia64__)
   if (!TESTS_QUIET)
      fprintf(stderr, "do_reads is at %p %p\n", &do_reads, sprof[1].pr_off);
#endif
   sprof[1].pr_scale = FULL_SCALE;
   /* Overflow bin */
   sprof[2].pr_base = buf[2];
   sprof[2].pr_size = 1;
   sprof[2].pr_off = 0;
   sprof[2].pr_scale = 0x2;

   EventSet = add_test_events(&num_events, &mask);

   values = allocate_test_space(num_tests, num_events);

   if ((retval = PAPI_sprofil(sprof, 3, EventSet, PAPI_TOT_CYC, THRESHOLD,
                              PAPI_PROFIL_POSIX | PAPI_PROFIL_BUCKET_16)) != PAPI_OK)
      test_fail(__FILE__, __LINE__, "PAPI_sprofil", retval);

   do_stuff();

   if ((retval = PAPI_start(EventSet)) != PAPI_OK)
      test_fail(__FILE__, __LINE__, "PAPI_start", retval);

   do_stuff();

   if ((retval = PAPI_stop(EventSet, values[1])) != PAPI_OK)
      test_fail(__FILE__, __LINE__, "PAPI_stop", retval);

   /* clear the profile flag before removing the event */
   if ((retval = PAPI_sprofil(sprof, 3, EventSet, PAPI_TOT_CYC, 0,
                              PAPI_PROFIL_POSIX | PAPI_PROFIL_BUCKET_16)) != PAPI_OK)
      test_fail(__FILE__, __LINE__, "PAPI_sprofil", retval);

   remove_test_events(&EventSet, mask);



   if (!TESTS_QUIET) {
      printf("Test case: PAPI_sprofil()\n");
      printf("---------Buffer 1--------\n");
      for (i = 0; i < length / 2; i++) {
         if (buf[0][i])
            printf("0x%lx\t%d\n", DO_FLOPS + 2 * i, buf[0][i]);
      }
      printf("---------Buffer 2--------\n");
      for (i = 0; i < length / 2; i++) {
         if (buf[1][i])
            printf("0x%lx\t%d\n", DO_READS + 2 * i, buf[1][i]);
      }
      printf("-------------------------\n");
      printf("%u samples fell outside the regions.\n", *buf[2]);
   }
   retval = prof_check(2, PAPI_PROFIL_BUCKET_16, num_buckets);

   for (i=0;i<3;i++) {
      free(profbuf[i]);
   }
   if (retval == 0)
      test_fail(__FILE__, __LINE__, "No information in buffers", 1);

   test_pass(__FILE__, values, num_tests);

   exit(1);
}
Exemple #2
0
int main(int argc, char **argv)
{
   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;

   /* initializaion */
   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));

   /* First half */
   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;  /* constant needed by PAPI_sprofil */
   /* Second half */
   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; /* constant needed by PAPI_sprofil */

   /* Overflow bin */
   sprof[2].pr_base = profbuf3;
   sprof[2].pr_size = 1;
   sprof[2].pr_off = 0;
   sprof[2].pr_scale = 0x2;  /* constant needed by PAPI_sprofil */

   /* Creating the eventset */
   if ( (retval = PAPI_create_eventset(&EventSet)) != PAPI_OK)
      ERROR_RETURN(retval);

   PAPI_event = PAPI_TOT_CYC;
   /* Add Total Instructions Executed to our EventSet */
   if ( (retval = PAPI_add_event(EventSet, PAPI_event)) != PAPI_OK)
      ERROR_RETURN(retval);

   /* Add Total Instructions Executed to our EventSet */
   if ( (retval = PAPI_add_event(EventSet, PAPI_TOT_INS)) != PAPI_OK)
      ERROR_RETURN(retval);

   /* set profile flag */
   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);

   /* to clear the profile flag before removing the events */
   if ((retval = PAPI_sprofil(sprof, 3, EventSet, PAPI_event, 0,
                              PAPI_PROFIL_POSIX)) != PAPI_OK)
      ERROR_RETURN(retval);

   /* free the resources hold by PAPI */
   PAPI_shutdown();

   printf("Test case: PAPI_sprofil()\n");
   printf("---------Buffer 1--------\n");
   for (i = 0; i < length / 2; i++) 
   {
      if (profbuf[i])
	printf("%#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("%#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);
}