PAPI  5.3.2.0
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
avail.c
Go to the documentation of this file.
1 
31 #include "papi_test.h"
32 extern int TESTS_QUIET; /* Declared in test_utils.c */
33 
34 static char *
36 {
37  if ( strlen( info->derived ) == 0 )
38  return ( "No" );
39  else if ( strcmp( info->derived, "NOT_DERIVED" ) == 0 )
40  return ( "No" );
41  else if ( strcmp( info->derived, "DERIVED_CMPD" ) == 0 )
42  return ( "No" );
43  else
44  return ( "Yes" );
45 }
46 
47 static void
48 print_help( char **argv )
49 {
50  printf( "Usage: %s [options]\n", argv[0] );
51  printf( "Options:\n\n" );
52  printf( "General command options:\n" );
53  printf( "\t-a, --avail Display only available preset events\n" );
54  printf
55  ( "\t-d, --detail Display detailed information about all preset events\n" );
56  printf
57  ( "\t-e EVENTNAME Display detail information about specified preset or native event\n" );
58  printf( "\t-h, --help Print this help message\n" );
59  printf( "\nEvent filtering options:\n" );
60  printf( "\t--br Display branch related PAPI preset events\n" );
61  printf( "\t--cache Display cache related PAPI preset events\n" );
62  printf( "\t--cnd Display conditional PAPI preset events\n" );
63  printf
64  ( "\t--fp Display Floating Point related PAPI preset events\n" );
65  printf
66  ( "\t--ins Display instruction related PAPI preset events\n" );
67  printf( "\t--idl Display Stalled or Idle PAPI preset events\n" );
68  printf
69  ( "\t--l1 Display level 1 cache related PAPI preset events\n" );
70  printf
71  ( "\t--l2 Display level 2 cache related PAPI preset events\n" );
72  printf
73  ( "\t--l3 Display level 3 cache related PAPI preset events\n" );
74  printf( "\t--mem Display memory related PAPI preset events\n" );
75  printf( "\t--msc Display miscellaneous PAPI preset events\n" );
76  printf
77  ( "\t--tlb Display Translation Lookaside Buffer PAPI preset events\n" );
78  printf( "\n" );
79  printf
80  ( "This program provides information about PAPI preset and native events.\n" );
81  printf( "PAPI preset event filters can be combined in a logical OR.\n" );
82 }
83 
84 static int
86 {
87  char *pmask;
88 
89  if ( ( pmask = strchr( info->symbol, ':' ) ) == NULL ) {
90  return ( 0 );
91  }
92  memmove( info->symbol, pmask, ( strlen( pmask ) + 1 ) * sizeof ( char ) );
93  pmask = strchr( info->long_descr, ':' );
94  if ( pmask == NULL )
95  info->long_descr[0] = 0;
96  else
97  memmove( info->long_descr, pmask + sizeof ( char ),
98  ( strlen( pmask ) + 1 ) * sizeof ( char ) );
99  return ( 1 );
100 }
101 
102 int
103 main( int argc, char **argv )
104 {
105  int args, j, k;
106  int retval;
107  unsigned int filter = 0;
108  int print_event_info = 0;
109  char *name = NULL;
110  int print_avail_only = 0;
111  int print_tabular = 1;
112  PAPI_event_info_t info;
113  const PAPI_hw_info_t *hwinfo = NULL;
114  int tot_count = 0;
115  int avail_count = 0;
116  int deriv_count = 0;
117  int event_code;
118 
119  PAPI_event_info_t n_info;
120 
121  /* Set TESTS_QUIET variable */
122 
123  tests_quiet( argc, argv );
124 
125  /* Parse command line arguments */
126 
127  for( args = 1; args < argc; args++ ) {
128  if ( strstr( argv[args], "-e" ) ) {
129  print_event_info = 1;
130  name = argv[args + 1];
131  if ( ( name == NULL ) || ( strlen( name ) == 0 ) ) {
132  print_help( argv );
133  exit( 1 );
134  }
135  } else if ( strstr( argv[args], "-a" ) )
136  print_avail_only = PAPI_PRESET_ENUM_AVAIL;
137  else if ( strstr( argv[args], "-d" ) )
138  print_tabular = 0;
139  else if ( strstr( argv[args], "-h" ) ) {
140  print_help( argv );
141  exit( 1 );
142  } else if ( strstr( argv[args], "--br" ) )
143  filter |= PAPI_PRESET_BIT_BR;
144  else if ( strstr( argv[args], "--cache" ) )
145  filter |= PAPI_PRESET_BIT_CACH;
146  else if ( strstr( argv[args], "--cnd" ) )
147  filter |= PAPI_PRESET_BIT_CND;
148  else if ( strstr( argv[args], "--fp" ) )
149  filter |= PAPI_PRESET_BIT_FP;
150  else if ( strstr( argv[args], "--ins" ) )
151  filter |= PAPI_PRESET_BIT_INS;
152  else if ( strstr( argv[args], "--idl" ) )
153  filter |= PAPI_PRESET_BIT_IDL;
154  else if ( strstr( argv[args], "--l1" ) )
155  filter |= PAPI_PRESET_BIT_L1;
156  else if ( strstr( argv[args], "--l2" ) )
157  filter |= PAPI_PRESET_BIT_L2;
158  else if ( strstr( argv[args], "--l3" ) )
159  filter |= PAPI_PRESET_BIT_L3;
160  else if ( strstr( argv[args], "--mem" ) )
161  filter |= PAPI_PRESET_BIT_BR;
162  else if ( strstr( argv[args], "--msc" ) )
163  filter |= PAPI_PRESET_BIT_MSC;
164  else if ( strstr( argv[args], "--tlb" ) )
165  filter |= PAPI_PRESET_BIT_TLB;
166  }
167 
168  if ( filter == 0 ) {
169  filter = ( unsigned int ) ( -1 );
170  }
171 
172  /* Init PAPI */
173 
175  if ( retval != PAPI_VER_CURRENT ) {
176  test_fail( __FILE__, __LINE__, "PAPI_library_init", retval );
177  }
178 
179  if ( !TESTS_QUIET ) {
180  retval = PAPI_set_debug( PAPI_VERB_ECONT );
181  if ( retval != PAPI_OK ) {
182  test_fail( __FILE__, __LINE__, "PAPI_set_debug", retval );
183  }
184 
185  retval=papi_print_header("Available events and hardware information.\n",
186  &hwinfo );
187  if ( retval != PAPI_OK ) {
188  test_fail( __FILE__, __LINE__, "PAPI_get_hardware_info", 2 );
189  }
190 
191  /* Code for info on just one event */
192 
193  if ( print_event_info ) {
194 
195  if ( PAPI_event_name_to_code( name, &event_code ) == PAPI_OK ) {
196  if ( PAPI_get_event_info( event_code, &info ) == PAPI_OK ) {
197 
198  if ( event_code & PAPI_PRESET_MASK ) {
199  printf( "%-30s%s\n%-30s%#-10x\n%-30s%d\n",
200  "Event name:", info.symbol, "Event Code:",
201  info.event_code, "Number of Native Events:",
202  info.count );
203  printf( "%-29s|%s|\n%-29s|%s|\n%-29s|%s|\n",
204  "Short Description:", info.short_descr,
205  "Long Description:", info.long_descr,
206  "Developer's Notes:", info.note );
207  printf( "%-29s|%s|\n%-29s|%s|\n", "Derived Type:",
208  info.derived, "Postfix Processing String:",
209  info.postfix );
210 
211  for( j = 0; j < ( int ) info.count; j++ ) {
212  printf( " Native Code[%d]: %#x |%s|\n", j,
213  info.code[j], info.name[j] );
214  PAPI_get_event_info( (int) info.code[j], &n_info );
215  printf(" Number of Register Values: %d\n", n_info.count );
216  for( k = 0; k < ( int ) n_info.count; k++ ) {
217  printf( " Register[%2d]: %#08x |%s|\n", k,
218  n_info.code[k], n_info.name[k] );
219  }
220  printf( " Native Event Description: |%s|\n\n",
221  n_info.long_descr );
222  }
223  } else { /* must be a native event code */
224  printf( "%-30s%s\n%-30s%#-10x\n%-30s%d\n",
225  "Event name:", info.symbol, "Event Code:",
226  info.event_code, "Number of Register Values:",
227  info.count );
228  printf( "%-29s|%s|\n", "Description:", info.long_descr );
229  for ( k = 0; k < ( int ) info.count; k++ ) {
230  printf( " Register[%2d]: %#08x |%s|\n", k,
231  info.code[k], info.name[k] );
232  }
233 
234  /* if unit masks exist but none are specified, process all */
235  if ( !strchr( name, ':' ) ) {
236  if ( 1 ) {
237  if ( PAPI_enum_event( &event_code, PAPI_NTV_ENUM_UMASKS ) == PAPI_OK ) {
238  printf( "\nUnit Masks:\n" );
239  do {
240  retval = PAPI_get_event_info(event_code, &info );
241  if ( retval == PAPI_OK ) {
242  if ( parse_unit_masks( &info ) ) {
243  printf( "%-29s|%s|%s|\n",
244  " Mask Info:", info.symbol,
245  info.long_descr );
246  for ( k = 0; k < ( int ) info.count;k++ ) {
247  printf( " Register[%2d]: %#08x |%s|\n",
248  k, info.code[k], info.name[k] );
249  }
250  }
251  }
252  } while ( PAPI_enum_event( &event_code,
254  }
255  }
256  }
257  }
258  }
259  } else {
260  printf( "Sorry, an event by the name '%s' could not be found.\n"
261  " Is it typed correctly?\n\n", name );
262  }
263  } else {
264 
265  /* Print *ALL* Events */
266 
267  /* For consistency, always ASK FOR the first event */
268  event_code = 0 | PAPI_PRESET_MASK;
269  PAPI_enum_event( &event_code, PAPI_ENUM_FIRST );
270 
271  if ( print_tabular ) {
272  printf( " Name Code " );
273  if ( !print_avail_only ) {
274  printf( "Avail " );
275  }
276  printf( "Deriv Description (Note)\n" );
277  } else {
278  printf( "%-13s%-11s%-8s%-16s\n |Long Description|\n"
279  " |Developer's Notes|\n |Derived|\n |PostFix|\n"
280  " Native Code[n]: <hex> |name|\n",
281  "Symbol", "Event Code", "Count", "|Short Description|" );
282  }
283  do {
284  if ( PAPI_get_event_info( event_code, &info ) == PAPI_OK ) {
285  if ( print_tabular ) {
286  if ( filter & info.event_type ) {
287  if ( print_avail_only ) {
288  if ( info.count ) {
289  printf( "%-13s%#x %-5s%s",
290  info.symbol,
291  info.event_code,
292  is_derived( &info ), info.long_descr );
293  }
294  if ( info.note[0] ) {
295  printf( " (%s)", info.note );
296  }
297  printf( "\n" );
298  } else {
299  printf( "%-13s%#x %-6s%-4s %s",
300  info.symbol,
301  info.event_code,
302  ( info.count ? "Yes" : "No" ),
303  is_derived( &info ), info.long_descr );
304  if ( info.note[0] ) {
305  printf( " (%s)", info.note );
306  }
307  printf( "\n" );
308  }
309  tot_count++;
310  if ( info.count ) {
311  avail_count++;
312  }
313  if ( !strcmp( is_derived( &info ), "Yes" ) ) {
314  deriv_count++;
315  }
316  }
317  } else {
318  if ( ( print_avail_only && info.count ) ||
319  ( print_avail_only == 0 ) ) {
320  printf( "%s\t%#x\t%d\t|%s|\n |%s|\n"
321  " |%s|\n |%s|\n |%s|\n",
322  info.symbol, info.event_code, info.count,
323  info.short_descr, info.long_descr, info.note,
324  info.derived, info.postfix );
325  for ( j = 0; j < ( int ) info.count; j++ ) {
326  printf( " Native Code[%d]: %#x |%s|\n", j,
327  info.code[j], info.name[j] );
328  }
329  }
330  tot_count++;
331  if ( info.count ) {
332  avail_count++;
333  }
334  if ( !strcmp( is_derived( &info ), "Yes" ) ) {
335  deriv_count++;
336  }
337  }
338  }
339  } while (PAPI_enum_event( &event_code, print_avail_only ) == PAPI_OK);
340  }
341  printf( "----------------------------------------"
342  "---------------------------------\n" );
343  if ( !print_event_info ) {
344  if ( print_avail_only ) {
345  printf( "Of %d available events, %d ", avail_count, deriv_count );
346  } else {
347  printf( "Of %d possible events, %d are available, of which %d ",
348  tot_count, avail_count, deriv_count );
349  }
350  if ( deriv_count == 1 ) {
351  printf( "is derived.\n\n" );
352  } else {
353  printf( "are derived.\n\n" );
354  }
355  }
356  }
357  test_pass( __FILE__, NULL, 0 );
358  exit( 1 );
359 
360 }
unsigned int count
Definition: papi.h:982
#define PAPI_PRESET_BIT_TLB
Definition: papi.h:519
#define PAPI_PRESET_BIT_L3
Definition: papi.h:518
Hardware info structure.
Definition: papi.h:775
int papi_print_header(char *prompt, const PAPI_hw_info_t **hwinfo)
Definition: test_utils.c:21
#define PAPI_PRESET_BIT_L1
Definition: papi.h:516
char long_descr[PAPI_HUGE_STR_LEN]
Definition: papi.h:964
int PAPI_enum_event(int *EventCode, int modifier)
Definition: papi.c:1148
#define PAPI_VERB_ECONT
Definition: fpapi.h:39
char symbol[PAPI_HUGE_STR_LEN]
Definition: papi.h:961
return PAPI_OK
Definition: linux-nvml.c:458
tests_quiet(argc, argv)
#define PAPI_PRESET_MASK
char note[PAPI_HUGE_STR_LEN]
Definition: papi.h:1008
#define printf
Definition: papi_test.h:125
test_pass(__FILE__, NULL, 0)
int int argc
Definition: iozone.c:1609
int PAPI_get_event_info(int EventCode, PAPI_event_info_t *info)
Definition: papi.c:844
int TESTS_QUIET
Definition: test_utils.c:11
char ** argv
Definition: iozone.c:1610
test_fail(__FILE__, __LINE__,"PAPI_library_init", retval)
int PAPI_library_init(int version)
Definition: papi.c:495
int k
Definition: iozone.c:19136
char short_descr[PAPI_MIN_STR_LEN]
Definition: papi.h:962
#define PAPI_VER_CURRENT
Definition: fpapi.h:14
unsigned int event_type
Definition: papi.h:987
#define PAPI_PRESET_BIT_MSC
Definition: papi.h:509
#define PAPI_PRESET_BIT_BR
Definition: papi.h:512
static void print_help(char **argv)
Definition: avail.c:48
static char * is_derived(PAPI_event_info_t *info)
Definition: avail.c:35
#define PAPI_PRESET_BIT_INS
Definition: papi.h:510
unsigned int code[PAPI_MAX_INFO_TERMS]
Definition: papi.h:998
again struct sockaddr sizeof(struct sockaddr_in))
int PAPI_event_name_to_code(char *in, int *out)
Definition: papi.c:1008
char * name
Definition: iozone.c:23648
#define PAPI_PRESET_BIT_FP
Definition: papi.h:520
int
Definition: iozone.c:18528
#define PAPI_PRESET_BIT_CACH
Definition: papi.h:515
#define PAPI_PRESET_BIT_CND
Definition: papi.h:513
#define PAPI_PRESET_BIT_IDL
Definition: papi.h:511
long j
Definition: iozone.c:19135
unsigned int event_code
Definition: papi.h:959
char derived[PAPI_MIN_STR_LEN]
Definition: papi.h:990
ssize_t retval
Definition: libasync.c:338
char postfix[PAPI_2MAX_STR_LEN]
Definition: papi.h:993
int main(int argc, char **argv)
List all appio events codes and names.
static int parse_unit_masks(PAPI_event_info_t *info)
Definition: avail.c:85
void exit()
int PAPI_set_debug(int level)
Definition: papi.c:3037
char name[PAPI_MAX_INFO_TERMS][PAPI_2MAX_STR_LEN]
Definition: papi.h:1004
#define PAPI_PRESET_BIT_L2
Definition: papi.h:517