PAPI  5.0.1.0
component.c
Go to the documentation of this file.
00001 
00025 #include "papi_test.h"
00026 
00027 #define EVT_LINE 80
00028 
00029 typedef struct command_flags
00030 {
00031     int help;
00032     int details;
00033     int named;
00034     char *name;
00035 } command_flags_t;
00036 
00037 static void
00038 print_help( char **argv )
00039 {
00040     printf( "This is the PAPI component avail program.\n" );
00041     printf( "It provides availability of installed PAPI components.\n" );
00042     printf( "Usage: %s [options]\n", argv[0] );
00043     printf( "Options:\n\n" );
00044     printf( "  --help, -h    print this help message\n" );
00045     printf( "  -d            print detailed information on each component\n" );
00046 }
00047 
00048 static void
00049 parse_args( int argc, char **argv, command_flags_t * f )
00050 {
00051     int i;
00052 
00053     /* Look for all currently defined commands */
00054     memset( f, 0, sizeof ( command_flags_t ) );
00055     for ( i = 1; i < argc; i++ ) {
00056         if ( !strcmp( argv[i], "-d" ) ) {
00057             f->details = 1;
00058         } else if ( strstr( argv[i], "-h" ) )
00059             f->help = 1;
00060         else
00061             printf( "%s is not supported\n", argv[i] );
00062     }
00063 
00064     /* if help requested, print and bail */
00065     if ( f->help ) {
00066         print_help( argv );
00067         exit( 1 );
00068     }
00069 
00070 }
00071 
00072 int
00073 main( int argc, char **argv )
00074 {
00075     int retval;
00076     const PAPI_hw_info_t *hwinfo = NULL;
00077     const PAPI_component_info_t* cmpinfo;
00078     command_flags_t flags;
00079     int numcmp, cid;
00080 
00081     tests_quiet( argc, argv );  /* Set TESTS_QUIET variable */
00082 
00083     /* Initialize before parsing the input arguments */
00084     retval = PAPI_library_init( PAPI_VER_CURRENT );
00085     if ( retval != PAPI_VER_CURRENT )
00086         test_fail( __FILE__, __LINE__, "PAPI_library_init", retval );
00087 
00088     parse_args( argc, argv, &flags );
00089 
00090     if ( !TESTS_QUIET ) {
00091         retval = PAPI_set_debug( PAPI_VERB_ECONT );
00092         if ( retval != PAPI_OK )
00093             test_fail( __FILE__, __LINE__, "PAPI_set_debug", retval );
00094     }
00095 
00096     retval =
00097         papi_print_header
00098         ( "Available components and hardware information.\n", &hwinfo );
00099     if ( retval != PAPI_OK )
00100         test_fail( __FILE__, __LINE__, "PAPI_get_hardware_info", 2 );
00101 
00102 
00103     /* Compiled-in Components */
00104     numcmp = PAPI_num_components(  );
00105 
00106     printf("Compiled-in components:\n");
00107     for ( cid = 0; cid < numcmp; cid++ ) {
00108       cmpinfo = PAPI_get_component_info( cid );
00109 
00110       printf( "Name:   %-23s %s\n", cmpinfo->name ,cmpinfo->description);
00111 
00112       if (cmpinfo->disabled) {
00113         printf("   \\-> Disabled: %s\n",cmpinfo->disabled_reason);
00114       }
00115 
00116       if ( flags.details ) {
00117         printf( "Version:\t\t\t%s\n", cmpinfo->version );
00118         printf( "Number of native events:\t%d\n", cmpinfo->num_native_events);
00119         printf( "Number of preset events:\t%d\n", cmpinfo->num_preset_events); 
00120         printf("\n");
00121       }
00122     }
00123 
00124     printf("\nActive components:\n");
00125     numcmp = PAPI_num_components(  );
00126 
00127     for ( cid = 0; cid < numcmp; cid++ ) {
00128       cmpinfo = PAPI_get_component_info( cid );
00129       if (cmpinfo->disabled) continue;
00130 
00131       printf( "Name:   %-23s %s\n", cmpinfo->name ,cmpinfo->description);
00132       printf( "        %-23s Native: %d, Preset: %d, Counters: %d\n\n", 
00133           " ", cmpinfo->num_native_events, cmpinfo->num_preset_events,
00134           cmpinfo->num_cntrs);
00135 
00136       if ( flags.details ) {
00137         printf( "Version:\t\t\t%s\n", cmpinfo->version );
00138         printf( "Number of native events:\t%d\n", cmpinfo->num_native_events);
00139         printf( "Number of preset events:\t%d\n", cmpinfo->num_preset_events); 
00140         printf("\n");
00141       }
00142     }
00143 
00144 
00145     printf
00146       ( "\n--------------------------------------------------------------------------------\n" );
00147     test_pass( __FILE__, NULL, 0 );
00148     exit( 0 );
00149 }
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Defines