|
PAPI
5.0.1.0
|
00001 00031 #include "papi_test.h" 00032 extern int TESTS_QUIET; /* Declared in test_utils.c */ 00033 00034 static char * 00035 is_derived( PAPI_event_info_t * info ) 00036 { 00037 if ( strlen( info->derived ) == 0 ) 00038 return ( "No" ); 00039 else if ( strcmp( info->derived, "NOT_DERIVED" ) == 0 ) 00040 return ( "No" ); 00041 else if ( strcmp( info->derived, "DERIVED_CMPD" ) == 0 ) 00042 return ( "No" ); 00043 else 00044 return ( "Yes" ); 00045 } 00046 00047 static void 00048 print_help( char **argv ) 00049 { 00050 printf( "Usage: %s [options]\n", argv[0] ); 00051 printf( "Options:\n\n" ); 00052 printf( "General command options:\n" ); 00053 printf( "\t-a, --avail Display only available preset events\n" ); 00054 printf 00055 ( "\t-d, --detail Display detailed information about all preset events\n" ); 00056 printf 00057 ( "\t-e EVENTNAME Display detail information about specified preset or native event\n" ); 00058 printf( "\t-h, --help Print this help message\n" ); 00059 printf( "\nEvent filtering options:\n" ); 00060 printf( "\t--br Display branch related PAPI preset events\n" ); 00061 printf( "\t--cache Display cache related PAPI preset events\n" ); 00062 printf( "\t--cnd Display conditional PAPI preset events\n" ); 00063 printf 00064 ( "\t--fp Display Floating Point related PAPI preset events\n" ); 00065 printf 00066 ( "\t--ins Display instruction related PAPI preset events\n" ); 00067 printf( "\t--idl Display Stalled or Idle PAPI preset events\n" ); 00068 printf 00069 ( "\t--l1 Display level 1 cache related PAPI preset events\n" ); 00070 printf 00071 ( "\t--l2 Display level 2 cache related PAPI preset events\n" ); 00072 printf 00073 ( "\t--l3 Display level 3 cache related PAPI preset events\n" ); 00074 printf( "\t--mem Display memory related PAPI preset events\n" ); 00075 printf( "\t--msc Display miscellaneous PAPI preset events\n" ); 00076 printf 00077 ( "\t--tlb Display Translation Lookaside Buffer PAPI preset events\n" ); 00078 printf( "\n" ); 00079 printf 00080 ( "This program provides information about PAPI preset and native events.\n" ); 00081 printf( "PAPI preset event filters can be combined in a logical OR.\n" ); 00082 } 00083 00084 static int 00085 parse_unit_masks( PAPI_event_info_t * info ) 00086 { 00087 char *pmask; 00088 00089 if ( ( pmask = strchr( info->symbol, ':' ) ) == NULL ) { 00090 return ( 0 ); 00091 } 00092 memmove( info->symbol, pmask, ( strlen( pmask ) + 1 ) * sizeof ( char ) ); 00093 pmask = strchr( info->long_descr, ':' ); 00094 if ( pmask == NULL ) 00095 info->long_descr[0] = 0; 00096 else 00097 memmove( info->long_descr, pmask + sizeof ( char ), 00098 ( strlen( pmask ) + 1 ) * sizeof ( char ) ); 00099 return ( 1 ); 00100 } 00101 00102 int 00103 main( int argc, char **argv ) 00104 { 00105 int args, j, k; 00106 int retval; 00107 unsigned int filter = 0; 00108 int print_event_info = 0; 00109 char *name = NULL; 00110 int print_avail_only = 0; 00111 int print_tabular = 1; 00112 PAPI_event_info_t info; 00113 const PAPI_hw_info_t *hwinfo = NULL; 00114 int tot_count = 0; 00115 int avail_count = 0; 00116 int deriv_count = 0; 00117 int event_code; 00118 00119 PAPI_event_info_t n_info; 00120 00121 /* Set TESTS_QUIET variable */ 00122 00123 tests_quiet( argc, argv ); 00124 00125 /* Parse command line arguments */ 00126 00127 for( args = 1; args < argc; args++ ) { 00128 if ( strstr( argv[args], "-e" ) ) { 00129 print_event_info = 1; 00130 name = argv[args + 1]; 00131 if ( ( name == NULL ) || ( strlen( name ) == 0 ) ) { 00132 print_help( argv ); 00133 exit( 1 ); 00134 } 00135 } else if ( strstr( argv[args], "-a" ) ) 00136 print_avail_only = PAPI_PRESET_ENUM_AVAIL; 00137 else if ( strstr( argv[args], "-d" ) ) 00138 print_tabular = 0; 00139 else if ( strstr( argv[args], "-h" ) ) { 00140 print_help( argv ); 00141 exit( 1 ); 00142 } else if ( strstr( argv[args], "--br" ) ) 00143 filter |= PAPI_PRESET_BIT_BR; 00144 else if ( strstr( argv[args], "--cache" ) ) 00145 filter |= PAPI_PRESET_BIT_CACH; 00146 else if ( strstr( argv[args], "--cnd" ) ) 00147 filter |= PAPI_PRESET_BIT_CND; 00148 else if ( strstr( argv[args], "--fp" ) ) 00149 filter |= PAPI_PRESET_BIT_FP; 00150 else if ( strstr( argv[args], "--ins" ) ) 00151 filter |= PAPI_PRESET_BIT_INS; 00152 else if ( strstr( argv[args], "--idl" ) ) 00153 filter |= PAPI_PRESET_BIT_IDL; 00154 else if ( strstr( argv[args], "--l1" ) ) 00155 filter |= PAPI_PRESET_BIT_L1; 00156 else if ( strstr( argv[args], "--l2" ) ) 00157 filter |= PAPI_PRESET_BIT_L2; 00158 else if ( strstr( argv[args], "--l3" ) ) 00159 filter |= PAPI_PRESET_BIT_L3; 00160 else if ( strstr( argv[args], "--mem" ) ) 00161 filter |= PAPI_PRESET_BIT_BR; 00162 else if ( strstr( argv[args], "--msc" ) ) 00163 filter |= PAPI_PRESET_BIT_MSC; 00164 else if ( strstr( argv[args], "--tlb" ) ) 00165 filter |= PAPI_PRESET_BIT_TLB; 00166 } 00167 00168 if ( filter == 0 ) { 00169 filter = ( unsigned int ) ( -1 ); 00170 } 00171 00172 /* Init PAPI */ 00173 00174 retval = PAPI_library_init( PAPI_VER_CURRENT ); 00175 if ( retval != PAPI_VER_CURRENT ) { 00176 test_fail( __FILE__, __LINE__, "PAPI_library_init", retval ); 00177 } 00178 00179 if ( !TESTS_QUIET ) { 00180 retval = PAPI_set_debug( PAPI_VERB_ECONT ); 00181 if ( retval != PAPI_OK ) { 00182 test_fail( __FILE__, __LINE__, "PAPI_set_debug", retval ); 00183 } 00184 00185 retval=papi_print_header("Available events and hardware information.\n", 00186 &hwinfo ); 00187 if ( retval != PAPI_OK ) { 00188 test_fail( __FILE__, __LINE__, "PAPI_get_hardware_info", 2 ); 00189 } 00190 00191 /* Code for info on just one event */ 00192 00193 if ( print_event_info ) { 00194 00195 if ( PAPI_event_name_to_code( name, &event_code ) == PAPI_OK ) { 00196 if ( PAPI_get_event_info( event_code, &info ) == PAPI_OK ) { 00197 00198 if ( event_code & PAPI_PRESET_MASK ) { 00199 printf( "%-30s%s\n%-30s0x%-10x\n%-30s%d\n", 00200 "Event name:", info.symbol, "Event Code:", 00201 info.event_code, "Number of Native Events:", 00202 info.count ); 00203 printf( "%-29s|%s|\n%-29s|%s|\n%-29s|%s|\n", 00204 "Short Description:", info.short_descr, 00205 "Long Description:", info.long_descr, 00206 "Developer's Notes:", info.note ); 00207 printf( "%-29s|%s|\n%-29s|%s|\n", "Derived Type:", 00208 info.derived, "Postfix Processing String:", 00209 info.postfix ); 00210 00211 for( j = 0; j < ( int ) info.count; j++ ) { 00212 printf( " Native Code[%d]: 0x%x |%s|\n", j, 00213 info.code[j], info.name[j] ); 00214 PAPI_get_event_info( (int) info.code[j], &n_info ); 00215 printf(" Number of Register Values: %d\n", n_info.count ); 00216 for( k = 0; k < ( int ) n_info.count; k++ ) { 00217 printf( " Register[%2d]: 0x%08x |%s|\n", k, 00218 n_info.code[k], n_info.name[k] ); 00219 } 00220 printf( " Native Event Description: |%s|\n\n", 00221 n_info.long_descr ); 00222 } 00223 } else { /* must be a native event code */ 00224 printf( "%-30s%s\n%-30s0x%-10x\n%-30s%d\n", 00225 "Event name:", info.symbol, "Event Code:", 00226 info.event_code, "Number of Register Values:", 00227 info.count ); 00228 printf( "%-29s|%s|\n", "Description:", info.long_descr ); 00229 for ( k = 0; k < ( int ) info.count; k++ ) { 00230 printf( " Register[%2d]: 0x%08x |%s|\n", k, 00231 info.code[k], info.name[k] ); 00232 } 00233 00234 /* if unit masks exist but none are specified, process all */ 00235 if ( !strchr( name, ':' ) ) { 00236 if ( 1 ) { 00237 if ( PAPI_enum_event( &event_code, PAPI_NTV_ENUM_UMASKS ) == PAPI_OK ) { 00238 printf( "\nUnit Masks:\n" ); 00239 do { 00240 retval = PAPI_get_event_info(event_code, &info ); 00241 if ( retval == PAPI_OK ) { 00242 if ( parse_unit_masks( &info ) ) { 00243 printf( "%-29s|%s|%s|\n", 00244 " Mask Info:", info.symbol, 00245 info.long_descr ); 00246 for ( k = 0; k < ( int ) info.count;k++ ) { 00247 printf( " Register[%2d]: 0x%08x |%s|\n", 00248 k, info.code[k], info.name[k] ); 00249 } 00250 } 00251 } 00252 } while ( PAPI_enum_event( &event_code, 00253 PAPI_NTV_ENUM_UMASKS ) == PAPI_OK ); 00254 } 00255 } 00256 } 00257 } 00258 } 00259 } else { 00260 printf( "Sorry, an event by the name '%s' could not be found.\n" 00261 " Is it typed correctly?\n\n", name ); 00262 } 00263 } else { 00264 00265 /* Print *ALL* Events */ 00266 00267 /* For consistency, always ASK FOR the first event */ 00268 event_code = 0 | PAPI_PRESET_MASK; 00269 PAPI_enum_event( &event_code, PAPI_ENUM_FIRST ); 00270 00271 if ( print_tabular ) { 00272 printf( " Name Code " ); 00273 if ( !print_avail_only ) { 00274 printf( "Avail " ); 00275 } 00276 printf( "Deriv Description (Note)\n" ); 00277 } else { 00278 printf( "%-13s%-11s%-8s%-16s\n |Long Description|\n" 00279 " |Developer's Notes|\n |Derived|\n |PostFix|\n" 00280 " Native Code[n]: <hex> |name|\n", 00281 "Symbol", "Event Code", "Count", "|Short Description|" ); 00282 } 00283 do { 00284 if ( PAPI_get_event_info( event_code, &info ) == PAPI_OK ) { 00285 if ( print_tabular ) { 00286 if ( filter & info.event_type ) { 00287 if ( print_avail_only ) { 00288 if ( info.count ) { 00289 printf( "%-13s0x%x %-5s%s", 00290 info.symbol, 00291 info.event_code, 00292 is_derived( &info ), info.long_descr ); 00293 } 00294 if ( info.note[0] ) { 00295 printf( " (%s)", info.note ); 00296 } 00297 printf( "\n" ); 00298 } else { 00299 printf( "%-13s0x%x %-6s%-4s %s", 00300 info.symbol, 00301 info.event_code, 00302 ( info.count ? "Yes" : "No" ), 00303 is_derived( &info ), info.long_descr ); 00304 if ( info.note[0] ) { 00305 printf( " (%s)", info.note ); 00306 } 00307 printf( "\n" ); 00308 } 00309 tot_count++; 00310 if ( info.count ) { 00311 avail_count++; 00312 } 00313 if ( !strcmp( is_derived( &info ), "Yes" ) ) { 00314 deriv_count++; 00315 } 00316 } 00317 } else { 00318 if ( ( print_avail_only && info.count ) || 00319 ( print_avail_only == 0 ) ) { 00320 printf( "%s\t0x%x\t%d\t|%s|\n |%s|\n" 00321 " |%s|\n |%s|\n |%s|\n", 00322 info.symbol, info.event_code, info.count, 00323 info.short_descr, info.long_descr, info.note, 00324 info.derived, info.postfix ); 00325 for ( j = 0; j < ( int ) info.count; j++ ) { 00326 printf( " Native Code[%d]: 0x%x |%s|\n", j, 00327 info.code[j], info.name[j] ); 00328 } 00329 } 00330 tot_count++; 00331 if ( info.count ) { 00332 avail_count++; 00333 } 00334 if ( !strcmp( is_derived( &info ), "Yes" ) ) { 00335 deriv_count++; 00336 } 00337 } 00338 } 00339 } while (PAPI_enum_event( &event_code, print_avail_only ) == PAPI_OK); 00340 } 00341 printf( "----------------------------------------" 00342 "---------------------------------\n" ); 00343 if ( !print_event_info ) { 00344 if ( print_avail_only ) { 00345 printf( "Of %d available events, %d ", avail_count, deriv_count ); 00346 } else { 00347 printf( "Of %d possible events, %d are available, of which %d ", 00348 tot_count, avail_count, deriv_count ); 00349 } 00350 if ( deriv_count == 1 ) { 00351 printf( "is derived.\n\n" ); 00352 } else { 00353 printf( "are derived.\n\n" ); 00354 } 00355 } 00356 } 00357 test_pass( __FILE__, NULL, 0 ); 00358 exit( 1 ); 00359 00360 }