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

Go to the source code of this file.

Functions

static char * is_derived (PAPI_event_info_t *info)
 
static int add_remove_event (int EventSet, int evt)
 
static int show_event_info (int evt)
 
static int native (int cidx)
 
static int preset (void)
 
int main (int argc, char **argv)
 

Variables

int EventSet = PAPI_NULL
 
int retval
 

Function Documentation

static int add_remove_event ( int  EventSet,
int  evt 
)
static

Definition at line 44 of file event_chooser.c.

45 {
46  int retval;
47 
48  if ( ( retval = PAPI_add_event( EventSet, evt ) ) != PAPI_OK ) {
49  //printf( "Error adding event.\n" );
50  } else {
51  if ( ( retval = PAPI_remove_event( EventSet, evt ) ) != PAPI_OK ) {
52  printf( "Error removing event.\n" );
53  }
54  }
55  return retval;
56 }
int PAPI_add_event(int EventSet, int EventCode)
Definition: papi.c:1604
int PAPI_remove_event(int EventSet, int EventCode)
Definition: papi.c:1699
return PAPI_OK
Definition: linux-nvml.c:458
#define printf
Definition: papi_test.h:125
int EventSet
ssize_t retval
Definition: libasync.c:338

Here is the call graph for this function:

Here is the caller graph for this function:

static char* is_derived ( PAPI_event_info_t info)
static

Definition at line 31 of file event_chooser.c.

32 {
33  if ( strlen( info->derived ) == 0 )
34  return ( "No" );
35  else if ( strcmp( info->derived, "NOT_DERIVED" ) == 0 )
36  return ( "No" );
37  else if ( strcmp( info->derived, "DERIVED_CMPD" ) == 0 )
38  return ( "No" );
39  else
40  return ( "Yes" );
41 }
char derived[PAPI_MIN_STR_LEN]
Definition: papi.h:990

Here is the caller graph for this function:

int main ( int  argc,
char **  argv 
)

Definition at line 189 of file event_chooser.c.

190 {
191  int i;
192  int pevent,cevent;
193  int cidx;
194 
195  const PAPI_hw_info_t *hwinfo = NULL;
196 
197  if ( argc < 3 ) {
198  goto use_exit;
199  }
200 
201  /* Set TESTS_QUIET variable */
202  tests_quiet( argc, argv );
203 
204  /* Init PAPI library */
206  if ( retval != PAPI_VER_CURRENT ) {
207  test_fail( __FILE__, __LINE__, "PAPI_library_init", retval );
208  }
209 
211  if ( retval != PAPI_OK ) {
212  test_fail( __FILE__, __LINE__, "PAPI_set_debug", retval );
213  }
214 
215  retval = papi_print_header( "Event Chooser: Available events "
216  "which can be added with given events.\n",
217  &hwinfo );
218  if ( retval != PAPI_OK ) {
219  test_fail( __FILE__, __LINE__, "PAPI_get_hardware_info", 2 );
220  }
221 
223  if ( retval != PAPI_OK ) {
224  fprintf( stderr, "PAPI_create_eventset error\n" );
225  exit( 1 );
226  }
227 
228  retval = PAPI_event_name_to_code( argv[2], &cevent );
229  if ( retval != PAPI_OK ) {
230  fprintf( stderr, "Event %s can't be found\n", argv[2] );
231  exit( 1 );
232  }
233  cidx = PAPI_get_event_component(cevent);
234 
235  for( i = 2; i < argc; i++ ) {
236  retval = PAPI_event_name_to_code( argv[i], &pevent );
237  if ( retval != PAPI_OK ) {
238  fprintf( stderr, "Event %s can't be found\n", argv[i] );
239  exit( 1 );
240  }
241  retval = PAPI_add_event( EventSet, pevent );
242  if ( retval != PAPI_OK ) {
243  fprintf( stderr, "Event %s can't be counted with others %d\n",
244  argv[i], retval );
245  exit( 1 );
246  }
247  }
248 
249  if ( !strcmp( "NATIVE", argv[1] ) ) {
250  native( cidx );
251  }
252  else if ( !strcmp( "PRESET", argv[1] ) ) {
253  preset( );
254  }
255  else {
256  goto use_exit;
257  }
258  exit( 0 );
259 
260 use_exit:
261  fprintf( stderr,
262  "Usage: papi_event_chooser NATIVE|PRESET evt1 evt2 ... \n" );
263  exit( 1 );
264 }
int PAPI_add_event(int EventSet, int EventCode)
Definition: papi.c:1604
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_VERB_ECONT
Definition: fpapi.h:39
return PAPI_OK
Definition: linux-nvml.c:458
tests_quiet(argc, argv)
int int argc
Definition: iozone.c:1609
char ** argv
Definition: iozone.c:1610
static int preset(void)
test_fail(__FILE__, __LINE__,"PAPI_library_init", retval)
int PAPI_library_init(int version)
Definition: papi.c:495
int i
Definition: fileop.c:140
static int cidx
Definition: event_info.c:40
#define PAPI_VER_CURRENT
Definition: fpapi.h:14
int PAPI_create_eventset(int *EventSet)
Definition: papi.c:1406
int PAPI_event_name_to_code(char *in, int *out)
Definition: papi.c:1008
int EventSet
static int native(int cidx)
Definition: event_chooser.c:81
ssize_t retval
Definition: libasync.c:338
void exit()
int PAPI_get_event_component(int EventCode)
Definition: papi.c:6456
int PAPI_set_debug(int level)
Definition: papi.c:3037

