PAPI  5.7.0.0
papi_component_avail.c
Go to the documentation of this file.
1 
25 #include <stdio.h>
26 #include <stdlib.h>
27 #include <string.h>
28 
29 #include "papi.h"
30 
31 #include "print_header.h"
32 
33 #define EVT_LINE 80
34 
35 typedef struct command_flags
36 {
37  int help;
38  int details;
39  int named;
40  char *name;
42 
43 static void
44 print_help( char **argv )
45 {
46  printf( "This is the PAPI component avail program.\n" );
47  printf( "It provides availability of installed PAPI components.\n" );
48  printf( "Usage: %s [options]\n", argv[0] );
49  printf( "Options:\n\n" );
50  printf( " --help, -h print this help message\n" );
51  printf( " -d print detailed information on each component\n" );
52 }
53 
54 static void
55 parse_args( int argc, char **argv, command_flags_t * f )
56 {
57  int i;
58 
59  /* Look for all currently defined commands */
60  memset( f, 0, sizeof ( command_flags_t ) );
61  for ( i = 1; i < argc; i++ ) {
62  if ( !strcmp( argv[i], "-d" ) ) {
63  f->details = 1;
64  } else if ( !strcmp( argv[i], "-h" ) || !strcmp( argv[i], "--help" ) )
65  f->help = 1;
66  else
67  printf( "%s is not supported\n", argv[i] );
68  }
69 
70  /* if help requested, print and bail */
71  if ( f->help ) {
72  print_help( argv );
73  exit( 1 );
74  }
75 
76 }
77 
78 int
79 main( int argc, char **argv )
80 {
81  int i;
82  int retval;
83  const PAPI_hw_info_t *hwinfo = NULL;
84  const PAPI_component_info_t* cmpinfo;
85  command_flags_t flags;
86  int numcmp, cid;
87 
88  /* Initialize before parsing the input arguments */
90  if ( retval != PAPI_VER_CURRENT ) {
91  fprintf(stderr,"Error! PAPI_library_init\n");
92  return retval;
93  }
94 
95  parse_args( argc, argv, &flags );
96 
98  if ( retval != PAPI_OK ) {
99  fprintf(stderr,"Error! PAPI_set_debug\n");
100  return retval;
101  }
102 
103  retval = papi_print_header( "Available components and "
104  "hardware information.\n", &hwinfo );
105  if ( retval != PAPI_OK ) {
106  fprintf(stderr,"Error! PAPI_get_ahrdware_info\n");
107  return 2;
108  }
109 
110  /* Compiled-in Components */
111  numcmp = PAPI_num_components( );
112 
113  printf("Compiled-in components:\n");
114  for ( cid = 0; cid < numcmp; cid++ ) {
115  cmpinfo = PAPI_get_component_info( cid );
116 
117  printf( "Name: %-23s %s\n", cmpinfo->name ,cmpinfo->description);
118 
119  if (cmpinfo->disabled) {
120  printf(" \\-> Disabled: %s\n",cmpinfo->disabled_reason);
121  }
122 
123  if ( flags.details ) {
124  printf( " %-23s Version:\t\t\t%s\n", " ", cmpinfo->version );
125  printf( " %-23s Number of native events:\t%d\n", " ", cmpinfo->num_native_events);
126  printf( " %-23s Number of preset events:\t%d\n", " ", cmpinfo->num_preset_events);
127  printf("\n");
128  }
129  }
130 
131  printf("\nActive components:\n");
132  numcmp = PAPI_num_components( );
133 
134  for ( cid = 0; cid < numcmp; cid++ ) {
135  cmpinfo = PAPI_get_component_info( cid );
136  if (cmpinfo->disabled) continue;
137 
138  printf( "Name: %-23s %s\n", cmpinfo->name ,cmpinfo->description);
139  printf( " %-23s Native: %d, Preset: %d, Counters: %d\n",
140  " ", cmpinfo->num_native_events, cmpinfo->num_preset_events, cmpinfo->num_cntrs);
141  printf( " %-23s PMUs supported: ", " ");
142  int line_len = 49;
143  for (i=0 ; i<PAPI_PMU_MAX ; i++) {
144  if (cmpinfo->pmu_names[i] == NULL) continue;
145 
146  if (line_len + strlen(cmpinfo->pmu_names[i]) > 130) {
147  printf("\n %-23s ", " ");
148  line_len = 49;
149  } else {
150  line_len += strlen(cmpinfo->pmu_names[i]);
151  }
152  // if it is not the first entry on a line, separate the names
153  if ((i != 0) && (line_len > 50)) {
154  printf(", ");
155  }
156  printf("%s", cmpinfo->pmu_names[i]);
157  }
158  printf("\n\n");
159 
160  if ( flags.details ) {
161  printf( " %-23s Version:\t\t\t%s\n", " ", cmpinfo->version );
162  printf( " %-23s Fast counter read:\t\t%d\n", " ", cmpinfo->fast_counter_read);
163  printf("\n");
164  }
165  }
166 
167 
168  printf
169  ( "\n--------------------------------------------------------------------------------\n" );
170 
171  return 0;
172 }
#define PAPI_OK
Definition: fpapi.h:105
char disabled_reason[PAPI_MAX_STR_LEN]
Definition: papi.h:637
double f(double a)
Definition: cpi.c:23
const PAPI_component_info_t * PAPI_get_component_info(int cidx)
Definition: papi.c:796
Hardware info structure.
Definition: papi.h:781
int PAPI_num_components(void)
Definition: papi.c:4387
#define PAPI_VER_CURRENT
Definition: fpapi.h:14
int retval
Definition: zero_fork.c:53
Return codes and api definitions.
int PAPI_library_init(int version)
Definition: papi.c:500
static void print_help(char **argv)
#define PAPI_PMU_MAX
Definition: papi.h:470
static void parse_args(int argc, char **argv, command_flags_t *f)
unsigned int fast_counter_read
Definition: papi.h:660
#define PAPI_VERB_ECONT
Definition: fpapi.h:39
int main(int argc, char **argv)
char name[PAPI_MAX_STR_LEN]
Definition: papi.h:630
char description[PAPI_MAX_STR_LEN]
Definition: papi.h:633
char * pmu_names[PAPI_PMU_MAX]
Definition: papi.h:651
char version[PAPI_MIN_STR_LEN]
Definition: papi.h:634
void exit()
int PAPI_set_debug(int level)
Definition: papi.c:3126
int i
Definition: fileop.c:140