PAPI 7.1.0.0
Loading...
Searching...
No Matches
papi_xml_event_info.c File Reference
Include dependency graph for papi_xml_event_info.c:

Go to the source code of this file.

Functions

static int xmlize (const char *msg, FILE *f)
 
static int papi_xml_hwinfo (FILE *f)
 
static int test_event (int evt)
 
static void xmlize_event (FILE *f, PAPI_event_info_t *info, int num)
 
static void enum_preset_events (FILE *f, int cidx)
 
static void enum_native_events (FILE *f, int cidx)
 
static void usage (char *argv[])
 
static void parse_command_line (int argc, char **argv, int numc)
 
int main (int argc, char **argv)
 

Variables

static int EventSet
 
static int preset = 1
 
static int native = 1
 
static int cidx = -1
 

Function Documentation

◆ enum_native_events()

static void enum_native_events ( FILE *  f,
int  cidx 
)
static

Definition at line 205 of file papi_xml_event_info.c.

206{
207 int i, k, num;
208 int retval;
210
212 fprintf( f, " <eventset type=\"NATIVE\">\n" );
213 num = -1;
215
216 while ( retval == PAPI_OK ) {
217
218 num++;
219 retval = PAPI_get_event_info( i, &info );
220 if ( retval != PAPI_OK ) {
222 continue;
223 }
224
225 /* enumerate any umasks */
226 k = i;
228
229 /* add the event */
230 xmlize_event( f, &info, num );
231
232 /* add the event's unit masks */
233 do {
234 retval = PAPI_get_event_info( k, &info );
235 if ( retval == PAPI_OK ) {
236 if ( test_event( k )!=PAPI_OK ) {
237 continue;
238 }
239 xmlize_event( f, &info, -1 );
240 }
242 fprintf( f, " </event>\n" );
243 } else {
244 /* this event has no unit masks; test & write the event */
245 if ( test_event( i ) == PAPI_OK ) {
246 xmlize_event( f, &info, num );
247 fprintf( f, " </event>\n" );
248 }
249 }
251 }
252 fprintf( f, " </eventset>\n" );
253}
int i
Enumerate PAPI preset or native events for a given component.
Get the event's name and description info.
double f(double a)
Definition: cpi.c:23
#define PAPI_ENUM_EVENTS
Definition: f90papi.h:224
#define PAPI_OK
Definition: f90papi.h:73
#define PAPI_ENUM_FIRST
Definition: f90papi.h:85
#define PAPI_NTV_ENUM_UMASKS
Definition: f90papi.h:66
#define PAPI_NATIVE_MASK
static int cidx
static int test_event(int evt)
static void xmlize_event(FILE *f, PAPI_event_info_t *info, int num)
int retval
Definition: zero_fork.c:53
Here is the call graph for this function:
Here is the caller graph for this function:

◆ enum_preset_events()

static void enum_preset_events ( FILE *  f,
int  cidx 
)
static

Definition at line 173 of file papi_xml_event_info.c.

174{
175 int i, num;
176 int retval;
178
180 fprintf( f, " <eventset type=\"PRESET\">\n" );
181 num = -1;
183
184 while ( retval == PAPI_OK ) {
185 num++;
186 retval = PAPI_get_event_info( i, &info );
187 if ( retval != PAPI_OK ) {
189 continue;
190 }
191 if ( test_event( i ) == PAPI_OK ) {
192 xmlize_event( f, &info, num );
193 fprintf( f, " </event>\n" );
194 }
196 }
197 fprintf( f, " </eventset>\n" );
198}
#define PAPI_PRESET_MASK
Here is the call graph for this function:
Here is the caller graph for this function:

◆ main()

int main ( int  argc,
char **  argv 
)

Definition at line 346 of file papi_xml_event_info.c.

