int main()
{
   int i,tmp=0;   
   int retval;
   const PAPI_exe_info_t *prginfo = NULL;

   /****************************************************************************
   *  This part initializes the library and compares the version number of the *
   * header file, to the version of the library, if these don't match then it  *
   * is likely that PAPI won't work correctly.If there is an error, retval     *
   * keeps track of the version number.                                        *
   ****************************************************************************/

   if((retval = PAPI_library_init(PAPI_VER_CURRENT)) != PAPI_VER_CURRENT )
   {
      printf("Library initialization error! \n");
      exit(1);
   }
    

   for(i=0;i<1000;i++)
      tmp=tmp+i;
    
   /* PAPI_get_executable_info returns a NULL if there is an error */    
   if ((prginfo = PAPI_get_executable_info()) == NULL)
   {
      printf("PAPI_get_executable_info error! \n");
      exit(1);
   }

  
   printf("Start text addess of user program is at %p\n",
              prginfo->address_info.text_start);
   printf("End text address of user program is at %p\n",
              prginfo->address_info.text_end);

   exit(0);
}
int
main( int argc, char **argv )
{
	pthread_t id[NUM_THREADS];
	int flops[NUM_THREADS];
	int i, rc, retval;
	pthread_attr_t attr;
	long long elapsed_us, elapsed_cyc;
	const PAPI_exe_info_t *prginfo = NULL;

	tests_quiet( argc, argv );	/* Set TESTS_QUIET variable */

	if ( ( retval =
		   PAPI_library_init( PAPI_VER_CURRENT ) ) != PAPI_VER_CURRENT )
		test_fail( __FILE__, __LINE__, "PAPI_library_init", retval );
	if ( ( retval =
		   PAPI_thread_init( ( unsigned
							   long ( * )( void ) ) ( pthread_self ) ) ) !=
		 PAPI_OK ) {
		if ( retval == PAPI_ECMP )
			test_skip( __FILE__, __LINE__, "PAPI_thread_init", retval );
		else
			test_fail( __FILE__, __LINE__, "PAPI_thread_init", retval );
	}
	if ( ( prginfo = PAPI_get_executable_info(  ) ) == NULL ) {
		retval = 1;
		test_fail( __FILE__, __LINE__, "PAPI_get_executable_info", retval );
	}
	my_start = prginfo->address_info.text_start;
	my_end = prginfo->address_info.text_end;
	length = ( unsigned int ) ( my_end - my_start );

	elapsed_us = PAPI_get_real_usec(  );

	elapsed_cyc = PAPI_get_real_cyc(  );

	pthread_attr_init( &attr );
#ifdef PTHREAD_CREATE_UNDETACHED
	pthread_attr_setdetachstate( &attr, PTHREAD_CREATE_UNDETACHED );
#endif
#ifdef PTHREAD_SCOPE_SYSTEM
	retval = pthread_attr_setscope( &attr, PTHREAD_SCOPE_SYSTEM );
	if ( retval != 0 )
		test_skip( __FILE__, __LINE__, "pthread_attr_setscope", retval );
#endif

	for ( i = 0; i < NUM_THREADS; i++ ) {
		flops[i] = FLOPS * ( i + 1 );
		rc = pthread_create( &id[i], &attr, Thread, ( void * ) &flops[i] );
		if ( rc )
			return ( FAILURE );
	}
	for ( i = 0; i < NUM_THREADS; i++ )
		pthread_join( id[i], NULL );

	pthread_attr_destroy( &attr );

	elapsed_cyc = PAPI_get_real_cyc(  ) - elapsed_cyc;

	elapsed_us = PAPI_get_real_usec(  ) - elapsed_us;

	if ( !TESTS_QUIET ) {
		printf( "Master real usec   : \t%lld\n", elapsed_us );
		printf( "Master real cycles : \t%lld\n", elapsed_cyc );
	}

	test_pass( __FILE__, NULL, 0 );
	pthread_exit( NULL );
	exit( 1 );
}
Beispiel #3
0
int
main( int argc, char **argv )
{
	int retval;
	const PAPI_exe_info_t *prginfo = NULL;
	const PAPI_hw_info_t *hw_info;

#if !defined(ITANIUM2) && !defined(ITANIUM3)
	test_skip( __FILE__, __LINE__, "Currently only works on itanium2", 0 );
	exit( 1 );
#endif

	tests_quiet( argc, argv );	/* Set TESTS_QUIET variable */

	init_array(  );
	printf( "Malloc'd array  pointers: %p   %p   %p\n", &parray1, &parray2,
			&parray3 );
	printf( "Malloc'd array addresses: %p   %p   %p\n", parray1, parray2,
			parray3 );
	printf( "Static   array addresses: %p   %p   %p\n", &array1, &array2,
			&array3 );

	tests_quiet( argc, argv );	/* Set TESTS_QUIET variable */

	if ( ( retval =
		   PAPI_library_init( PAPI_VER_CURRENT ) ) != PAPI_VER_CURRENT )
		test_fail( __FILE__, __LINE__, "PAPI_library_init", retval );

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

	if ( ( prginfo = PAPI_get_executable_info(  ) ) == NULL )
		test_fail( __FILE__, __LINE__, "PAPI_get_executable_info", 1 );

#if defined(linux) && defined(__ia64__)
	sprintf( event_name[0], "loads_retired" );
	sprintf( event_name[1], "stores_retired" );
	PAPI_event_name_to_code( event_name[0], &PAPI_event[0] );
	PAPI_event_name_to_code( event_name[1], &PAPI_event[1] );
#else
	test_fail( __FILE__, __LINE__, "only works for Itanium", PAPI_ESBSTR );
#endif

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

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

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

/***************************************************************************************/
	printf
		( "\n\nMeasure loads and stores on the pointers to the allocated arrays\n" );
	printf( "Expected loads: %d; Expected stores: 0\n", NUM * 2 );
	printf
		( "These loads result from accessing the pointers to compute array addresses.\n" );
	printf
		( "They will likely disappear with higher levels of optimization.\n" );

	measure_load_store( ( caddr_t ) & parray1, ( caddr_t ) ( &parray1 + 1 ) );
	measure_load_store( ( caddr_t ) & parray2, ( caddr_t ) ( &parray2 + 1 ) );
	measure_load_store( ( caddr_t ) & parray3, ( caddr_t ) ( &parray3 + 1 ) );
/***************************************************************************************/
	printf
		( "\n\nMeasure loads and stores on the allocated arrays themselves\n" );
	printf( "Expected loads: %d; Expected stores: %d\n", NUM, NUM );

	measure_load_store( ( caddr_t ) parray1, ( caddr_t ) ( parray1 + NUM ) );
	measure_load_store( ( caddr_t ) parray2, ( caddr_t ) ( parray2 + NUM ) );
	measure_load_store( ( caddr_t ) parray3, ( caddr_t ) ( parray3 + NUM ) );
/***************************************************************************************/
	printf( "\n\nMeasure loads and stores on the static arrays\n" );
	printf
		( "These values will differ from the expected values by the size of the offsets.\n" );
	printf( "Expected loads: %d; Expected stores: %d\n", NUM, NUM );

	measure_load_store( ( caddr_t ) array1, ( caddr_t ) ( array1 + NUM ) );
	measure_load_store( ( caddr_t ) array2, ( caddr_t ) ( array2 + NUM ) );
	measure_load_store( ( caddr_t ) array3, ( caddr_t ) ( array3 + NUM ) );
/***************************************************************************************/

	retval = PAPI_destroy_eventset( &EventSet );
	if ( retval != PAPI_OK )
		test_fail( __FILE__, __LINE__, "PAPI_destroy", retval );

	free( parray1 );
	free( parray2 );
	free( parray3 );

	test_pass( __FILE__, NULL, 0 );

	exit( 1 );
}
int main()
{

    unsigned long length;
    caddr_t start, end;
    PAPI_sprofil_t * prof; 
    int EventSet = PAPI_NULL;
    /*must be initialized to PAPI_NULL before calling PAPI_create_event*/
    int PAPI_event,i,tmp = 0;
    char event_name[PAPI_MAX_STR_LEN];
    /*These are going to be used as buffers */
    unsigned short *profbuf;
    long long values[2];
    const PAPI_exe_info_t *prginfo = NULL;


    int retval;
    

   /****************************************************************************
   *  This part initializes the library and compares the version number of the *
   * header file, to the version of the library, if these don't match then it  *
   * is likely that PAPI won't work correctly.If there is an error, retval     *
   * keeps track of the version number.                                        *
   ****************************************************************************/
    
   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)
   {  
      fprintf(stderr, "Error in get executable information \n");
      exit(1);
   }

   start = prginfo->address_info.text_start;
   end = prginfo->address_info.text_end;
   length = (end - start);

   /* for PAPI_PROFIL_BUCKET_16 and scale = 65536, 
      profile buffer length == program address length.
      Larger bucket sizes would increase the buffer length.
      Smaller scale factors would decrease it.
      Handle with care...
   */
   profbuf = (unsigned short *)malloc(length);
   if (profbuf == NULL)
   {
      fprintf(stderr, "Not enough memory \n");
      exit(1);
   }
   memset(profbuf,0x00,length);

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

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

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

   /* enable the collection of profiling information */
   if ((retval = PAPI_profil(profbuf, length, start, 65536, EventSet,
            PAPI_event, THRESHOLD, PAPI_PROFIL_POSIX | PAPI_PROFIL_BUCKET_16)) != PAPI_OK)
      ERROR_RETURN(retval);
   
   /* let's rock and roll */
   if ((retval=PAPI_start(EventSet)) != PAPI_OK)
      ERROR_RETURN(retval);

   code_to_monitor();
  
   if ((retval=PAPI_stop(EventSet, values)) != PAPI_OK)
      ERROR_RETURN(retval);

   /* disable the collection of profiling information by setting threshold
      to 0
   */
   if ((retval = PAPI_profil(profbuf, length, start, 65536, EventSet,
            PAPI_event, 0, PAPI_PROFIL_POSIX)) != PAPI_OK)
      ERROR_RETURN(retval);
   
   printf("-----------------------------------------------------------\n");
   printf("Text start: %p, Text end: %p, \n",   
            prginfo->address_info.text_start,prginfo->address_info.text_end);
   printf("Data start: %p, Data end: %p\n",
            prginfo->address_info.data_start,prginfo->address_info.data_end);
   printf("BSS start : %p, BSS end: %p\n",
            prginfo->address_info.bss_start,prginfo->address_info.bss_end);
    
   printf("------------------------------------------\n");
        
   printf("Test type   : \tPAPI_PROFIL_POSIX\n");
   printf("------------------------------------------\n\n\n");  
   printf("PAPI_profil() hash table.\n");
   printf("address\t\tflat   \n");
   for (i = 0; i < (int) length/2; i++) 
   {
      if (profbuf[i]) 
         printf("0x%lx\t%d \n",
               (unsigned long) start + (unsigned long) (2 * i), profbuf[i]);
   }

   printf("-----------------------------------------\n");

   retval = 0;
   for (i = 0; i < (int) length/2; i++)
      retval = retval || (profbuf[i]); 
   if (retval)
      printf("Test succeeds! \n");
   else
      printf( "No information in buffers\n");
   /* clean up */
   PAPI_shutdown();

   exit(0);
}
Beispiel #5
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);
}