PAPI  5.3.2.0
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
native_avail.c File Reference
Include dependency graph for native_avail.c:

Go to the source code of this file.

Data Structures

struct  command_flags_t
 

Macros

#define EVT_LINE   80
 

Functions

static void print_help (char **argv)
 
static int no_str_arg (char *arg)
 
static void parse_args (int argc, char **argv, command_flags_t *f)
 
static void space_pad (char *str, int spaces)
 
static void print_event (PAPI_event_info_t *info, int offset)
 
static int parse_unit_masks (PAPI_event_info_t *info)
 
int main (int argc, char **argv)
 

Macro Definition Documentation

#define EVT_LINE   80

Definition at line 47 of file native_avail.c.

Function Documentation

int main ( int  argc,
char **  argv 
)

Definition at line 229 of file native_avail.c.

230 {
231  int i, j = 0, k;
232  int retval;
233  PAPI_event_info_t info;
234  const PAPI_hw_info_t *hwinfo = NULL;
236  int enum_modifier;
237  int numcmp, cid;
238 
239  /* Set TESTS_QUIET variable */
240  tests_quiet( argc, argv );
241 
242  /* Initialize before parsing the input arguments */
244  if ( retval != PAPI_VER_CURRENT ) {
245  test_fail( __FILE__, __LINE__, "PAPI_library_init", retval );
246  }
247 
248  /* Parse the command-line arguments */
249  parse_args( argc, argv, &flags );
250 
251  /* Set enum modifier mask */
252  if ( flags.dear )
253  enum_modifier = PAPI_NTV_ENUM_DEAR;
254  else if ( flags.darr )
255  enum_modifier = PAPI_NTV_ENUM_DARR;
256  else if ( flags.iear )
257  enum_modifier = PAPI_NTV_ENUM_IEAR;
258  else if ( flags.iarr )
259  enum_modifier = PAPI_NTV_ENUM_IARR;
260  else if ( flags.opcm )
261  enum_modifier = PAPI_NTV_ENUM_OPCM;
262  else
263  enum_modifier = PAPI_ENUM_EVENTS;
264 
265 
266  if ( !TESTS_QUIET ) {
267  retval = PAPI_set_debug( PAPI_VERB_ECONT );
268  if ( retval != PAPI_OK ) {
269  test_fail( __FILE__, __LINE__, "PAPI_set_debug", retval );
270  }
271  }
272 
273  retval = papi_print_header( "Available native events and hardware information.\n", &hwinfo );
274  if ( retval != PAPI_OK ) {
275  test_fail( __FILE__, __LINE__, "PAPI_get_hardware_info", 2 );
276  }
277 
278 
279  /* Do this code if the event name option was specified on the commandline */
280  if ( flags.named ) {
281  if ( PAPI_event_name_to_code( flags.name, &i ) == PAPI_OK ) {
282  if ( PAPI_get_event_info( i, &info ) == PAPI_OK ) {
283  printf( "%-30s%s\n",
284  "Event name:", info.symbol);
285  printf( "%-29s|%s|\n", "Description:", info.long_descr );
286 
287  /* if unit masks exist but none specified, process all */
288  if ( !strchr( flags.name, ':' ) ) {
289  if ( PAPI_enum_event( &i, PAPI_NTV_ENUM_UMASKS ) == PAPI_OK ) {
290  printf( "\nUnit Masks:\n" );
291  do {
292  retval = PAPI_get_event_info( i, &info );
293  if ( retval == PAPI_OK ) {
294  if ( parse_unit_masks( &info ) ) {
295  printf( "%-29s|%s|%s|\n", " Mask Info:",
296  info.symbol, info.long_descr );
297  }
298  }
299  } while ( PAPI_enum_event( &i, PAPI_NTV_ENUM_UMASKS ) == PAPI_OK );
300  }
301  }
302  }
303  } else {
304  printf("Sorry, an event by the name '%s' could not be found.\n",
305  flags.name);
306  printf("Is it typed correctly?\n\n");
307  exit( 1 );
308  }
309  }
310  else {
311 
312  /* Print *ALL* available events */
313 
314  numcmp = PAPI_num_components( );
315 
316  j = 0;
317 
318  for ( cid = 0; cid < numcmp; cid++ ) {
319 
320  const PAPI_component_info_t *component;
321  component=PAPI_get_component_info(cid);
322 
323  /* Skip disabled components */
324  if (component->disabled) continue;
325 
326  printf( "===============================================================================\n" );
327  printf( " Native Events in Component: %s\n",component->name);
328  printf( "===============================================================================\n" );
329 
330  /* Always ASK FOR the first event */
331  /* Don't just assume it'll be the first numeric value */
332  i = 0 | PAPI_NATIVE_MASK;
333 
334  retval=PAPI_enum_cmp_event( &i, PAPI_ENUM_FIRST, cid );
335 
336  if (retval==PAPI_OK)
337 
338  do {
339  memset( &info, 0, sizeof ( info ) );
340  retval = PAPI_get_event_info( i, &info );
341 
342  /* This event may not exist */
343  if ( retval != PAPI_OK )
344  continue;
345 
346  /* Bail if event name doesn't contain include string */
347  if ( flags.include ) {
348  if ( !strstr( info.symbol, flags.istr ) ) {
349  continue;
350  }
351  }
352 
353  /* Bail if event name does contain exclude string */
354  if ( flags.xclude ) {
355  if ( strstr( info.symbol, flags.xstr ) )
356  continue;
357  }
358 
359  /* count only events that are actually processed */
360  j++;
361 
362  print_event( &info, 0 );
363 
364  if (flags.details) {
365  if (info.units[0]) printf( "| Units: %-67s|\n",
366  info.units );
367  }
368 
369 /* modifier = PAPI_NTV_ENUM_GROUPS returns event codes with a
370  groups id for each group in which this
371  native event lives, in bits 16 - 23 of event code
372  terminating with PAPI_ENOEVNT at the end of the list.
373 */
374 
375  /* This is an IBM Power issue */
376  if ( flags.groups ) {
377  k = i;
378  if ( PAPI_enum_cmp_event( &k, PAPI_NTV_ENUM_GROUPS, cid ) == PAPI_OK ) {
379  printf( "Groups: " );
380  do {
381  printf( "%4d", ( ( k & PAPI_NTV_GROUP_AND_MASK ) >>
382  PAPI_NTV_GROUP_SHIFT ) - 1 );
383  } while ( PAPI_enum_cmp_event( &k, PAPI_NTV_ENUM_GROUPS, cid ) ==PAPI_OK );
384  printf( "\n" );
385  }
386  }
387 
388  /* Print umasks */
389  /* components that don't have them can just ignore */
390 
391  if ( flags.umask ) {
392  k = i;
393  if ( PAPI_enum_cmp_event( &k, PAPI_NTV_ENUM_UMASKS, cid ) == PAPI_OK ) {
394  do {
395  retval = PAPI_get_event_info( k, &info );
396  if ( retval == PAPI_OK ) {
397  if ( parse_unit_masks( &info ) )
398  print_event( &info, 2 );
399  }
400  } while ( PAPI_enum_cmp_event( &k, PAPI_NTV_ENUM_UMASKS, cid ) == PAPI_OK );
401  }
402 
403  }
404  printf( "--------------------------------------------------------------------------------\n" );
405 
406  } while (PAPI_enum_cmp_event( &i, enum_modifier, cid ) == PAPI_OK );
407  }
408 
409 
410  printf("\n");
411  printf( "Total events reported: %d\n", j );
412  }
413 
414  test_pass( __FILE__, NULL, 0 );
415  exit( 0 );
416 }
char name[PAPI_MAX_STR_LEN]
Definition: papi.h:625
memset(eventId, 0, size)
#define PAPI_NATIVE_MASK
const PAPI_component_info_t * PAPI_get_component_info(int cidx)
Definition: papi.c:805
Hardware info structure.
Definition: papi.h:775
long long flags
Definition: iozone.c:12330
int papi_print_header(char *prompt, const PAPI_hw_info_t **hwinfo)
Definition: test_utils.c:21
char long_descr[PAPI_HUGE_STR_LEN]
Definition: papi.h:964
int PAPI_num_components(void)
Definition: papi.c:4285
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 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
static void parse_args(int argc, char **argv, command_flags_t *f)
Definition: native_avail.c:96
test_fail(__FILE__, __LINE__,"PAPI_library_init", retval)
int PAPI_library_init(int version)
Definition: papi.c:495
int i
Definition: fileop.c:140
#define PAPI_NTV_GROUP_SHIFT
Definition: papi.h:523
int k
Definition: iozone.c:19136
static void print_event(PAPI_event_info_t *info, int offset)
Definition: native_avail.c:170
#define PAPI_VER_CURRENT
Definition: fpapi.h:14
int PAPI_enum_cmp_event(int *EventCode, int modifier, int cidx)
Definition: papi.c:1311
int PAPI_event_name_to_code(char *in, int *out)
Definition: papi.c:1008
#define PAPI_NTV_GROUP_AND_MASK
Definition: papi.h:522
static int parse_unit_masks(PAPI_event_info_t *info)
Definition: native_avail.c:200
long j
Definition: iozone.c:19135
ssize_t retval
Definition: libasync.c:338
void exit()
char units[PAPI_MIN_STR_LEN]
Definition: papi.h:970
int PAPI_set_debug(int level)
Definition: papi.c:3037

