PAPI 7.1.0.0
Loading...
Searching...
No Matches
papi_event_chooser.c File Reference
Include dependency graph for papi_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

◆ add_remove_event()

static int add_remove_event ( int  EventSet,
int  evt 
)
static

Definition at line 48 of file papi_event_chooser.c.

49{
50 int retval;
51
52 if ( ( retval = PAPI_add_event( EventSet, evt ) ) != PAPI_OK ) {
53 //printf( "Error adding event.\n" );
54 } else {
55 if ( ( retval = PAPI_remove_event( EventSet, evt ) ) != PAPI_OK ) {
56 printf( "Error removing event.\n" );
57 }
58 }
59 return retval;
60}
add PAPI preset or native hardware event to an event set
removes a hardware event from a PAPI event set.
#define PAPI_OK
Definition: f90papi.h:73
int EventSet
int retval
Here is the caller graph for this function:

◆ is_derived()

static char * is_derived ( PAPI_event_info_t info)
static

Definition at line 35 of file papi_event_chooser.c.

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}
char derived[PAPI_MIN_STR_LEN]
Definition: papi.h:989
Here is the caller graph for this function:

◆ main()

int main ( int  argc,
char **  argv 
)

Definition at line 193 of file papi_event_chooser.c.

194{
195 int i;
196 int pevent,cevent;
197 int cidx;
198
199 const PAPI_hw_info_t *hwinfo = NULL;
200
201 if ( argc < 3 ) {
202 goto use_exit;
203 }
204
205 /* Init PAPI library */
207 if ( retval != PAPI_VER_CURRENT ) {
208 fprintf(stderr,"Error! PAPI_library_init\n");
209 return retval;
210 }
211
213 if ( retval != PAPI_OK ) {
214 fprintf(stderr,"Error! PAPI_set_debug\n");
215 return retval;
216 }
217
218 retval = papi_print_header( "Event Chooser: Available events "
219 "which can be added with given events.\n",
220 &hwinfo );
221 if ( retval != PAPI_OK ) {
222 fprintf(stderr, "Error! PAPI_get_hardware_info\n");
223 return 2;
224 }
225
227 if ( retval != PAPI_OK ) {
228 fprintf( stderr, "PAPI_create_eventset error\n" );
229 return 1;
230 }
231
232 retval = PAPI_event_name_to_code( argv[2], &cevent );
233 if ( retval != PAPI_OK ) {
234 fprintf( stderr, "Event %s can't be found\n", argv[2] );
235 return 1;
236 }
238
239 for( i = 2; i < argc; i++ ) {
240 retval = PAPI_event_name_to_code( argv[i], &pevent );
241 if ( retval != PAPI_OK ) {
242 fprintf( stderr, "Event %s can't be found\n", argv[i] );
243 return 1;
244 }
245 retval = PAPI_add_event( EventSet, pevent );
246 if ( retval != PAPI_OK ) {
247 fprintf( stderr, "Event %s can't be counted with others %d\n",
248 argv[i], retval );
249 return 1;
250 }
251 }
252
253 if ( !strcmp( "NATIVE", argv[1] ) ) {
254 native( cidx );
255 }
256 else if ( !strcmp( "PRESET", argv[1] ) ) {
257 preset( );
258 }
259 else {
260 goto use_exit;
261 }
262 return 0;
263
264use_exit:
265 fprintf( stderr,
266 "Usage: papi_event_chooser NATIVE|PRESET evt1 evt2 ... \n" );
267 return 1;
268}
int i
Create a new empty PAPI EventSet.
Convert a name to a numeric hardware event code.
return component an event belongs to
initialize the PAPI library.
Set the current debug level for error output from PAPI.
#define PAPI_VER_CURRENT
Definition: f90papi.h:54
#define PAPI_VERB_ECONT
Definition: f90papi.h:164
static int preset(void)
FILE * stderr
static int native
static int cidx
int papi_print_header(char *prompt, const PAPI_hw_info_t **hwinfo)
Definition: print_header.c:12
Hardware info structure.
Definition: papi.h:774
Here is the call graph for this function:

◆ native()

static int native ( int  cidx)
static

Definition at line 85 of file papi_event_chooser.c.

