int main(int argc, char **argv)
{
   int num_tests = 6;
   long length;
   int mask;
   int retval;
   int mythreshold=THRESHOLD;
   const PAPI_hw_info_t *hw_info;
   const PAPI_exe_info_t *prginfo;
   caddr_t start, end;

  prof_init(argc, argv, &hw_info, &prginfo);
  mask = prof_events(num_tests,hw_info);

#ifdef PROFILE_ALL
/* use these lines to profile entire code address space */
   start = prginfo->address_info.text_start;
   end = prginfo->address_info.text_end;
#else
/* use these lines to profile only do_flops address space */
   start = (caddr_t)do_flops;
   end = (caddr_t)fdo_flops;
/* Itanium and ppc64 processors return function descriptors instead of function addresses.
   You must dereference the descriptor to get the address.
*/
#if defined(ITANIUM1) || defined(ITANIUM2) || defined(__powerpc64__)
   start = (caddr_t)(((struct fdesc *)start)->ip);
   end = (caddr_t)(((struct fdesc *)end)->ip);
#endif
#endif

#if defined(linux)
     {
       char *tmp = getenv("THRESHOLD");
       if (tmp) 
	     mythreshold = atoi(tmp);
     }
#endif

   length = end - start;
   if (length < 0)
      test_fail(__FILE__, __LINE__, "Profile length < 0!", length);

   prof_print_address("Test case profile: POSIX compatible profiling with hardware counters.\n",prginfo);
   prof_print_prof_info(start,end,mythreshold,event_name);
   retval = do_profile(start, length, FULL_SCALE, mythreshold, PAPI_PROFIL_BUCKET_16);
   if (retval)
      retval = do_profile(start, length, FULL_SCALE, mythreshold, PAPI_PROFIL_BUCKET_32);
   if (retval)
      retval = do_profile(start, length, FULL_SCALE, mythreshold, PAPI_PROFIL_BUCKET_64);

   remove_test_events(&EventSet, mask);

   if (retval)
      test_pass(__FILE__, values, num_tests);
   else
      test_fail(__FILE__, __LINE__, "No information in buffers", 1);
   exit(1);
}
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);
}
示例#3
0
int
main( int argc, char **argv )
{
	long length;
	int mask;
	int retval;
	const PAPI_exe_info_t *prginfo;
	caddr_t start, end;

	prof_init( argc, argv, &prginfo );

	hw_info = PAPI_get_hardware_info(  );
        if ( hw_info == NULL )
	  test_fail( __FILE__, __LINE__, "PAPI_get_hardware_info", 2 );

       	mask = MASK_TOT_CYC | MASK_TOT_INS | MASK_FP_OPS | MASK_L2_TCM;

#if defined(__powerpc__)
	if ( strcmp( hw_info->model_string, "POWER6" ) == 0 )
		mask = MASK_TOT_CYC | MASK_FP_INS;
	else
		mask = MASK_TOT_CYC | MASK_TOT_INS | MASK_FP_INS;
#endif

#if defined(ITANIUM2)
	mask = MASK_TOT_CYC | MASK_FP_OPS | MASK_L2_TCM | MASK_L1_DCM;
#endif
	EventSet = add_test_events( &num_events, &mask, 0 );
	values = allocate_test_space( 1, num_events );

/* profile the cleara and my_main address space */
	start = ( caddr_t ) cleara;
	end = ( caddr_t ) my_dummy;

/* Itanium and PowerPC64 processors return function descriptors instead
 * of function addresses. You must dereference the descriptor to get the address.
*/
#if defined(ITANIUM1) || defined(ITANIUM2) || defined(__powerpc64__)
	start = ( caddr_t ) ( ( ( struct fdesc * ) start )->ip );
	end = ( caddr_t ) ( ( ( struct fdesc * ) end )->ip );
#endif

	/* call dummy so it doesn't get optimized away */
	retval = my_dummy( 1 );

	length = end - start;
	if ( length < 0 )
		test_fail( __FILE__, __LINE__, "Profile length < 0!", ( int ) length );

	prof_print_address
		( "Test case byte_profile: Multi-event profiling at byte resolution.\n",
		  prginfo );
	prof_print_prof_info( start, end, THRESHOLD, event_name );

	retval =
		do_profile( start, ( unsigned ) length, 
			    FULL_SCALE * 2, THRESHOLD,
			    PAPI_PROFIL_BUCKET_32, mask );

	remove_test_events( &EventSet, mask );

	if ( retval )
		test_pass( __FILE__, values, 1 );
	else
		test_fail( __FILE__, __LINE__, "No information in buffers", 1 );
	return 1;
}