Here is the call graph for this function:

static int native ( int  cidx)
static

Definition at line 81 of file event_chooser.c.

82 {
83  int i, j, k;
84  int retval, added;
85  PAPI_event_info_t info;
86 
87  j = 0;
88 
89  /* For platform independence, always ASK FOR the first event */
90  /* Don't just assume it'll be the first numeric value */
91  i = 0 | PAPI_NATIVE_MASK;
93  if (retval==PAPI_ENOEVNT) {
94  printf("Cannot find first event in component %d\n",cidx);
95  }
96 
97  do {
98  k = i;
99 
101  if ( ( added = add_remove_event( EventSet, k ) ) == PAPI_OK ) {
102  show_event_info( i );
103  do {
104  retval = PAPI_get_event_info( k, &info );
105  if ( retval == PAPI_OK ) {
106  printf( " %#-10x%s |%s|\n", info.event_code,
107  strchr( info.symbol, ':' ),
108  strchr( info.long_descr, ':' ) + 1 );
109  }
110  } while ( PAPI_enum_cmp_event( &k, PAPI_NTV_ENUM_UMASKS, cidx ) ==
111  PAPI_OK );
112  j++;
113  }
114  } else {
115  if ( ( added = add_remove_event( EventSet, i ) ) == PAPI_OK ) {
116  show_event_info( i );
117  j++;
118  }
119  }
120 
121  if ( added == PAPI_OK ) {
122  /* modifier = PAPI_NTV_ENUM_GROUPS returns event codes with a
123  groups id for each group in which this
124  native event lives, in bits 16 - 23 of event code
125  terminating with PAPI_ENOEVNT at the end of the list.
126  */
127  k = i;
129  printf( "Groups: " );
130  do {
131  printf( "%4d", ( ( k & PAPI_NTV_GROUP_AND_MASK ) >>
132  PAPI_NTV_GROUP_SHIFT ) - 1 );
133  } while ( PAPI_enum_cmp_event( &k, PAPI_NTV_ENUM_GROUPS, cidx ) ==
134  PAPI_OK );
135  printf( "\n" );
136  }
137 
138  printf( "---------------------------------------------"
139  "----------------------------\n" );
140  }
141  } while ( PAPI_enum_cmp_event( &i, PAPI_ENUM_EVENTS, cidx ) == PAPI_OK );
142 
143  printf( "------------------------------------------"
144  "-------------------------------\n" );
145  printf( "Total events reported: %d\n", j );
146  test_pass( __FILE__, NULL, 0 );
147  exit( 1 );
148 }
#define PAPI_NATIVE_MASK
#define PAPI_ENOEVNT
Definition: fpapi.h:112
static int show_event_info(int evt)
Definition: event_chooser.c:59
char long_descr[PAPI_HUGE_STR_LEN]
Definition: papi.h:964
char symbol[PAPI_HUGE_STR_LEN]
Definition: papi.h:961
return PAPI_OK
Definition: linux-nvml.c:458
#define printf
Definition: papi_test.h:125
test_pass(__FILE__, NULL, 0)
int PAPI_get_event_info(int EventCode, PAPI_event_info_t *info)
Definition: papi.c:844
int i
Definition: fileop.c:140
#define PAPI_NTV_GROUP_SHIFT
Definition: papi.h:523
static int cidx
Definition: event_info.c:40
int k
Definition: iozone.c:19136
int PAPI_enum_cmp_event(int *EventCode, int modifier, int cidx)
Definition: papi.c:1311
int EventSet
#define PAPI_NTV_GROUP_AND_MASK
Definition: papi.h:522
static int add_remove_event(int EventSet, int evt)
Definition: event_chooser.c:44
long j
Definition: iozone.c:19135
unsigned int event_code
Definition: papi.h:959
ssize_t retval
Definition: libasync.c:338
void exit()