347{
348 int retval;
349 const PAPI_component_info_t *comp;
350
351 int numc = 0;
352
354 if ( retval != PAPI_VER_CURRENT ) {
355 fprintf(stderr,"Error! PAPI_library_init\n");
356 return retval;
357 }
358
359 /* report any return codes less than 0? */
360 /* Why? */
361#if 0
363 if ( retval != PAPI_OK ) {
364 test_fail( __FILE__, __LINE__, "PAPI_set_debug", retval );
365 }
366#endif
367
368 /* Create EventSet to use */
370
372 if ( retval != PAPI_OK ) {
373 fprintf(stderr,"Error! PAPI_create_eventset\n");
374 return retval;
375 }
376
377 /* Get number of components */
378 numc = PAPI_num_components( );
379
380 /* parse command line arguments */
381 parse_command_line(argc,argv,numc);
382
383 /* print XML header */
384 fprintf( stdout, "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" );
385 fprintf( stdout, "<eventinfo>\n" );
386
387
388 /* print hardware info */
390
391 /* If a specific component specified, only print events from there */
392 if ( cidx >= 0 ) {
394
395 fprintf( stdout, "<component index=\"%d\" type=\"%s\" id=\"%s\">\n",
396 cidx, cidx ? "Unknown" : "CPU", comp->name );
397
398 if ( native )
400 if ( preset )
402
403 fprintf( stdout, "</component>\n" );
404 }
405 else {
406 /* Otherwise, print info for all components */
407 for ( cidx = 0; cidx < numc; cidx++ ) {
409
410 fprintf( stdout, "<component index=\"%d\" type=\"%s\" id=\"%s\">\n",
411 cidx, cidx ? "Unknown" : "CPU", comp->name );
412
413 if ( native )
415 if ( preset )
417
418 fprintf( stdout, "</component>\n" );
419
420 /* clean out eventset */
422 if ( retval != PAPI_OK ) {
423 fprintf(stderr,"Error! PAPI_cleanup_eventset\n");
424 return retval;
425 }
427 if ( retval != PAPI_OK ) {
428 fprintf(stderr,"Error! PAPI_destroy_eventset\n");
429 return retval;
430 }
432
434 if ( retval != PAPI_OK ) {
435 fprintf(stderr,"Error! PAPI_create_eventset\n");
436 return retval;
437 }
438
439 /* re-parse command line to set up any events specified */
440 parse_command_line (argc, argv, numc);
441 }
442 }
443 fprintf( stdout, "</eventinfo>\n" );
444
445 return 0;
446}
Empty and destroy an EventSet.
Create a new empty PAPI EventSet.
Empty and destroy an EventSet.
get information about a specific software component
initialize the PAPI library.
Get the number of components available on the system.
Set the current debug level for error output from PAPI.
#define PAPI_VER_CURRENT
Definition: f90papi.h:54
#define PAPI_NULL
Definition: f90papi.h:78
#define PAPI_VERB_ECONT
Definition: f90papi.h:164
FILE * stdout
FILE * stderr
void PAPI_NORETURN test_fail(const char *file, int line, const char *call, int retval)
Definition: test_utils.c:491
static void parse_command_line(int argc, char **argv, int numc)
static int preset
static int EventSet
static int native
static int papi_xml_hwinfo(FILE *f)
static void enum_preset_events(FILE *f, int cidx)
static void enum_native_events(FILE *f, int cidx)
char name[PAPI_MAX_STR_LEN]
Definition: papi.h:627
Here is the call graph for this function:

◆ papi_xml_hwinfo()

static int papi_xml_hwinfo ( FILE *  f)
static

Definition at line 82 of file papi_xml_event_info.c.

