PAPI 7.1.0.0
Loading...
Searching...
No Matches
papi_avail.c File Reference
Include dependency graph for papi_avail.c:

Go to the source code of this file.

Functions

static char * is_derived (PAPI_event_info_t *info)
 
static void print_help (char **argv)
 
static int parse_unit_masks (PAPI_event_info_t *info)
 
static int checkCounter (int eventcode)
 
int is_preset_event_available (char *name)
 
int main (int argc, char **argv)
 

Function Documentation

◆ checkCounter()

static int checkCounter ( int  eventcode)
static

Definition at line 249 of file papi_avail.c.

250{
251 int EventSet = PAPI_NULL;
253 return 0;
254 if (PAPI_add_event (EventSet, eventcode) != PAPI_OK)
255 return 0;
257 return 0;
259 return 0;
260 return 1;
261}
add PAPI preset or native hardware event to an event set
Empty and destroy an EventSet.
Create a new empty PAPI EventSet.
Empty and destroy an EventSet.
#define PAPI_OK
Definition: f90papi.h:73
#define PAPI_NULL
Definition: f90papi.h:78
static int EventSet
Definition: init_fini.c:8
Here is the caller graph for this function:

◆ is_derived()

static char * is_derived ( PAPI_event_info_t info)
static

Definition at line 188 of file papi_avail.c.

189{
190 if ( strlen( info->derived ) == 0 )
191 return ( "No" );
192 else if ( strcmp( info->derived, "NOT_DERIVED" ) == 0 )
193 return ( "No" );
194 else if ( strcmp( info->derived, "DERIVED_CMPD" ) == 0 )
195 return ( "No" );
196 else
197 return ( "Yes" );
198}
char derived[PAPI_MIN_STR_LEN]
Definition: papi.h:989
Here is the caller graph for this function:

◆ is_preset_event_available()

int is_preset_event_available ( char *  name)

Definition at line 268 of file papi_avail.c.

268 {
269
270 int event_code = 0 | PAPI_PRESET_MASK;
272 int check_counter = 1;
273
274
275 if (PAPI_enum_event( &event_code, PAPI_ENUM_FIRST ) != PAPI_OK) {
276 printf("error!");
277 exit(1);
278 }
279
280 /* Iterate over all the available preset events and compare them by names. */
281 do {
282 if ( PAPI_get_event_info( event_code, &info ) == PAPI_OK ) {
283
284 if ( info.count ) {
285 if ( (check_counter && checkCounter (event_code)) || !check_counter) {
286 if (strcmp(info.symbol, name) == 0)
287 return 1;
288 }
289 }
290 }
291 } while (PAPI_enum_event( &event_code, PAPI_PRESET_ENUM_AVAIL ) == PAPI_OK);
292
293 return 0;
294}
Enumerate PAPI preset or native events.
Get the event's name and description info.
#define PAPI_ENUM_FIRST
Definition: f90papi.h:85
#define PAPI_PRESET_MASK
@ PAPI_PRESET_ENUM_AVAIL
Definition: papi.h:490
static int checkCounter(int eventcode)
Definition: papi_avail.c:249
const char * name
Definition: rocs.c:225
unsigned int count
Definition: papi.h:981
char symbol[PAPI_HUGE_STR_LEN]
Definition: papi.h:960
Here is the call graph for this function:
Here is the caller graph for this function:

◆ main()

int main ( int  argc,
char **  argv 
)

Definition at line 299 of file papi_avail.c.