Here is the call graph for this function:

Here is the caller graph for this function:

static int preset ( void  )
static

Definition at line 151 of file event_chooser.c.

152 {
153  int i, j = 0;
154  int retval;
155  PAPI_event_info_t info;
156 
157  printf( " Name Code " );
158  printf( "Deriv Description (Note)\n" );
159 
160  /* For consistency, always ASK FOR the first event */
161  i = 0 | PAPI_PRESET_MASK;
163 
164  do {
165  retval = PAPI_add_event( EventSet, i );
166  if ( retval == PAPI_OK ) {
167  if ( PAPI_get_event_info( i, &info ) == PAPI_OK ) {
168  printf( "%-13s%#x %-5s%s",
169  info.symbol,
170  info.event_code, is_derived( &info ), info.long_descr );
171  if ( info.note[0] )
172  printf( " (%s)", info.note );
173  printf( "\n" );
174  }
175  if ( ( retval = PAPI_remove_event( EventSet, i ) ) != PAPI_OK )
176  printf( "Error in PAPI_remove_event\n" );
177  j++;
178  }
179  } while ( PAPI_enum_event( &i, PAPI_PRESET_ENUM_AVAIL ) == PAPI_OK );
180 
181  printf
182  ( "-------------------------------------------------------------------------\n" );
183  printf( "Total events reported: %d\n", j );
184  test_pass( __FILE__, NULL, 0 );
185  exit( 1 );
186 }
int PAPI_add_event(int EventSet, int EventCode)
Definition: papi.c:1604
int PAPI_remove_event(int EventSet, int EventCode)
Definition: papi.c:1699
char long_descr[PAPI_HUGE_STR_LEN]
Definition: papi.h:964
int PAPI_enum_event(int *EventCode, int modifier)
Definition: papi.c:1148
char symbol[PAPI_HUGE_STR_LEN]
Definition: papi.h:961
return PAPI_OK
Definition: linux-nvml.c:458
static char * is_derived(PAPI_event_info_t *info)
Definition: event_chooser.c:31
#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 PAPI_get_event_info(int EventCode, PAPI_event_info_t *info)
Definition: papi.c:844
int i
Definition: fileop.c:140
int EventSet
long j
Definition: iozone.c:19135
unsigned int event_code
Definition: papi.h:959
ssize_t retval
Definition: libasync.c:338
void exit()

Here is the call graph for this function:

Here is the caller graph for this function:

static int show_event_info ( int  evt)
static

Definition at line 59 of file event_chooser.c.

60 {
61  int k;
62  int retval;
63  PAPI_event_info_t info;
64 
65  if ( ( retval = PAPI_get_event_info( evt, &info ) ) == PAPI_OK ) {
66  printf( "%s\t%#x\n |%s|\n",
67  info.symbol, info.event_code, info.long_descr );
68 
69  for( k = 0; k < ( int ) info.count; k++ ) {
70  if ( strlen( info.name[k] ) ) {
71  printf( " |Register Value[%d]: %#-10x %s|\n",
72  k, info.code[k], info.name[k] );
73  }
74  }
75  }
76  return retval;
77 }
unsigned int count
Definition: papi.h:982
char long_descr[PAPI_HUGE_STR_LEN]
Definition: papi.h:964
char symbol[PAPI_HUGE_STR_LEN]
Definition: papi.h:961
return PAPI_OK
Definition: linux-nvml.c:458
#define printf
Definition: papi_test.h:125
int PAPI_get_event_info(int EventCode, PAPI_event_info_t *info)
Definition: papi.c:844
int k
Definition: iozone.c:19136
unsigned int code[PAPI_MAX_INFO_TERMS]
Definition: papi.h:998
int
Definition: iozone.c:18528
unsigned int event_code
Definition: papi.h:959
ssize_t retval
Definition: libasync.c:338
char name[PAPI_MAX_INFO_TERMS][PAPI_2MAX_STR_LEN]
Definition: papi.h:1004

Here is the call graph for this function:

Here is the caller graph for this function:

Variable Documentation

int EventSet = PAPI_NULL

Definition at line 27 of file event_chooser.c.

int retval

Definition at line 28 of file event_chooser.c.