PAPI  5.0.1.0
event_chooser.c File Reference
Include dependency graph for event_chooser.c:

Go to the source code of this file.

Functions

static char * is_derived (PAPI_event_info_t *info)
static int add_remove_event (int EventSet, int evt)
static int show_event_info (int evt)
static int native (int cidx)
static int preset (void)
int main (int argc, char **argv)

Variables

int EventSet = PAPI_NULL
int retval

Function Documentation

static int add_remove_event ( int  EventSet,
int  evt 
) [static]

Definition at line 44 of file event_chooser.c.

{
    int retval;

    if ( ( retval = PAPI_add_event( EventSet, evt ) ) != PAPI_OK ) {
       //printf( "Error adding event.\n" );
    } else {
       if ( ( retval = PAPI_remove_event( EventSet, evt ) ) != PAPI_OK ) {
      printf( "Error removing event.\n" );
       }
    }
    return retval;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static char* is_derived ( PAPI_event_info_t info) [static]

Definition at line 31 of file event_chooser.c.

{
    if ( strlen( info->derived ) == 0 )
        return ( "No" );
    else if ( strcmp( info->derived, "NOT_DERIVED" ) == 0 )
        return ( "No" );
    else if ( strcmp( info->derived, "DERIVED_CMPD" ) == 0 )
        return ( "No" );
    else
        return ( "Yes" );
}

Here is the caller graph for this function:

int main ( int  argc,
char **  argv 
)

Definition at line 189 of file event_chooser.c.

{
    int i;
    int pevent,cevent;
    int cidx;

    const PAPI_hw_info_t *hwinfo = NULL;

    if ( argc < 3 ) {
       goto use_exit;
    }

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

    /* Init PAPI library */
    retval = PAPI_library_init( PAPI_VER_CURRENT );
    if ( retval != PAPI_VER_CURRENT ) {
       test_fail( __FILE__, __LINE__, "PAPI_library_init", retval );
    }

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

    retval = papi_print_header( "Event Chooser: Available events "
                "which can be added with given events.\n",
                        &hwinfo );
    if ( retval != PAPI_OK ) {
       test_fail( __FILE__, __LINE__, "PAPI_get_hardware_info", 2 );
    }

    retval = PAPI_create_eventset( &EventSet );
    if ( retval != PAPI_OK ) {
       fprintf( stderr, "PAPI_create_eventset error\n" );
       exit( 1 );
    }

    retval = PAPI_event_name_to_code( argv[2], &cevent );
    if ( retval != PAPI_OK ) {
       fprintf( stderr, "Event %s can't be found\n", argv[2] );
       exit( 1 );
    }
    cidx = PAPI_get_event_component(cevent);

    for( i = 2; i < argc; i++ ) {
       retval = PAPI_event_name_to_code( argv[i], &pevent );
       if ( retval != PAPI_OK ) {
      fprintf( stderr, "Event %s can't be found\n", argv[i] );
      exit( 1 );
       }
       retval = PAPI_add_event( EventSet, pevent );
       if ( retval != PAPI_OK ) {
      fprintf( stderr, "Event %s can't be counted with others %d\n",
           argv[i], retval );
      exit( 1 );
       }
    }

    if ( !strcmp( "NATIVE", argv[1] ) ) {
       native( cidx );
    }
    else if ( !strcmp( "PRESET", argv[1] ) ) {
       preset(  );
    }
    else {
       goto use_exit;
    }
    exit( 0 );
  
use_exit:
    fprintf( stderr,
        "Usage: papi_event_chooser NATIVE|PRESET evt1 evt2 ... \n" );
    exit( 1 );
}

Here is the call graph for this function:

static int native ( int  cidx) [static]

Definition at line 81 of file event_chooser.c.

{
    int i, j, k;
    int retval, added;
    PAPI_event_info_t info;

    j = 0;

    /* For platform independence, always ASK FOR the first event */
    /* Don't just assume it'll be the first numeric value */
    i = 0 | PAPI_NATIVE_MASK;
    retval=PAPI_enum_cmp_event( &i, PAPI_ENUM_FIRST, cidx );
    if (retval==PAPI_ENOEVNT) {
       printf("Cannot find first event in component %d\n",cidx);
    }

    do {
       k = i;

       if ( PAPI_enum_cmp_event( &k, PAPI_NTV_ENUM_UMASKS, cidx) == PAPI_OK ) {
      if ( ( added = add_remove_event( EventSet, k ) ) == PAPI_OK ) {
         show_event_info( i );
         do {
        retval = PAPI_get_event_info( k, &info );
        if ( retval == PAPI_OK ) {
           printf( "    0x%-10x%s  |%s|\n", info.event_code,
               strchr( info.symbol, ':' ),
               strchr( info.long_descr, ':' ) + 1 );
        }
         } while ( PAPI_enum_cmp_event( &k, PAPI_NTV_ENUM_UMASKS, cidx ) ==
                              PAPI_OK );
         j++;
      }
       } else {
      if ( ( added = add_remove_event( EventSet, i ) ) == PAPI_OK ) {
         show_event_info( i );
         j++;
      }
       }
    
       if ( added == PAPI_OK ) {
      /* 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.
       */
      k = i;
      if ( PAPI_enum_cmp_event( &k, PAPI_NTV_ENUM_GROUPS, cidx ) == PAPI_OK ) {
         printf( "Groups: " );
         do {
        printf( "%4d", ( ( k & PAPI_NTV_GROUP_AND_MASK ) >>
                      PAPI_NTV_GROUP_SHIFT ) - 1 );
         } while ( PAPI_enum_cmp_event( &k, PAPI_NTV_ENUM_GROUPS, cidx ) ==
                              PAPI_OK );
         printf( "\n" );
      }
      
      printf( "---------------------------------------------"
          "----------------------------\n" );
       }
    } while ( PAPI_enum_cmp_event( &i, PAPI_ENUM_EVENTS, cidx ) == PAPI_OK );

    printf( "------------------------------------------"
        "-------------------------------\n" );
    printf( "Total events reported: %d\n", j );
    test_pass( __FILE__, NULL, 0 );
    exit( 1 );
}

Here is the call graph for this function:

Here is the caller graph for this function:

static int preset ( void  ) [static]

Definition at line 151 of file event_chooser.c.

{
    int i, j = 0;
    int retval;
    PAPI_event_info_t info;

    printf( "    Name        Code    " );
    printf( "Deriv Description (Note)\n" );

    /* For consistency, always ASK FOR the first event */
    i = 0 | PAPI_PRESET_MASK;
    PAPI_enum_event( &i, PAPI_ENUM_FIRST );

    do {
        retval = PAPI_add_event( EventSet, i );
        if ( retval == PAPI_OK ) {
            if ( PAPI_get_event_info( i, &info ) == PAPI_OK ) {
                printf( "%-13s0x%x  %-5s%s",
                        info.symbol,
                        info.event_code, is_derived( &info ), info.long_descr );
                if ( info.note[0] )
                    printf( " (%s)", info.note );
                printf( "\n" );
            }
            if ( ( retval = PAPI_remove_event( EventSet, i ) ) != PAPI_OK )
                printf( "Error in PAPI_remove_event\n" );
            j++;
        }
    } while ( PAPI_enum_event( &i, PAPI_PRESET_ENUM_AVAIL ) == PAPI_OK );

    printf
        ( "-------------------------------------------------------------------------\n" );
    printf( "Total events reported: %d\n", j );
    test_pass( __FILE__, NULL, 0 );
    exit( 1 );
}

Here is the call graph for this function:

Here is the caller graph for this function:

static int show_event_info ( int  evt) [static]

Definition at line 59 of file event_chooser.c.

{
    int k;
    int retval;
    PAPI_event_info_t info;

    if ( ( retval = PAPI_get_event_info( evt, &info ) ) == PAPI_OK ) {
       printf( "%s\t0x%x\n |%s|\n",
           info.symbol, info.event_code, info.long_descr );

       for( k = 0; k < ( int ) info.count; k++ ) {
      if ( strlen( info.name[k] ) ) {
         printf( " |Register Value[%d]: 0x%-10x  %s|\n", 
                     k, info.code[k], info.name[k] );
      }
       }
    }
    return retval;
}

Here is the call graph for this function:

Here is the caller graph for this function:


Variable Documentation

Definition at line 27 of file event_chooser.c.

int retval

Definition at line 28 of file event_chooser.c.

 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Defines