@@ -277,19 +277,31 @@ int is_preset_event_available(char *name) {
277277 exit (1 );
278278 }
279279
280+ /* Since some component presets require qualifiers, such as ":device=0", but
281+ * the base preset names do not contain qualifiers, then the qualifier must
282+ * first be stripped in order to find a match. */
283+ char * localname = strdup (name );
284+ char * basename = strtok (localname , ":" );
285+ if ( NULL == basename ) {
286+ basename = name ;
287+ }
288+
280289 /* Iterate over all the available preset events and compare them by names. */
281290 do {
282291 if ( PAPI_get_event_info ( event_code , & info ) == PAPI_OK ) {
283292
284293 if ( info .count ) {
285294 if ( (check_counter && checkCounter (event_code )) || !check_counter ) {
286- if (strcmp (info .symbol , name ) == 0 )
295+ if (strcmp (info .symbol , basename ) == 0 )
287296 return 1 ;
288297 }
289298 }
290299 }
291300 } while (PAPI_enum_event ( & event_code , PAPI_PRESET_ENUM_AVAIL ) == PAPI_OK );
292301
302+ /* Free the temporary, dynamically allocated buffer. */
303+ free (localname );
304+
293305 return 0 ;
294306}
295307
@@ -503,7 +515,7 @@ main( int argc, char **argv )
503515 }
504516 printf ( "Deriv Description (Note)\n" );
505517 } else {
506- printf ( "%-13s %-11s%-8s%-16s\n |Long Description|\n"
518+ printf ( "%-17s %-11s%-8s%-16s\n |Long Description|\n"
507519 " |Developer's Notes|\n |Derived|\n |PostFix|\n"
508520 " Native Code[n]: <hex> |name|\n" ,
509521 "Symbol" , "Event Code" , "Count" , "|Short Description|" );
@@ -517,7 +529,7 @@ main( int argc, char **argv )
517529 if ( info .count ) {
518530 if ( (check_counter && checkCounter (event_code )) || !check_counter )
519531 {
520- printf ( "%-13s %#x %-5s%s" ,
532+ printf ( "%-17s %#x %-5s%s" ,
521533 info .symbol ,
522534 info .event_code ,
523535 is_derived ( & info ), info .long_descr );
@@ -528,7 +540,7 @@ main( int argc, char **argv )
528540 }
529541 printf ( "\n" );
530542 } else {
531- printf ( "%-13s %#x %-6s%-4s %s" ,
543+ printf ( "%-17s %#x %-6s%-4s %s" ,
532544 info .symbol ,
533545 info .event_code ,
534546 ( info .count ? "Yes" : "No" ),
@@ -575,13 +587,151 @@ main( int argc, char **argv )
575587 }
576588 }
577589 } while (PAPI_enum_event ( & event_code , print_avail_only ) == PAPI_OK );
590+
591+ /* Repeat the logic for component presets. For consistency, always ASK FOR the first event,
592+ * if there is not one then nothing to process */
593+ if (PAPI_enum_event ( & event_code , PAPI_PRESET_ENUM_FIRST_COMP ) != PAPI_OK ) {
594+ continue ;
595+ }
596+
597+ /* Print heading for component presets. */
598+ if (i == 0 ) {
599+
600+ if ( print_avail_only == PAPI_PRESET_ENUM_CPU ) {
601+ print_avail_only = PAPI_ENUM_EVENTS ;
602+ } else if ( print_avail_only == PAPI_PRESET_ENUM_CPU_AVAIL ) {
603+ print_avail_only = PAPI_PRESET_ENUM_AVAIL ;
604+ }
605+
606+ printf ( "================================================================================\n" );
607+ printf ( " PAPI Component Presets\n" );
608+ printf ( "================================================================================\n" );
609+
610+ if ( print_tabular ) {
611+ printf ( " Name Code " );
612+ if ( print_avail_only == PAPI_ENUM_EVENTS ) {
613+ printf ( "Avail " );
614+ }
615+ printf ( "Deriv Description (Note)\n" );
616+ } else {
617+ printf ( "%-17s%-11s%-8s%-16s\n |Long Description|\n"
618+ " |Developer's Notes|\n |Derived|\n |PostFix|\n"
619+ " Native Code[n]: <hex> |name|\n" ,
620+ "Symbol" , "Event Code" , "Count" , "|Short Description|" );
621+ }
622+
623+ int first_flag = 1 ;
624+ do {
625+ if ( PAPI_get_event_info ( event_code , & info ) == PAPI_OK ) {
626+ if ( print_tabular ) {
627+ // if this is a user defined event or its a preset and matches the preset event filters, display its information
628+ if ( filter & info .event_type ) {
629+ if ( print_avail_only == PAPI_PRESET_ENUM_AVAIL ) {
630+ if ( info .count ) {
631+ if ( (check_counter && checkCounter (event_code )) || !check_counter ) {
632+ printf ( "%-17s%#x %-5s%s\n" ,
633+ info .symbol ,
634+ info .event_code ,
635+ is_derived ( & info ), info .long_descr );
636+
637+ /* Add event to tally. */
638+ avail_count ++ ;
639+ if ( !strcmp ( is_derived ( & info ), "Yes" ) ) {
640+ deriv_count ++ ;
641+ }
642+
643+ /* List the qualifiers. */
644+ int k ;
645+ for ( k = 0 ; k < info .num_quals ; ++ k ) {
646+ printf (" %s\n %s" , info .quals [k ], info .quals_descrs [k ]);
647+ }
648+ }
649+ }
650+ if ( info .note [0 ] ) {
651+ printf ( " (%s)" , info .note );
652+ }
653+ printf ( "\n" );
654+ } else {
655+
656+ int cid , numcmp = PAPI_num_components ();
657+ for ( cid = 0 ; cid < numcmp ; cid ++ ) {
658+ const PAPI_component_info_t * component ;
659+ component = PAPI_get_component_info (cid );
660+
661+ /* Skip disabled components */
662+ if (component -> disabled && component -> disabled != PAPI_EDELAY_INIT ) continue ;
663+
664+ if ( info .count && info .component_index == cid ) {
665+ if ( !first_flag ) {
666+ printf ( "--------------------------------------------------------------------------------\n" );
667+ }
668+ first_flag = 0 ;
669+ printf ( "%-17s%#x %-6s%-4s %s" ,
670+ info .symbol ,
671+ info .event_code ,
672+ ( info .count ? "Yes" : "No" ),
673+ is_derived ( & info ), info .long_descr );
674+ if ( info .note [0 ] ) {
675+ printf ( " (%s)" , info .note );
676+ }
677+ printf ("\n" );
678+
679+ /* List the qualifiers. */
680+ int k ;
681+ for ( k = 0 ; k < info .num_quals ; ++ k ) {
682+ printf (" %s\n %s\n" , info .quals [k ], info .quals_descrs [k ]);
683+ }
684+
685+ tot_count ++ ;
686+ if ( info .count ) {
687+ if ((check_counter && checkCounter (event_code )) || !check_counter )
688+ avail_count ++ ;
689+ }
690+ if ( !strcmp ( is_derived ( & info ), "Yes" ) ) {
691+ deriv_count ++ ;
692+ }
693+ }
694+ } // end of loop for number of components
695+ }
696+ }
697+ } else {
698+ if ( ( print_avail_only == PAPI_PRESET_ENUM_AVAIL && info .count ) ||
699+ ( print_avail_only == PAPI_ENUM_EVENTS ) )
700+ {
701+ if ((check_counter && checkCounter (event_code )) || !check_counter ) {
702+ printf ( "%s\t%#x\t%d\t|%s|\n |%s|\n"
703+ " |%s|\n |%s|\n |%s|\n" ,
704+ info .symbol , info .event_code , info .count ,
705+ info .short_descr , info .long_descr , info .note ,
706+ info .derived , info .postfix );
707+ for ( j = 0 ; j < ( int ) info .count ; j ++ ) {
708+ printf ( " Native Code[%d]: %#x |%s|\n" , j ,
709+ info .code [j ], info .name [j ] );
710+ }
711+ }
712+ }
713+ tot_count ++ ;
714+ if ( info .count ) {
715+ if ((check_counter && checkCounter (event_code )) || !check_counter )
716+ avail_count ++ ;
717+ }
718+ if ( !strcmp ( is_derived ( & info ), "Yes" ) ) {
719+ deriv_count ++ ;
720+ }
721+ }
722+ }
723+ } while (PAPI_enum_event ( & event_code , PAPI_ENUM_EVENTS ) == PAPI_OK );
724+ }
725+
726+
727+
578728 }
579729 }
580730
581- printf ( "-------------------------------------------------------------------------------- \n" );
731+ printf ( "================================================================================ \n" );
582732
583733 if ( !print_event_info ) {
584- if ( print_avail_only == PAPI_PRESET_ENUM_CPU_AVAIL ) {
734+ if ( print_avail_only == PAPI_PRESET_ENUM_CPU_AVAIL || print_avail_only == PAPI_PRESET_ENUM_AVAIL ) {
585735 printf ( "Of %d available events, %d " , avail_count , deriv_count );
586736 } else {
587737 printf ( "Of %d possible events, %d are available, of which %d " ,
0 commit comments