60#define EVT_LINE_BUF_SIZE 4096
62typedef struct command_flags
83 printf(
"This is the PAPI native avail program.\n" );
84 printf(
"It provides availability and details about PAPI Native Events.\n" );
85 printf(
"Usage: %s [options]\n", argv[0] );
86 printf(
"Options:\n\n" );
87 printf(
"\nGeneral command options:\n" );
88 printf(
"\t-h, --help print this help message\n" );
89 printf(
"\t-c, --check attempts to add each event\n");
90 printf(
"\t-sde FILE lists SDEs that are registered by the library or executable in FILE\n" );
91 printf(
"\t-e EVENTNAME display detailed information about named native event\n" );
92 printf(
"\t-i EVENTSTR include only event names that contain EVENTSTR\n" );
93 printf(
"\t-x EVENTSTR exclude any event names that contain EVENTSTR\n" );
94 printf(
"\t--noqual suppress display of event qualifiers (mask and flag) information\n" );
95 printf(
"\nProcessor-specific options:\n");
96 printf(
"\t--darr display events supporting Data Address Range Restriction\n" );
97 printf(
"\t--dear display Data Event Address Register events only\n" );
98 printf(
"\t--iarr display events supporting Instruction Address Range Restriction\n" );
99 printf(
"\t--iear display Instruction Event Address Register events only\n" );
100 printf(
"\t--opcm display events supporting OpCode Matching\n" );
101 printf(
"\t--nogroups suppress display of Event grouping information\n" );
108 return ( ( arg == NULL ) || ( strlen( arg ) == 0 ) || ( arg[0] ==
'-' ) );
121 for (
i = 1;
i < argc;
i++ ) {
122 if ( !strcmp( argv[
i],
"--darr" ) )
124 else if ( !strcmp( argv[
i],
"--dear" ) )
126 else if ( !strcmp( argv[
i],
"--iarr" ) )
128 else if ( !strcmp( argv[
i],
"--iear" ) )
130 else if ( !strcmp( argv[
i],
"--opcm" ) )
132 else if ( !strcmp( argv[
i],
"--noqual" ) )
134 else if ( !strcmp( argv[
i],
"--nogroups" ) )
136 else if ( !strcmp( argv[
i],
"-e" ) ) {
142 printf(
"Invalid argument for -e\n");
147 else if ( !strcmp( argv[
i],
"-sde" ) ) {
153 printf(
"Invalid argument for -sde\n");
158 else if ( !strcmp( argv[
i],
"-i" ) ) {
164 printf(
"Invalid argument for -i\n");
167 }
else if ( !strcmp( argv[
i],
"-x" ) ) {
173 printf(
"Invalid argument for -x\n");
176 }
else if ( strstr( argv[
i],
"-h" ) ) {
178 }
else if ( !strcmp( argv[
i],
"-c" ) || !strcmp( argv[
i],
"--check" ) ) {
181 printf(
"%s is not supported\n", argv[
i] );
196 while ( spaces-- > 0 )
220 printf(
"********** Call to destroy eventset failed when trying to check event '%s' **********\n", info->
symbol);
230 unsigned int i, j = 0;
232 char event_line_units[100];
237 sprintf(event_line_buffer,
"| %-73s|\n", info->
symbol);
241 sprintf(event_line_buffer,
"| %-73s%4s|\n", info->
symbol,
"<-->");
252 printf (
"Event or mask description has been truncated.\n");
259 strcat(event_line_buffer,
"| " );
262 strcat( event_line_buffer, &info->
long_descr[j]);
264 strcat( event_line_buffer,
"|\n" );
269 int k = strlen(event_line_buffer);
270 strncat( event_line_buffer, &info->
long_descr[j],
i );
271 event_line_buffer[k+
i] =
'\0';
272 strcat( event_line_buffer,
"|\n" );
279 event_line_units[0] =
'\0';
280 if (info->
units[0] != 0) {
281 sprintf(event_line_units,
"| Units: %-66s|\n", info->
units );
285 int out_buf_used = 0;
303 fprintf(
stderr,
"Error! Allocation of output buffer memory failed.\n");
320 if (val_flag_ptr != NULL) {
323 *(val_flag_ptr+1) =
'N';
324 *(val_flag_ptr+2) =
'A';
329 *(val_flag_ptr+1) =
' ';
330 *(val_flag_ptr+2) =
' ';
331 *(val_flag_ptr+3) =
' ';
349 if ((ptr=strstr(info->
symbol,
":::"))) {
352 }
else if ((ptr=strstr(info->
symbol,
"::"))) {
359 if ( ( pmask = strchr( ptr,
':' ) ) == NULL ) {
362 memmove( info->
symbol, pmask, ( strlen(pmask) + 1 ) *
sizeof(
char) );
369 if ( pmask == NULL ) {
373 memmove( info->
long_descr, pmask, (strlen(pmask) + 1) *
sizeof(
char) );
380invoke_hook_fptr(
char *lib_path )
384 hook_fptr_t hook_func_ptr;
389 dl_handle = dlopen(lib_path, RTLD_LOCAL | RTLD_LAZY);
390 if ( NULL == dl_handle ) {
394 hook_func_ptr = (hook_fptr_t)dlsym(dl_handle,
"papi_sde_hook_list_events");
395 if ( (NULL != hook_func_ptr) && ( NULL == dlerror()) ) {
399 (void)hook_func_ptr( &fptr_struct );
412 int num_cmp_events = 0;
423 fprintf(
stderr,
"Error! PAPI_library_init\n");
433 else if ( flags.
darr )
435 else if ( flags.
iear )
437 else if ( flags.
iarr )
439 else if ( flags.
opcm )
446 fprintf(
stderr,
"Error! PAPI_set_debug\n");
452 fprintf(
stderr,
"Error! PAPI_get_hardware_info\n");
467 if ( access(flags.
path, R_OK) == -1 ){
468 fprintf(
stderr,
"Error! Unable to read file '%s'.\n",flags.
path);
472 int len = 5+strlen(flags.
path);
473 cmd = (
char *)calloc(len,
sizeof(
char));
474 if( NULL == cmd )
goto no_sdes;
476 int l = snprintf(cmd, len,
"ldd %s",flags.
path);
483 pipe = popen(cmd,
"r");
485 while( !feof(pipe) ){
486 char *lineptr, *lib_name, *lib_path;
488 lineptr = lib_name = lib_path = NULL;
490 if( getline(&lineptr, &n, pipe) == -1 ){
491 if(lineptr) free(lineptr);
496 if( (NULL != strstr(lineptr,
"not found")) || (NULL == strstr(lineptr,
" => ")) ) {
500 int status = sscanf(lineptr,
"%ms => %ms (%*x)", &lib_name, &lib_path);
509 invoke_hook_fptr(lib_path);
511 if( lib_name ) free(lib_name);
512 if( lib_path ) free(lib_path);
514 if(lineptr) free(lineptr);
522 invoke_hook_fptr(flags.
path);
524 if( NULL != cmd ) free(cmd);
533 printf(
"Event name: %s\n", info.
symbol);
534 printf(
"Description: %s\n", info.
long_descr );
538 if ((ptr=strstr(flags.
name,
":::"))) {
541 }
else if ((ptr=strstr(flags.
name,
"::"))) {
549 if ( !strchr( ptr,
':' ) ) {
551 printf(
"\nQualifiers: Name -- Description\n" );
564 printf(
"Sorry, an event by the name '%s' could not be found.\n",
566 printf(
"Is it typed correctly?\n\n");
578 for ( cid = 0; cid < numcmp; cid++ ) {
585 printf(
"===============================================================================\n" );
586 printf(
" Native Events in Component: %s\n",component->
name);
587 printf(
"===============================================================================\n" );
600 memset( &info, 0,
sizeof ( info ) );
613 if (num_cmp_events) {
614 printf(
"--------------------------------------------------------------------------------\n" );
637 printf(
"Groups: " );
663 if (strlen(first_event_mask_string) == 0) {
664 strcpy (first_event_mask_string, info.
symbol);
682 strcpy (info.
symbol, first_event_mask_string);
683 strcat (info.
symbol,
":cpu=1");
689 strcpy (info.
symbol, first_event_mask_string);
690 char *wptr = strrchr (info.
symbol,
':');
693 strcat (info.
symbol,
":ff=64:cpu=1");
704 if (num_cmp_events != 0) {
705 printf(
"--------------------------------------------------------------------------------\n" );
707 printf(
"\nTotal events reported: %d\n",
num_events );
710 printf(
"\nNo events detected! Check papi_component_avail to find out why.\n");
add PAPI preset or native hardware event by name to an EventSet
Create a new empty PAPI EventSet.
Empty and destroy an EventSet.
Enumerate PAPI preset or native events for a given component.
Enumerate PAPI preset or native events.
Convert a name to a numeric hardware event code.
get information about a specific software component
Get the event's name and description info.
initialize the PAPI library.
Get the number of components available on the system.
removes a named hardware event from a PAPI event set.
Set the current debug level for error output from PAPI.
#define PAPI_NTV_GROUP_AND_MASK
#define PAPI_NTV_ENUM_IEAR
#define PAPI_NTV_ENUM_UMASKS
#define PAPI_NTV_ENUM_OPCM
#define PAPI_NTV_GROUP_SHIFT
#define PAPI_NTV_ENUM_DEAR
#define PAPI_NTV_ENUM_DARR
#define PAPI_NTV_ENUM_IARR
#define PAPI_HUGE_STR_LEN
Return codes and api definitions.
static void print_help(void)
#define EVT_LINE_BUF_SIZE
static int format_event_output(PAPI_event_info_t *info, int offset)
static void print_event_output(int val_flag)
unsigned int event_available
char * event_output_buffer
static int parse_event_qualifiers(PAPI_event_info_t *info)
static int no_str_arg(char *arg)
unsigned int event_output_buffer_size
static void check_event(PAPI_event_info_t *info)
static void parse_args(int argc, char **argv, command_flags_t *f)
static void space_pad(char *str, int spaces)
static const pmg_power_group_t * groups
SDE prototypes and macros.
#define POPULATE_SDE_FPTR_STRUCT(_A_)
char name[PAPI_MAX_STR_LEN]
char units[PAPI_MIN_STR_LEN]
char symbol[PAPI_HUGE_STR_LEN]
char long_descr[PAPI_HUGE_STR_LEN]