300{
301 int args, i, j, k;
302 int retval;
303 unsigned int filter = 0;
304 int print_event_info = 0;
305 char *name = NULL;
306 int print_avail_only = PAPI_ENUM_EVENTS;
307 int print_tabular = 1;
309 const PAPI_hw_info_t *hwinfo = NULL;
310 int tot_count = 0;
311 int avail_count = 0;
312 int deriv_count = 0;
313 int check_counter = 0;
314 int event_code;
315
316 PAPI_event_info_t n_info;
317
318 /* Parse command line arguments */
319
320 for( args = 1; args < argc; args++ ) {
321 if ( strstr( argv[args], "-e" ) ) {
322 print_event_info = 1;
323 if( (args+1 >= argc) || ( argv[args+1] == NULL ) || ( strlen( argv[args+1] ) == 0 ) ) {
324 print_help( argv );
325 exit( 1 );
326 }
327 name = argv[args + 1];
328 }
329 else if ( strstr( argv[args], "-c" ) || strstr (argv[args], "--check") )
330 {
331 print_avail_only = PAPI_PRESET_ENUM_AVAIL;
332 check_counter = 1;
333 }
334 else if ( strstr( argv[args], "-a" ))
335 print_avail_only = PAPI_PRESET_ENUM_AVAIL;
336 else if ( strstr( argv[args], "-d" ) )
337 print_tabular = 0;
338 else if ( strstr( argv[args], "-h" ) ) {
339 print_help( argv );
340 exit( 1 );
341 } else if ( strstr( argv[args], "--br" ) )
342 filter |= PAPI_PRESET_BIT_BR;
343 else if ( strstr( argv[args], "--cache" ) )
344 filter |= PAPI_PRESET_BIT_CACH;
345 else if ( strstr( argv[args], "--cnd" ) )
346 filter |= PAPI_PRESET_BIT_CND;
347 else if ( strstr( argv[args], "--fp" ) )
348 filter |= PAPI_PRESET_BIT_FP;
349 else if ( strstr( argv[args], "--ins" ) )
350 filter |= PAPI_PRESET_BIT_INS;
351 else if ( strstr( argv[args], "--idl" ) )
352 filter |= PAPI_PRESET_BIT_IDL;
353 else if ( strstr( argv[args], "--l1" ) )
354 filter |= PAPI_PRESET_BIT_L1;
355 else if ( strstr( argv[args], "--l2" ) )
356 filter |= PAPI_PRESET_BIT_L2;
357 else if ( strstr( argv[args], "--l3" ) )
358 filter |= PAPI_PRESET_BIT_L3;
359 else if ( strstr( argv[args], "--mem" ) )
360 filter |= PAPI_PRESET_BIT_BR;
361 else if ( strstr( argv[args], "--msc" ) )
362 filter |= PAPI_PRESET_BIT_MSC;
363 else if ( strstr( argv[args], "--tlb" ) )
364 filter |= PAPI_PRESET_BIT_TLB;
365 }
366
367 if ( filter == 0 ) {
368 filter = ( unsigned int ) ( -1 );
369 }
370
371 /* Init PAPI */
372
374 if ( retval != PAPI_VER_CURRENT ) {
375 fprintf(stderr,"Error! PAPI library mismatch!\n");
376 return 1;
377 }
378
379
381 if ( retval != PAPI_OK ) {
382 fprintf(stderr,"Error with PAPI_set debug!\n");
383 return 1;
384 }
385
386 retval=papi_print_header("Available PAPI preset and user defined events plus hardware information.\n",
387 &hwinfo );
388 if ( retval != PAPI_OK ) {
389 fprintf(stderr,"Error with PAPI_get_hardware_info!\n");
390 return 1;
391 }
392
393 /* Code for info on just one event */
394
395 if ( print_event_info ) {
396
397 if ( PAPI_event_name_to_code( name, &event_code ) == PAPI_OK ) {
398 if ( PAPI_get_event_info( event_code, &info ) == PAPI_OK ) {
399
400 if ( event_code & PAPI_PRESET_MASK ) {
401 printf( "%-30s%s\n%-30s%#-10x\n%-30s%d\n",
402 "Event name:", info.symbol, "Event Code:",
403 info.event_code, "Number of Native Events:",
404 info.count );
405 printf( "%-29s|%s|\n%-29s|%s|\n%-29s|%s|\n",
406 "Short Description:", info.short_descr,
407 "Long Description:", info.long_descr,
408 "Developer's Notes:", info.note );
409 printf( "%-29s|%s|\n%-29s|%s|\n", "Derived Type:",
410 info.derived, "Postfix Processing String:",
411 info.postfix );
412
413 for( j = 0; j < ( int ) info.count; j++ ) {
414 printf( " Native Code[%d]: %#x |%s|\n", j,
415 info.code[j], info.name[j] );
416 PAPI_get_event_info( (int) info.code[j], &n_info );
417 printf(" Number of Register Values: %d\n", n_info.count );
418 for( k = 0; k < ( int ) n_info.count; k++ ) {
419 printf( " Register[%2d]: %#08x |%s|\n", k,
420 n_info.code[k], n_info.name[k] );
421 }
422 printf( " Native Event Description: |%s|\n\n",
423 n_info.long_descr );
424 }
425
427 printf("\nPRESET event %s is NOT available on this architecture!\n\n", name);
428 }
429
430 } else { /* must be a native event code */
431 printf( "%-30s%s\n%-30s%#-10x\n%-30s%d\n",
432 "Event name:", info.symbol, "Event Code:",
433 info.event_code, "Number of Register Values:",
434 info.count );
435 printf( "%-29s|%s|\n", "Description:", info.long_descr );
436 for ( k = 0; k < ( int ) info.count; k++ ) {
437 printf( " Register[%2d]: %#08x |%s|\n", k,
438 info.code[k], info.name[k] );
439 }
440
441 /* if unit masks exist but none are specified, process all */
442 if ( !strchr( name, ':' ) ) {
443 if ( 1 ) {
444 if ( PAPI_enum_event( &event_code, PAPI_NTV_ENUM_UMASKS ) == PAPI_OK ) {
445 printf( "\nUnit Masks:\n" );
446 do {
447 retval = PAPI_get_event_info(event_code, &info );
448 if ( retval == PAPI_OK ) {
449 if ( parse_unit_masks( &info ) ) {
450 printf( "%-29s|%s|%s|\n",
451 " Mask Info:", info.symbol,
452 info.long_descr );
453 for ( k = 0; k < ( int ) info.count;k++ ) {
454 printf( " Register[%2d]: %#08x |%s|\n",
455 k, info.code[k], info.name[k] );
456 }
457 }
458 }
459 } while ( PAPI_enum_event( &event_code,
461 }
462 }
463 }
464 }
465 }
466 } else {
467 printf( "Sorry, an event by the name '%s' could not be found.\n"
468 " Is it typed correctly?\n\n", name );
469 }
470 } else {
471
472 /* Print *ALL* Events */
473
474 for (i=0 ; i<2 ; i++) {
475 // set the event code to fetch preset events the first time through loop and user events the second time through the loop
476 if (i== 0) {
477 event_code = 0 | PAPI_PRESET_MASK;
478 } else {
479 event_code = 0 | PAPI_UE_MASK;
480 }
481
482 /* For consistency, always ASK FOR the first event, if there is not one then nothing to process */
483 if (PAPI_enum_event( &event_code, PAPI_ENUM_FIRST ) != PAPI_OK) {
484 continue;
485 }
486
487 // print heading to show which kind of events follow
488 if (i== 0) {
489 printf( "================================================================================\n" );
490 printf( " PAPI Preset Events\n" );
491 printf( "================================================================================\n" );
492 } else {
493 printf( "\n"); // put a blank line after the presets before strarting the user events
494 printf( "================================================================================\n" );
495 printf( " User Defined Events\n" );
496 printf( "================================================================================\n" );
497 }
498
499 if ( print_tabular ) {
500 printf( " Name Code " );
501 if ( !print_avail_only ) {
502 printf( "Avail " );
503 }
504 printf( "Deriv Description (Note)\n" );
505 } else {
506 printf( "%-13s%-11s%-8s%-16s\n |Long Description|\n"
507 " |Developer's Notes|\n |Derived|\n |PostFix|\n"
508 " Native Code[n]: <hex> |name|\n",
509 "Symbol", "Event Code", "Count", "|Short Description|" );
510 }
511 do {
512 if ( PAPI_get_event_info( event_code, &info ) == PAPI_OK ) {
513 if ( print_tabular ) {
514 // if this is a user defined event or its a preset and matches the preset event filters, display its information
515 if ( (i==1) || (filter & info.event_type)) {
516 if ( print_avail_only ) {
517 if ( info.count ) {
518 if ( (check_counter && checkCounter (event_code)) || !check_counter)
519 {
520 printf( "%-13s%#x %-5s%s",
521 info.symbol,
522 info.event_code,
523 is_derived( &info ), info.long_descr );
524 }
525 }
526 if ( info.note[0] ) {
527 printf( " (%s)", info.note );
528 }
529 printf( "\n" );
530 } else {
531 printf( "%-13s%#x %-6s%-4s %s",
532 info.symbol,
533 info.event_code,
534 ( info.count ? "Yes" : "No" ),
535 is_derived( &info ), info.long_descr );
536 if ( info.note[0] ) {
537 printf( " (%s)", info.note );
538 }
539 printf( "\n" );
540 }
541 tot_count++;
542 if ( info.count ) {
543 if ((check_counter && checkCounter (event_code)) || !check_counter )
544 avail_count++;
545 }
546 if ( !strcmp( is_derived( &info ), "Yes" ) ) {
547 deriv_count++;
548 }
549 }
550 } else {
551 if ( ( print_avail_only && info.count ) ||
552 ( print_avail_only == 0 ) )
553 {
554 if ((check_counter && checkCounter (event_code)) || !check_counter)
555 {
556 printf( "%s\t%#x\t%d\t|%s|\n |%s|\n"
557 " |%s|\n |%s|\n |%s|\n",
558 info.symbol, info.event_code, info.count,
559 info.short_descr, info.long_descr, info.note,
560 info.derived, info.postfix );
561 for ( j = 0; j < ( int ) info.count; j++ ) {
562 printf( " Native Code[%d]: %#x |%s|\n", j,
563 info.code[j], info.name[j] );
564 }
565 }
566 }
567 tot_count++;
568 if ( info.count ) {
569 if ((check_counter && checkCounter (event_code)) || !check_counter )
570 avail_count++;
571 }
572 if ( !strcmp( is_derived( &info ), "Yes" ) ) {
573 deriv_count++;
574 }
575 }
576 }
577 } while (PAPI_enum_event( &event_code, print_avail_only ) == PAPI_OK);
578 }
579 }
580
581 printf( "--------------------------------------------------------------------------------\n" );
582
583 if ( !print_event_info ) {
584 if ( print_avail_only ) {
585 printf( "Of %d available events, %d ", avail_count, deriv_count );
586 } else {
587 printf( "Of %d possible events, %d are available, of which %d ",
588 tot_count, avail_count, deriv_count );
589 }
590 if ( deriv_count == 1 ) {
591 printf( "is derived.\n\n" );
592 } else {
593 printf( "are derived.\n\n" );
594 }
595
596 if (avail_count==0) {
597 printf("No events detected! Check papi_component_avail to find out why.\n");
598 printf("\n");
599 }
600 }
601
602 return 0;
603
604}
int i
Convert a name to a numeric hardware event code.
initialize the PAPI library.
Set the current debug level for error output from PAPI.
#define PAPI_VER_CURRENT
Definition: f90papi.h:54
#define PAPI_ENUM_EVENTS
Definition: f90papi.h:224
#define PAPI_VERB_ECONT
Definition: f90papi.h:164
#define PAPI_NTV_ENUM_UMASKS
Definition: f90papi.h:66
#define PAPI_UE_MASK
#define PAPI_PRESET_BIT_MSC
Definition: papi.h:519
#define PAPI_PRESET_BIT_CND
Definition: papi.h:523
#define PAPI_PRESET_BIT_L3
Definition: papi.h:528
#define PAPI_PRESET_BIT_FP
Definition: papi.h:530
#define PAPI_PRESET_BIT_INS
Definition: papi.h:520
#define PAPI_PRESET_BIT_IDL
Definition: papi.h:521
#define PAPI_PRESET_BIT_TLB
Definition: papi.h:529
#define PAPI_PRESET_BIT_CACH
Definition: papi.h:525
#define PAPI_PRESET_BIT_L2
Definition: papi.h:527
#define PAPI_PRESET_BIT_BR
Definition: papi.h:522
#define PAPI_PRESET_BIT_L1
Definition: papi.h:526
int is_preset_event_available(char *name)
Definition: papi_avail.c:268
static int parse_unit_masks(PAPI_event_info_t *info)
Definition: papi_avail.c:231
static char * is_derived(PAPI_event_info_t *info)
Definition: papi_avail.c:188
static void print_help(void)
Definition: papi_cost.c:85
FILE * stderr
int papi_print_header(char *prompt, const PAPI_hw_info_t **hwinfo)
Definition: print_header.c:12
int
Definition: sde_internal.h:89
char name[PAPI_MAX_INFO_TERMS][PAPI_2MAX_STR_LEN]
Definition: papi.h:1003
unsigned int event_type
Definition: papi.h:986
char postfix[PAPI_2MAX_STR_LEN]
Definition: papi.h:992
char note[PAPI_HUGE_STR_LEN]
Definition: papi.h:1007
unsigned int event_code
Definition: papi.h:958
char short_descr[PAPI_MIN_STR_LEN]
Definition: papi.h:961
unsigned int code[PAPI_MAX_INFO_TERMS]
Definition: papi.h:997
char long_descr[PAPI_HUGE_STR_LEN]
Definition: papi.h:963
Hardware info structure.
Definition: papi.h:774
int retval
Definition: zero_fork.c:53
Here is the call graph for this function:

◆ parse_unit_masks()

static int parse_unit_masks ( PAPI_event_info_t info)
static

Definition at line 231 of file papi_avail.c.

232{
233 char *pmask;
234
235 if ( ( pmask = strchr( info->symbol, ':' ) ) == NULL ) {
236 return ( 0 );
237 }
238 memmove( info->symbol, pmask, ( strlen( pmask ) + 1 ) * sizeof ( char ) );
239 pmask = strchr( info->long_descr, ':' );
240 if ( pmask == NULL )
241 info->long_descr[0] = 0;
242 else
243 memmove( info->long_descr, pmask + sizeof ( char ),
244 ( strlen( pmask ) + 1 ) * sizeof ( char ) );
245 return 1;
246}
Here is the caller graph for this function:

◆ print_help()

static void print_help ( char **  argv)
static

Definition at line 201 of file papi_avail.c.

202{
203 printf( "This is the PAPI avail program.\n" );
204 printf( "It provides availability and details about PAPI Presets and User-defined Events.\n" );
205 printf( "PAPI Preset Event filters can be combined in a logical OR.\n" );
206 printf( "Usage: %s [options]\n", argv[0] );
207 printf( "Options:\n\n" );
208 printf( "General command options:\n" );
209 printf( "\t-h, --help Print this help message\n" );
210 printf( "\t-a, --avail Display only available PAPI preset and user defined events\n" );
211 printf( "\t-c, --check Display only available PAPI preset and user defined events after an availability check\n" );
212 printf( "\t-d, --detail Display detailed information about events\n" );
213 printf( "\t-e EVENTNAME Display detail information about specified event\n" );
214 printf( "\nEvent filtering options:\n" );
215 printf( "\t--br Display branch related PAPI preset events\n" );
216 printf( "\t--cache Display cache related PAPI preset events\n" );
217 printf( "\t--cnd Display conditional PAPI preset events\n" );
218 printf( "\t--fp Display Floating Point related PAPI preset events\n" );
219 printf( "\t--ins Display instruction related PAPI preset events\n" );
220 printf( "\t--idl Display Stalled or Idle PAPI preset events\n" );
221 printf( "\t--l1 Display level 1 cache related PAPI preset events\n" );
222 printf( "\t--l2 Display level 2 cache related PAPI preset events\n" );
223 printf( "\t--l3 Display level 3 cache related PAPI preset events\n" );
224 printf( "\t--mem Display memory related PAPI preset events\n" );
225 printf( "\t--msc Display miscellaneous PAPI preset events\n" );
226 printf( "\t--tlb Display Translation Lookaside Buffer PAPI preset events\n" );
227 printf( "\n" );
228}