Here is the call graph for this function:

static int no_str_arg ( char *  arg)
static

Definition at line 90 of file native_avail.c.

91 {
92  return ( ( arg == NULL ) || ( strlen( arg ) == 0 ) || ( arg[0] == '-' ) );
93 }

Here is the caller graph for this function:

static void parse_args ( int  argc,
char **  argv,
command_flags_t f 
)
static

Definition at line 96 of file native_avail.c.

97 {
98 
99  int i;
100 
101  /* Look for all currently defined commands */
102  memset( f, 0, sizeof ( command_flags_t ) );
103  f->umask = 1;
104  f->groups = 1;
105 
106  for ( i = 1; i < argc; i++ ) {
107  if ( !strcmp( argv[i], "--darr" ) )
108  f->darr = 1;
109  else if ( !strcmp( argv[i], "--dear" ) )
110  f->dear = 1;
111  else if ( !strcmp( argv[i], "--iarr" ) )
112  f->iarr = 1;
113  else if ( !strcmp( argv[i], "--iear" ) )
114  f->iear = 1;
115  else if ( !strcmp( argv[i], "--opcm" ) )
116  f->opcm = 1;
117  else if ( !strcmp( argv[i], "--noumasks" ) )
118  f->umask = 0;
119  else if ( !strcmp( argv[i], "--nogroups" ) )
120  f->groups = 0;
121  else if ( !strcmp( argv[i], "-d" ) )
122  f->details = 1;
123  else if ( !strcmp( argv[i], "-e" ) ) {
124  f->named = 1;
125  i++;
126  f->name = argv[i];
127  if ( i >= argc || no_str_arg( f->name ) ) {
128  printf( "Invalid argument for -e\n");
129  exit(1);
130  }
131  } else if ( !strcmp( argv[i], "-i" ) ) {
132  f->include = 1;
133  i++;
134  f->istr = argv[i];
135  if ( i >= argc || no_str_arg( f->istr ) ) {
136  printf( "Invalid argument for -i\n");
137  exit(1);
138  }
139  } else if ( !strcmp( argv[i], "-x" ) ) {
140  f->xclude = 1;
141  i++;
142  f->xstr = argv[i];
143  if ( i >= argc || no_str_arg( f->xstr ) ) {
144  printf( "Invalid argument for -x\n");
145  exit(1);
146  }
147  } else if ( !strcmp( argv[i], "-h" ) || !strcmp( argv[i], "--help" ) )
148  f->help = 1;
149  else {
150  printf( "%s is not supported\n", argv[i] );
151  exit(1);
152  }
153  }
154 
155  /* if help requested, print and bail */
156  if ( f->help ) {
157  print_help( argv);
158  exit( 1 );
159  }
160 }
memset(eventId, 0, size)
#define printf
Definition: papi_test.h:125
static int no_str_arg(char *arg)
Definition: native_avail.c:90
int int argc
Definition: iozone.c:1609
char ** argv
Definition: iozone.c:1610
int i
Definition: fileop.c:140
static void print_help(char **argv)
Definition: native_avail.c:67
void exit()

