void dump_avail(char * (*get_avail(unsigned *)))
{
  unsigned n_avail, i;
  char *ptr, ** avail = get_avail(&n_avail);
  int eventcode = PAPI_NULL, retval;
  PAPI_event_info_t info;

  for(i=0;i<n_avail;i++){
    if(get_avail == get_native_avail_papi_counters || get_avail == get_preset_avail_papi_counters){
      PAPI_event_name_to_code(avail[i],&eventcode);
      PAPI_get_event_info(eventcode, &info);
      printf("\t%s%*s, %s\n",info.symbol, (int)(40-strlen(info.symbol))," ", info.long_descr);
      
      if(get_avail == get_native_avail_papi_counters &&
	 PAPI_enum_event(&eventcode, PAPI_NTV_ENUM_UMASKS) == PAPI_OK){
	printf("\t\t%s%*s, %s\n","Masks", (int)(20-strlen("Masks"))," ", "Mask description");
	do{
	  retval = PAPI_get_event_info(eventcode, &info);
	  if (retval == PAPI_OK){
	    if(parse_unit_masks(&info)){
	      printf("\t\t%s%*s, %s\n",info.symbol, (int)(20-strlen(info.symbol))," ",info.long_descr);
	    }
	  }
	} while ( PAPI_enum_event( &eventcode, PAPI_NTV_ENUM_UMASKS) == PAPI_OK );
      }
    }
    else
      printf("%s\n",avail[i]);

    free(avail[i]);
  }
  free(avail);
}
示例#2
0
int
main( int argc, char **argv )
{
	int i, j = 0, k;
	int retval;
	PAPI_event_info_t info;
	const PAPI_hw_info_t *hwinfo = NULL;
	command_flags_t flags;
	int enum_modifier;
	int numcmp, cid;

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

	/* Initialize before parsing the input arguments */
	retval = PAPI_library_init( PAPI_VER_CURRENT );
	if ( retval != PAPI_VER_CURRENT ) {
		test_fail( __FILE__, __LINE__, "PAPI_library_init", retval );
	}

	/* Parse the command-line arguments */
	parse_args( argc, argv, &flags );

	/* Set enum modifier mask */
	if ( flags.dear )
		enum_modifier = PAPI_NTV_ENUM_DEAR;
	else if ( flags.darr )
		enum_modifier = PAPI_NTV_ENUM_DARR;
	else if ( flags.iear )
		enum_modifier = PAPI_NTV_ENUM_IEAR;
	else if ( flags.iarr )
		enum_modifier = PAPI_NTV_ENUM_IARR;
	else if ( flags.opcm )
		enum_modifier = PAPI_NTV_ENUM_OPCM;
	else
		enum_modifier = PAPI_ENUM_EVENTS;


	if ( !TESTS_QUIET ) {
	   retval = PAPI_set_debug( PAPI_VERB_ECONT );
	   if ( retval != PAPI_OK ) {
	      test_fail( __FILE__, __LINE__, "PAPI_set_debug", retval );
	   }
	}

	retval = papi_print_header( "Available native events and hardware information.\n", &hwinfo );
	if ( retval != PAPI_OK ) {
		test_fail( __FILE__, __LINE__, "PAPI_get_hardware_info", 2 );
	}


	/* Do this code if an event name was specified on the commandline */
	if ( flags.named ) {
	   if ( PAPI_event_name_to_code( flags.name, &i ) == PAPI_OK ) {
	      if ( PAPI_get_event_info( i, &info ) == PAPI_OK ) {
		 printf( "%-30s%s\n%-30s%d\n",
			 "Event name:", info.symbol,
			 "Number of Register Values:", info.count );
		 printf( "%-29s|%s|\n", "Description:", info.long_descr );
		 for ( k = 0; k < ( int ) info.count; k++ )
		     printf( " Register[%2d]:               |%s|\n", 
			     k, info.name[k] );

		     /* if unit masks exist but none specified, process all */
		     if ( !strchr( flags.name, ':' ) ) {
			if ( PAPI_enum_event( &i, PAPI_NTV_ENUM_UMASKS ) == PAPI_OK ) {
			   printf( "\nUnit Masks:\n" );
			   do {
			      retval = PAPI_get_event_info( i, &info );
			      if ( retval == PAPI_OK ) {
				 if ( parse_unit_masks( &info ) ) {
				    printf( "%-29s|%s|%s|\n", " Mask Info:",
					    info.symbol, info.long_descr );
				    for ( k = 0; k < ( int ) info.count; k++ )
					printf( "  Register[%2d]:  0x%08x  |%s|\n",
					       k, info.code[k], info.name[k] );
				 }
			      }
			   } while ( PAPI_enum_event( &i, PAPI_NTV_ENUM_UMASKS ) == PAPI_OK );
			}
		     }
	      }
	   } else {
	     printf("Sorry, an event by the name '%s' could not be found.\n",
		    flags.name);
	     printf("Is it typed correctly?\n\n");
	     exit( 1 );
	   }
	}
        else {

	   /* Print *ALL* available events */


	   numcmp = PAPI_num_components(  );

	   j = 0;

	   for ( cid = 0; cid < numcmp; cid++ ) {

	       const PAPI_component_info_t *component;
	       component=PAPI_get_component_info(cid);

	       /* Skip if requested enumeration not available */
	       if (( flags.dear ) && !( component->cntr_DEAR_events )) {
		 continue;
	       }
	       if (( flags.darr ) && !( component->data_address_range)) {
		 continue;
	       }
               if (( flags.iear ) && !( component->cntr_IEAR_events )) {
		 continue;
	       }
	       if (( flags.iarr ) && !( component->instr_address_range )) {
		 continue;
	       }
	       if (( flags.opcm ) && !( component->cntr_OPCM_events )) {
		 continue;
	       }


	       printf( "===============================================================================\n" );
	       printf( " Events in Component: %s\n",component->name);
	       printf( "===============================================================================\n" );
	     
	       /* Always ASK FOR the first event */
	       /* Don't just assume it'll be the first numeric value */
	       i = 0 | PAPI_NATIVE_MASK | PAPI_COMPONENT_MASK( cid );

	       /* UGH PAPI_enum_event() really needs a component field */
	       PAPI_enum_event( &i, PAPI_ENUM_FIRST );

	       do {
		  memset( &info, 0, sizeof ( info ) );
		  retval = PAPI_get_event_info( i, &info );

		  /* This event may not exist */
		  if ( retval != PAPI_OK )
		     continue;

		  /* count only events that as supported by host cpu */
		  j++;

		  print_event( &info, 0 );

		  /* Does this matter on anything but perfctr? */
		  if ( flags.details ) {
		     for ( k = 0; k < ( int ) info.count; k++ ) {
			 if ( strlen( info.name[k] ) ) {
			    printf( "  Register[%d] Name: %-20s  Value: 0x%-28x|\n",
				    k, info.name[k], info.code[k] );
			 }
		     }
		  }

/*		modifier = PAPI_NTV_ENUM_GROUPS returns event codes with a
			groups id for each group in which this
			native event lives, in bits 16 - 23 of event code
			terminating with PAPI_ENOEVNT at the end of the list.
*/

		  /* This is an IBM Power issue */
		  if ( flags.groups ) {
		     k = i;
		     if ( PAPI_enum_event( &k, PAPI_NTV_ENUM_GROUPS ) == PAPI_OK ) {
			printf( "Groups: " );
			do {
			  printf( "%4d", ( ( k & PAPI_NTV_GROUP_AND_MASK ) >>
					     PAPI_NTV_GROUP_SHIFT ) - 1 );
			} while ( PAPI_enum_event( &k, PAPI_NTV_ENUM_GROUPS ) ==PAPI_OK );
			printf( "\n" );
		     }
		  }

		  /* Print umasks */
		  /* components that don't have them can just ignore */

	          if ( flags.umask ) { 
		     k = i;
		     if ( PAPI_enum_event( &k, PAPI_NTV_ENUM_UMASKS ) == PAPI_OK ) {
		        do {
			   retval = PAPI_get_event_info( k, &info );
			   if ( retval == PAPI_OK ) {
			      if ( parse_unit_masks( &info ) )
			         print_event( &info, 2 );
			   }
		        } while ( PAPI_enum_event( &k, PAPI_NTV_ENUM_UMASKS ) == PAPI_OK );
		     }

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

	       } while ( PAPI_enum_event( &i, enum_modifier ) == PAPI_OK );
	   }