83{
84 const PAPI_hw_info_t *hwinfo;
85
86 if ( ( hwinfo = PAPI_get_hardware_info( ) ) == NULL )
87 return PAPI_ESYS;
88
89 fprintf( f, "<hardware>\n" );
90
91 fprintf( f, " <vendor string=\"");
92 xmlize( hwinfo->vendor_string, f );
93 fprintf( f,"\"/>\n");
94 fprintf( f, " <vendorCode value=\"%d\"/>\n", hwinfo->vendor );
95 fprintf( f, " <model string=\"");
96 xmlize( hwinfo->model_string, f );
97 fprintf( f, "\"/>\n");
98 fprintf( f, " <modelCode value=\"%d\"/>\n", hwinfo->model );
99 fprintf( f, " <cpuRevision value=\"%f\"/>\n", hwinfo->revision );
100 fprintf( f, " <cpuID>\n" );
101 fprintf( f, " <family value=\"%d\"/>\n", hwinfo->cpuid_family );
102 fprintf( f, " <model value=\"%d\"/>\n", hwinfo->cpuid_model );
103 fprintf( f, " <stepping value=\"%d\"/>\n", hwinfo->cpuid_stepping );
104 fprintf( f, " </cpuID>\n" );
105 fprintf( f, " <cpuMaxMegahertz value=\"%d\"/>\n", hwinfo->cpu_max_mhz );
106 fprintf( f, " <cpuMinMegahertz value=\"%d\"/>\n", hwinfo->cpu_min_mhz );
107 fprintf( f, " <threads value=\"%d\"/>\n", hwinfo->threads );
108 fprintf( f, " <cores value=\"%d\"/>\n", hwinfo->cores );
109 fprintf( f, " <sockets value=\"%d\"/>\n", hwinfo->sockets );
110 fprintf( f, " <nodes value=\"%d\"/>\n", hwinfo->nnodes );
111 fprintf( f, " <cpuPerNode value=\"%d\"/>\n", hwinfo->ncpu );
112 fprintf( f, " <totalCPUs value=\"%d\"/>\n", hwinfo->totalcpus );
113 fprintf( f, "</hardware>\n" );
114
115 return PAPI_OK;
116}
get information about the system hardware
#define PAPI_ESYS
Definition: f90papi.h:136
static int xmlize(const char *msg, FILE *f)
Hardware info structure.
Definition: papi.h:774
char vendor_string[PAPI_MAX_STR_LEN]
Definition: papi.h:782
int cpuid_family
Definition: papi.h:786
int nnodes
Definition: papi.h:779
int model
Definition: papi.h:783
int cpuid_model
Definition: papi.h:787
int totalcpus
Definition: papi.h:780
int sockets
Definition: papi.h:778
int vendor
Definition: papi.h:781
float revision
Definition: papi.h:785
int cpu_min_mhz
Definition: papi.h:791
int ncpu
Definition: papi.h:775
char model_string[PAPI_MAX_STR_LEN]
Definition: papi.h:784
int cpuid_stepping
Definition: papi.h:788
int cpu_max_mhz
Definition: papi.h:790
int cores
Definition: papi.h:777
int threads
Definition: papi.h:776
Here is the call graph for this function:
Here is the caller graph for this function:

◆ parse_command_line()

static void parse_command_line ( int  argc,
char **  argv,
int  numc 
)
static

Definition at line 272 of file papi_xml_event_info.c.

272 {
273
274 int i,retval;
275
276 for( i = 1; i < argc; i++ ) {
277 if ( argv[i][0] == '-' ) {
278 switch ( argv[i][1] ) {
279 case 'c':
280 /* only events for specified component */
281
282 /* UGH, what is this, the IOCCC? */
283 cidx = (i+1) < argc ? atoi( argv[(i++)+1] ) : -1;
284 if ( cidx < 0 || cidx >= numc ) {
285 fprintf( stderr,"Error: component index %d out of bounds (0..%d)\n",
286 cidx, numc - 1 );
287 usage( argv );
288 exit(1);
289 }
290 break;
291
292 case 'p':
293 /* only preset events */
294 preset = 1;
295 native = 0;
296 break;
297
298 case 'n':
299 /* only native events */
300 native = 1;
301 preset = 0;
302 break;
303
304 case 'h':
305 /* print help */
306 usage( argv );
307 exit(0);
308 break;
309
310 default:
311 fprintf( stderr,
312 "Error: unknown option: %s\n", argv[i] );
313 usage( argv );
314 exit(1);
315 }
316 } else {
317
318 /* If event names are specified, add them to the */
319 /* EventSet and test if other events can be run with them */
320
321 int code = -1;
322
323 retval = PAPI_event_name_to_code( argv[i], &code );
324 retval = PAPI_query_event( code );
325 if ( retval != PAPI_OK ) {
326 fprintf( stderr, "Error: unknown event: %s\n", argv[i] );
327 usage( argv );
328 exit(1);
329 }
330
331 retval = PAPI_add_event( EventSet, code );
332 if ( retval != PAPI_OK ) {
333 fprintf( stderr,
334 "Error: event %s cannot be counted with others\n",
335 argv[i] );
336 usage( argv );
337 exit(1);
338 }
339 }
340 }
341
342}
add PAPI preset or native hardware event to an event set
Convert a name to a numeric hardware event code.
Query if PAPI event exists.
static void usage(void)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ test_event()