86{
87 int i, j, k;
88 int retval, added;
90
91 j = 0;
92
93 /* For platform independence, always ASK FOR the first event */
94 /* Don't just assume it'll be the first numeric value */
95 i = 0 | PAPI_NATIVE_MASK;
97 if (retval==PAPI_ENOEVNT) {
98 printf("Cannot find first event in component %d\n",cidx);
99 }
100
101 do {
102 k = i;
103
105 if ( ( added = add_remove_event( EventSet, k ) ) == PAPI_OK ) {
107 do {
108 retval = PAPI_get_event_info( k, &info );
109 if ( retval == PAPI_OK ) {
110 printf( " %#-10x%s |%s|\n", info.event_code,
111 strchr( info.symbol, ':' ),
112 strchr( info.long_descr, ':' ) + 1 );
113 }
115 PAPI_OK );
116 j++;
117 }
118 } else {
119 if ( ( added = add_remove_event( EventSet, i ) ) == PAPI_OK ) {
121 j++;
122 }
123 }
124
125 if ( added == PAPI_OK ) {
126 /* modifier = PAPI_NTV_ENUM_GROUPS returns event codes with a
127 groups id for each group in which this
128 native event lives, in bits 16 - 23 of event code
129 terminating with PAPI_ENOEVNT at the end of the list.
130 */
131 k = i;
133 printf( "Groups: " );
134 do {
135 printf( "%4d", ( ( k & PAPI_NTV_GROUP_AND_MASK ) >>
136 PAPI_NTV_GROUP_SHIFT ) - 1 );
138 PAPI_OK );
139 printf( "\n" );
140 }
141
142 printf( "---------------------------------------------"
143 "----------------------------\n" );
144 }
146
147 printf( "------------------------------------------"
148 "-------------------------------\n" );
149 printf( "Total events reported: %d\n", j );
150
151 exit( 0 );
152}
Enumerate PAPI preset or native events for a given component.
Get the event's name and description info.
#define PAPI_ENUM_EVENTS
Definition: f90papi.h:224
#define PAPI_NTV_GROUP_AND_MASK
Definition: f90papi.h:30
#define PAPI_ENUM_FIRST
Definition: f90papi.h:85
#define PAPI_ENOEVNT
Definition: f90papi.h:139
#define PAPI_NTV_ENUM_UMASKS
Definition: f90papi.h:66
#define PAPI_NTV_GROUP_SHIFT
Definition: f90papi.h:162
#define PAPI_NATIVE_MASK
@ PAPI_NTV_ENUM_GROUPS
Definition: papi.h:514
static int add_remove_event(int EventSet, int evt)
static int show_event_info(int evt)
unsigned int event_code
Definition: papi.h:958
char symbol[PAPI_HUGE_STR_LEN]
Definition: papi.h:960
char long_descr[PAPI_HUGE_STR_LEN]
Definition: papi.h:963
Here is the call graph for this function:

◆ preset()

static int preset ( void  )
static

Definition at line 155 of file papi_event_chooser.c.

156{
157 int i, j = 0;
158 int retval;
160
161 printf( " Name Code " );
162 printf( "Deriv Description (Note)\n" );
163
164 /* For consistency, always ASK FOR the first event */
165 i = 0 | PAPI_PRESET_MASK;
167
168 do {
170 if ( retval == PAPI_OK ) {
171 if ( PAPI_get_event_info( i, &info ) == PAPI_OK ) {
172 printf( "%-13s%#x %-5s%s",
173 info.symbol,
174 info.event_code, is_derived( &info ), info.long_descr );
175 if ( info.note[0] )
176 printf( " (%s)", info.note );
177 printf( "\n" );
178 }
179 if ( ( retval = PAPI_remove_event( EventSet, i ) ) != PAPI_OK )
180 printf( "Error in PAPI_remove_event\n" );
181 j++;
182 }
184
185 printf
186 ( "-------------------------------------------------------------------------\n" );
187 printf( "Total events reported: %d\n", j );
188
189 exit( 0 );
190}
Enumerate PAPI preset or native events.
#define PAPI_PRESET_MASK
@ PAPI_PRESET_ENUM_AVAIL
Definition: papi.h:490
static char * is_derived(PAPI_event_info_t *info)
char note[PAPI_HUGE_STR_LEN]
Definition: papi.h:1007
Here is the call graph for this function:
Here is the caller graph for this function:

◆ show_event_info()

static int show_event_info ( int  evt)
static

Definition at line 63 of file papi_event_chooser.c.

64{
65 int k;
66 int retval;
68
69 if ( ( retval = PAPI_get_event_info( evt, &info ) ) == PAPI_OK ) {
70 printf( "%s\t%#x\n |%s|\n",
71 info.symbol, info.event_code, info.long_descr );
72
73 for( k = 0; k < ( int ) info.count; k++ ) {
74 if ( strlen( info.name[k] ) ) {
75 printf( " |Register Value[%d]: %#-10x %s|\n",
76 k, info.code[k], info.name[k] );
77 }
78 }
79 }
80 return retval;
81}
int
Definition: sde_internal.h:89
char name[PAPI_MAX_INFO_TERMS][PAPI_2MAX_STR_LEN]
Definition: papi.h:1003
unsigned int count
Definition: papi.h:981
unsigned int code[PAPI_MAX_INFO_TERMS]
Definition: papi.h:997
Here is the caller graph for this function:

Variable Documentation

◆ EventSet

int EventSet = PAPI_NULL

Definition at line 31 of file papi_event_chooser.c.

◆ retval

int retval

Definition at line 32 of file papi_event_chooser.c.