PAPI  5.4.0.0
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
component.c
Go to the documentation of this file.
1 
25 #include "papi_test.h"
26 
27 #define EVT_LINE 80
28 
29 typedef struct command_flags
30 {
31  int help;
32  int details;
33  int named;
34  char *name;
36 
37 static void
38 print_help( char **argv )
39 {
40  printf( "This is the PAPI component avail program.\n" );
41  printf( "It provides availability of installed PAPI components.\n" );
42  printf( "Usage: %s [options]\n", argv[0] );
43  printf( "Options:\n\n" );
44  printf( " --help, -h print this help message\n" );
45  printf( " -d print detailed information on each component\n" );
46 }
47 
48 static void
50 {
51  int i;
52 
53  /* Look for all currently defined commands */
54  memset( f, 0, sizeof ( command_flags_t ) );
55  for ( i = 1; i < argc; i++ ) {
56  if ( !strcmp( argv[i], "-d" ) ) {
57  f->details = 1;
58  } else if ( !strcmp( argv[i], "-h" ) || !strcmp( argv[i], "--help" ) )
59  f->help = 1;
60  else
61  printf( "%s is not supported\n", argv[i] );
62  }
63 
64  /* if help requested, print and bail */
65  if ( f->help ) {
66  print_help( argv );
67  exit( 1 );
68  }
69 
70 }
71 
72 int
73 main( int argc, char **argv )
74 {
75  int i;
76  int retval;
77  const PAPI_hw_info_t *hwinfo = NULL;
78  const PAPI_component_info_t* cmpinfo;
80  int numcmp, cid;
81 
82  tests_quiet( argc, argv ); /* Set TESTS_QUIET variable */
83 
84  /* Initialize before parsing the input arguments */
86  if ( retval != PAPI_VER_CURRENT )
87  test_fail( __FILE__, __LINE__, "PAPI_library_init", retval );
88 
89  parse_args( argc, argv, &flags );
90 
91  if ( !TESTS_QUIET ) {
92  retval = PAPI_set_debug( PAPI_VERB_ECONT );
93  if ( retval != PAPI_OK )
94  test_fail( __FILE__, __LINE__, "PAPI_set_debug", retval );
95  }
96 
97  retval =
99  ( "Available components and hardware information.\n", &hwinfo );
100  if ( retval != PAPI_OK )
101  test_fail( __FILE__, __LINE__, "PAPI_get_hardware_info", 2 );
102 
103 
104  /* Compiled-in Components */
105  numcmp = PAPI_num_components( );
106 
107  printf("Compiled-in components:\n");
108  for ( cid = 0; cid < numcmp; cid++ ) {
109  cmpinfo = PAPI_get_component_info( cid );
110 
111  printf( "Name: %-23s %s\n", cmpinfo->name ,cmpinfo->description);
112 
113  if (cmpinfo->disabled) {
114  printf(" \\-> Disabled: %s\n",cmpinfo->disabled_reason);
115  }
116 
117  if ( flags.details ) {
118  printf( "Version:\t\t\t%s\n", cmpinfo->version );
119  printf( "Number of native events:\t%d\n", cmpinfo->num_native_events);
120  printf( "Number of preset events:\t%d\n", cmpinfo->num_preset_events);
121  printf("\n");
122  }
123  }
124 
125  printf("\nActive components:\n");
126  numcmp = PAPI_num_components( );
127 
128  for ( cid = 0; cid < numcmp; cid++ ) {
129  cmpinfo = PAPI_get_component_info( cid );
130  if (cmpinfo->disabled) continue;
131 
132  printf( "Name: %-23s %s\n", cmpinfo->name ,cmpinfo->description);
133  printf( " %-23s Native: %d, Preset: %d, Counters: %d\n",
134  " ", cmpinfo->num_native_events, cmpinfo->num_preset_events, cmpinfo->num_cntrs);
135  printf( " %-23s PMU's supported: ", " ");
136  int line_len = 49;
137  for (i=0 ; i<PAPI_PMU_MAX ; i++) {
138  if (cmpinfo->pmu_names[i] == NULL) continue;
139 
140  if (line_len + strlen(cmpinfo->pmu_names[i]) > 130) {
141  printf("\n %-23s ", " ");
142  line_len = 49;
143  } else {
144  line_len += strlen(cmpinfo->pmu_names[i]);
145  }
146  // if it is not the first entry on a line, separate the names
147  if ((i != 0) && (line_len > 50)) {
148  printf(", ");
149  }
150  printf("%s", cmpinfo->pmu_names[i]);
151  }
152  printf("\n\n");
153 
154  if ( flags.details ) {
155  printf( "Version:\t\t\t%s\n", cmpinfo->version );
156  printf( "Number of native events:\t%d\n", cmpinfo->num_native_events);
157  printf( "Number of preset events:\t%d\n", cmpinfo->num_preset_events);
158  printf("\n");
159  }
160  }
161 
162 
163  printf
164  ( "\n--------------------------------------------------------------------------------\n" );
165  test_pass( __FILE__, NULL, 0 );
166  exit( 0 );
167 }
char name[PAPI_MAX_STR_LEN]
Definition: papi.h:626
memset(eventId, 0, size)
double f(double a)
Definition: cpi.c:23
const PAPI_component_info_t * PAPI_get_component_info(int cidx)
Definition: papi.c:807
#define PAPI_VERB_ECONT
Definition: papi.h:387
Hardware info structure.
Definition: papi.h:777
long long flags
Definition: iozone.c:12330
int papi_print_header(char *prompt, const PAPI_hw_info_t **hwinfo)
Definition: test_utils.c:21
int PAPI_num_components(void)
Definition: papi.c:4326
return PAPI_OK
Definition: linux-nvml.c:458
tests_quiet(argc, argv)
#define printf
Definition: papi_test.h:125
static void print_help(char **argv)
Definition: component.c:38
test_pass(__FILE__, NULL, 0)
int int argc
Definition: iozone.c:1609
int TESTS_QUIET
Definition: test_utils.c:11
char ** argv
Definition: iozone.c:1610
char disabled_reason[PAPI_MAX_STR_LEN]
Definition: papi.h:633
test_fail(__FILE__, __LINE__,"PAPI_library_init", retval)
int PAPI_library_init(int version)
Definition: papi.c:497
int i
Definition: fileop.c:140
#define PAPI_PMU_MAX
Definition: papi.h:467
char * pmu_names[PAPI_PMU_MAX]
Definition: papi.h:647
char description[PAPI_MAX_STR_LEN]
Definition: papi.h:629
static void parse_args(int argc, char **argv, command_flags_t *f)
Definition: component.c:49
char version[PAPI_MIN_STR_LEN]
Definition: papi.h:630
ssize_t retval
Definition: libasync.c:338
#define PAPI_VER_CURRENT
Definition: papi.h:223
int main(int argc, char **argv)
List all appio events codes and names.
void exit()
int PAPI_set_debug(int level)
Definition: papi.c:3070