static int test_event ( int  evt)
static

Definition at line 126 of file papi_xml_event_info.c.

127{
128 int retval;
129
131 if ( retval != PAPI_OK ) {
132 return retval;
133 }
134
135 if ( ( retval = PAPI_remove_event( EventSet, evt ) ) != PAPI_OK ) {
136 fprintf( stderr, "Error removing event from eventset\n" );
137 exit( 1 );
138 }
139 return PAPI_OK;
140}
removes a hardware event from a PAPI event set.
Here is the caller graph for this function:

◆ usage()

static void usage ( char *  argv[])
static

Definition at line 260 of file papi_xml_event_info.c.

261{
262 fprintf( stderr, "Usage: %s [options] [[event1] event2 ...]\n", argv[0] );
263 fprintf( stderr, " options: -h print help message\n" );
264 fprintf( stderr, " -p print only preset events\n" );
265 fprintf( stderr, " -n print only native events\n" );
266 fprintf( stderr," -c n print only events for component index n\n" );
267 fprintf( stderr, "If event1, event2, etc., are specified, then only events\n");
268 fprintf( stderr, "that can be run in addition to these events will be printed\n\n");
269}

◆ xmlize()

static int xmlize ( const char *  msg,
FILE *  f 
)
static

Definition at line 46 of file papi_xml_event_info.c.

47{
48 const char *op;
49
50 if ( !msg )
51 return PAPI_OK;
52
53 for ( op = msg; *op != '\0'; op++ ) {
54 switch ( *op ) {
55 case '"':
56 fprintf( f, "&quot;" );
57 break;
58 case '&':
59 fprintf( f, "&amp;" );
60 break;
61 case '\'':
62 fprintf( f, "&apos;" );
63 break;
64 case '<':
65 fprintf( f, "&lt;" );
66 break;
67 case '>':
68 fprintf( f, "&gt;" );
69 break;
70 default:
71 fprintf( f, "%c", *op);
72 }
73 }
74
75 return PAPI_OK;
76}
Here is the call graph for this function:
Here is the caller graph for this function:

◆ xmlize_event()

static void xmlize_event ( FILE *  f,
PAPI_event_info_t info,
int  num 
)
static

Definition at line 147 of file papi_xml_event_info.c.

148{
149
150 if ( num >= 0 ) {
151 fprintf( f, " <event index=\"%d\" name=\"",num);
152 xmlize( info->symbol, f );
153 fprintf( f, "\" desc=\"");
154 xmlize( info->long_descr, f );
155 fprintf( f, "\">\n");
156 }
157 else {
158 fprintf( f," <modifier name=\"");
159 xmlize( info->symbol, f );
160 fprintf( f,"\" desc=\"");
161 xmlize( info->long_descr, f );
162 fprintf( f,"\"> </modifier>\n");
163 }
164
165}
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:
Here is the caller graph for this function:

Variable Documentation

◆ cidx

int cidx = -1
static

Definition at line 40 of file papi_xml_event_info.c.

◆ EventSet

int EventSet
static

Definition at line 37 of file papi_xml_event_info.c.

◆ native

int native = 1
static

Definition at line 39 of file papi_xml_event_info.c.

◆ preset

int preset ( void  ) = 1
static

Definition at line 38 of file papi_xml_event_info.c.