Here is the call graph for this function:

Here is the caller graph for this function:

static int parse_unit_masks ( PAPI_event_info_t info)
static

Definition at line 200 of file native_avail.c.

201 {
202  char *pmask,*ptr;
203 
204  /* handle the PAPI component-style events which have a component:::event type */
205  if ((ptr=strstr(info->symbol, ":::"))) {
206  ptr+=3;
207  /* handle libpfm4-style events which have a pmu::event type event name */
208  } else if ((ptr=strstr(info->symbol, "::"))) {
209  ptr+=2;
210  }
211  else {
212  ptr=info->symbol;
213  }
214 
215  if ( ( pmask = strchr( ptr, ':' ) ) == NULL ) {
216  return ( 0 );
217  }
218  memmove( info->symbol, pmask, ( strlen( pmask ) + 1 ) * sizeof ( char ) );
219  pmask = strchr( info->long_descr, ':' );
220  if ( pmask == NULL )
221  info->long_descr[0] = 0;
222  else
223  memmove( info->long_descr, pmask + sizeof ( char ),
224  ( strlen( pmask ) + 1 ) * sizeof ( char ) );
225  return ( 1 );
226 }
char long_descr[PAPI_HUGE_STR_LEN]
Definition: papi.h:964
char symbol[PAPI_HUGE_STR_LEN]
Definition: papi.h:961
again struct sockaddr sizeof(struct sockaddr_in))
char * ptr
Definition: iozone.c:23586

