PAPI 7.1.0.0
Loading...
Searching...
No Matches
papi_xml_event_info.c
Go to the documentation of this file.
1
32#include <stdio.h>
33#include <stdlib.h>
34
35#include "papi.h"
36
37static int EventSet;
38static int preset = 1;
39static int native = 1;
40static int cidx = -1;
41
42/**********************************************************************/
43/* Take a string and print a version with properly escaped XML */
44/**********************************************************************/
45static int
46xmlize( const char *msg, FILE *f )
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}
77
78/*************************************/
79/* print hardware info in XML format */
80/*************************************/
81static int
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}
117
118
119
120/****************************************************************/
121/* Test if event can be added to an eventset */
122/* (there might be existing events if specified on command line */
123/****************************************************************/
124
125static int
126test_event( int evt )
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}
141
142/***************************************/
143/* Convert an event to XML */
144/***************************************/
145
146static void
147xmlize_event( FILE * f, PAPI_event_info_t * info, int num )
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}
166
167
168/****************************************/
169/* Print all preset events */
170/****************************************/
171
172static void
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}
199
200/****************************************/
201/* Print all native events */
202/****************************************/
203
204static void
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}
254
255/****************************************/
256/* Print usage information */
257/****************************************/
258
259static void
260usage( char *argv[] )
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}
270
271static void
272parse_command_line (int argc, char **argv, int numc) {
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}
343
344
345int
346main( int argc, char **argv)
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}
int i
add PAPI preset or native hardware event to an event set
Empty and destroy an EventSet.
Create a new empty PAPI EventSet.
Empty and destroy an EventSet.
Enumerate PAPI preset or native events for a given component.
Convert a name to a numeric hardware event code.
get information about a specific software component
Get the event's name and description info.
get information about the system hardware
initialize the PAPI library.
Get the number of components available on the system.
Query if PAPI event exists.
removes a hardware event from a PAPI event set.
Set the current debug level for error output from PAPI.
double f(double a)
Definition: cpi.c:23
#define PAPI_VER_CURRENT
Definition: f90papi.h:54
#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_NULL
Definition: f90papi.h:78
#define PAPI_VERB_ECONT
Definition: f90papi.h:164
#define PAPI_ESYS
Definition: f90papi.h:136
#define PAPI_NTV_ENUM_UMASKS
Definition: f90papi.h:66
#define PAPI_PRESET_MASK
#define PAPI_NATIVE_MASK
Return codes and api definitions.
FILE * stdout
FILE * stderr
static void usage(void)
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 cidx
static int papi_xml_hwinfo(FILE *f)
static int test_event(int evt)
static void enum_preset_events(FILE *f, int cidx)
static int xmlize(const char *msg, FILE *f)
static void xmlize_event(FILE *f, PAPI_event_info_t *info, int num)
static void enum_native_events(FILE *f, int cidx)
int main()
Definition: pernode.c:20
char name[PAPI_MAX_STR_LEN]
Definition: papi.h:627
char symbol[PAPI_HUGE_STR_LEN]
Definition: papi.h:960
char long_descr[PAPI_HUGE_STR_LEN]
Definition: papi.h:963
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
int retval
Definition: zero_fork.c:53