Here is the call graph for this function:

Here is the caller graph for this function:

static void print_event ( PAPI_event_info_t info,
int  offset 
)
static

Definition at line 170 of file native_avail.c.

171 {
172  unsigned int i, j = 0;
173  char str[EVT_LINE + EVT_LINE];
174 
175  /* indent by offset */
176  if ( offset ) {
177  printf( "| %-73s|\n", info->symbol );
178  }
179  else {
180  printf( "| %-77s|\n", info->symbol );
181  }
182 
183  while ( j <= strlen( info->long_descr ) ) {
184  i = EVT_LINE - 12 - 2;
185  if ( i > 0 ) {
186  str[0] = 0;
187  strcat(str,"| " );
188  space_pad( str, 11 );
189  strncat( str, &info->long_descr[j], i );
190  j += i;
191  i = ( unsigned int ) strlen( str );
192  space_pad( str, EVT_LINE - ( int ) i - 1 );
193  strcat( str, "|" );
194  }
195  printf( "%s\n", str );
196  }
197 }
off64_t offset
Definition: iozone.c:1279
char long_descr[PAPI_HUGE_STR_LEN]
Definition: papi.h:964
char symbol[PAPI_HUGE_STR_LEN]
Definition: papi.h:961
static void space_pad(char *str, int spaces)
Definition: native_avail.c:163
#define printf
Definition: papi_test.h:125
int i
Definition: fileop.c:140
#define EVT_LINE
Definition: native_avail.c:47
strcat(command, mountname)
int
Definition: iozone.c:18528
long j
Definition: iozone.c:19135

Here is the call graph for this function:

Here is the caller graph for this function:

static void print_help ( char **  argv)
static

Definition at line 67 of file native_avail.c.

68 {
69  printf( "This is the PAPI native avail program.\n" );
70  printf( "It provides availability and detail information for PAPI native events.\n" );
71  printf( "Usage: %s [options]\n", argv[0] );
72  printf( "\nOptions:\n" );
73  printf( " --help, -h print this help message\n" );
74  printf( " -d display detailed information about native events\n" );
75  printf( " -e EVENTNAME display detailed information about named native event\n" );
76  printf( " -i EVENTSTR include only event names that contain EVENTSTR\n" );
77  printf( " -x EVENTSTR exclude any event names that contain EVENTSTR\n" );
78  printf( " --noumasks suppress display of Unit Mask information\n" );
79  printf( "\nProcessor-specific options\n");
80  printf( " --darr display events supporting Data Address Range Restriction\n" );
81  printf( " --dear display Data Event Address Register events only\n" );
82  printf( " --iarr display events supporting Instruction Address Range Restriction\n" );
83  printf( " --iear display Instruction Event Address Register events only\n" );
84  printf( " --opcm display events supporting OpCode Matching\n" );
85  printf( " --nogroups suppress display of Event grouping information\n" );
86  printf( "\n" );
87 }
#define printf
Definition: papi_test.h:125
char ** argv
Definition: iozone.c:1610

Here is the caller graph for this function:

static void space_pad ( char *  str,
int  spaces 
)
static

Definition at line 163 of file native_avail.c.

164 {
165  while ( spaces-- > 0 )
166  strcat( str, " " );
167 }
strcat(command, mountname)

Here is the call graph for this function:

Here is the caller graph for this function: