event_info.c File Reference

Include dependency graph for 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

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

Definition at line 205 of file event_info.c.

00206 {
00207     int i, k, num;
00208     int retval;
00209     PAPI_event_info_t info;
00210 
00211     i = PAPI_NATIVE_MASK;
00212     fprintf( f, "  <eventset type=\"NATIVE\">\n" );
00213     num = -1;
00214     retval = PAPI_enum_cmp_event( &i, PAPI_ENUM_FIRST, cidx );
00215 
00216     while ( retval == PAPI_OK ) {
00217 
00218        num++;
00219        retval = PAPI_get_event_info( i, &info );
00220        if ( retval != PAPI_OK ) {
00221           retval = PAPI_enum_cmp_event( &i, PAPI_ENUM_EVENTS, cidx );
00222           continue;
00223        }
00224             
00225        /* enumerate any umasks */
00226        k = i;
00227        if ( PAPI_enum_cmp_event( &k, PAPI_NTV_ENUM_UMASKS, cidx ) == PAPI_OK ) {
00228          
00229           /* Test if event can be added */
00230           if ( test_event( k ) == PAPI_OK ) {
00231 
00232          /* add the event */
00233          xmlize_event( f, &info, num );
00234             
00235          /* add the event's unit masks */
00236          do {
00237             retval = PAPI_get_event_info( k, &info );
00238             if ( retval == PAPI_OK ) {
00239                if ( test_event( k )!=PAPI_OK ) {
00240                break;
00241                }
00242                xmlize_event( f, &info, -1 );
00243             }
00244          } while ( PAPI_enum_cmp_event( &k, PAPI_NTV_ENUM_UMASKS, cidx ) == PAPI_OK);
00245          fprintf( f, "    </event>\n" );
00246           }
00247        } else {      
00248               /* this event has no unit masks; test & write the event */
00249           if ( test_event( i ) == PAPI_OK ) {
00250          xmlize_event( f, &info, num );
00251          fprintf( f, "    </event>\n" );
00252           }
00253        }
00254        retval = PAPI_enum_cmp_event( &i, PAPI_ENUM_EVENTS, cidx );
00255     }
00256     fprintf( f, "  </eventset>\n" );
00257 }

Here is the call graph for this function:

Here is the caller graph for this function:

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

Definition at line 173 of file event_info.c.

00174 {
00175     int i, num;
00176     int retval;
00177     PAPI_event_info_t info;
00178 
00179     i = PAPI_PRESET_MASK;
00180     fprintf( f, "  <eventset type=\"PRESET\">\n" );
00181     num = -1;
00182     retval = PAPI_enum_cmp_event( &i, PAPI_ENUM_FIRST, cidx );
00183 
00184     while ( retval == PAPI_OK ) {
00185        num++;
00186        retval = PAPI_get_event_info( i, &info );
00187        if ( retval != PAPI_OK ) {
00188          retval = PAPI_enum_cmp_event( &i, PAPI_ENUM_EVENTS, cidx );
00189           continue;
00190        }
00191        if ( test_event( i ) == PAPI_OK ) {
00192           xmlize_event( f, &info, num );
00193           fprintf( f, "    </event>\n" );
00194        }
00195        retval = PAPI_enum_cmp_event( &i, PAPI_ENUM_EVENTS, cidx );
00196     }
00197     fprintf( f, "  </eventset>\n" );
00198 }

Here is the call graph for this function:

Here is the caller graph for this function:

int main ( int  argc,
char **  argv 
)

Definition at line 350 of file event_info.c.

00351 {
00352     int retval;
00353     const PAPI_component_info_t *comp;
00354 
00355     int numc = 0;
00356 
00357     /* Set TESTS_QUIET variable */
00358     tests_quiet( argc, argv );  
00359 
00360     retval = PAPI_library_init( PAPI_VER_CURRENT );
00361     if ( retval != PAPI_VER_CURRENT ) {
00362        test_fail( __FILE__, __LINE__, "PAPI_library_init", retval );
00363     }
00364 
00365     /* report any return codes less than 0? */
00366     /* Why? */
00367 #if 0
00368     retval = PAPI_set_debug( PAPI_VERB_ECONT );
00369     if ( retval != PAPI_OK ) {
00370        test_fail( __FILE__, __LINE__, "PAPI_set_debug", retval );
00371     }
00372 #endif
00373 
00374     /* Create EventSet to use */
00375     EventSet = PAPI_NULL;
00376 
00377     retval = PAPI_create_eventset( &EventSet  );
00378     if ( retval != PAPI_OK ) {
00379        test_fail( __FILE__, __LINE__, "PAPI_create_eventset", retval );
00380        return 1;
00381     }
00382 
00383     /* Get number of components */
00384     numc = PAPI_num_components(  );
00385 
00386     /* parse command line arguments */
00387         parse_command_line(argc,argv,numc);
00388 
00389     /* print XML header */
00390     fprintf( stdout, "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" );
00391     fprintf( stdout, "<eventinfo>\n" );
00392 
00393 
00394     /* print hardware info */
00395     papi_xml_hwinfo( stdout );
00396 
00397     /* If a specific component specified, only print events from there */
00398     if ( cidx >= 0 ) {
00399        comp = PAPI_get_component_info( cidx );
00400 
00401        fprintf( stdout, "<component index=\"%d\" type=\"%s\" id=\"%s\">\n",
00402                 cidx, cidx ? "Unknown" : "CPU", comp->name );
00403 
00404        if ( native )
00405           enum_native_events( stdout, cidx);
00406        if ( preset )
00407           enum_preset_events( stdout, cidx);
00408 
00409        fprintf( stdout, "</component>\n" );
00410     } 
00411     else {
00412        /* Otherwise, print info for all components */
00413        for ( cidx = 0; cidx < numc; cidx++ ) {
00414            comp = PAPI_get_component_info( cidx );
00415 
00416            fprintf( stdout, "<component index=\"%d\" type=\"%s\" id=\"%s\">\n",
00417                 cidx, cidx ? "Unknown" : "CPU", comp->name );
00418 
00419            if ( native )
00420           enum_native_events( stdout, cidx );
00421            if ( preset )
00422           enum_preset_events( stdout, cidx );
00423 
00424            fprintf( stdout, "</component>\n" );
00425 
00426            /* clean out eventset */
00427            retval = PAPI_cleanup_eventset( EventSet );
00428            if ( retval != PAPI_OK )
00429           test_fail( __FILE__, __LINE__, "PAPI_cleanup_eventset", retval );
00430            retval = PAPI_destroy_eventset( &EventSet );
00431            if ( retval != PAPI_OK )
00432           test_fail( __FILE__, __LINE__, "PAPI_destroy_eventset", retval );
00433            EventSet = PAPI_NULL;
00434 
00435            retval = PAPI_create_eventset( &EventSet  );
00436            if ( retval != PAPI_OK ) {
00437           test_fail( __FILE__, __LINE__, "PAPI_create_eventset", retval );          }
00438 
00439            /* re-parse command line to set up any events specified */
00440            parse_command_line (argc, argv, numc);
00441            
00442 
00443        }
00444     }
00445     fprintf( stdout, "</eventinfo>\n" );
00446 
00447     return 0;
00448 }

Here is the call graph for this function:

static int papi_xml_hwinfo ( FILE *  f  )  [static]

Definition at line 82 of file event_info.c.

00083 {
00084     const PAPI_hw_info_t *hwinfo;
00085 
00086     if ( ( hwinfo = PAPI_get_hardware_info(  ) ) == NULL )
00087         return PAPI_ESYS;
00088 
00089     fprintf( f, "<hardware>\n" );
00090 
00091     fprintf( f, "  <vendor string=\"");
00092        xmlize( hwinfo->vendor_string, f );
00093        fprintf( f,"\"/>\n");
00094     fprintf( f, "  <vendorCode value=\"%d\"/>\n", hwinfo->vendor );
00095     fprintf( f, "  <model string=\"");
00096     xmlize( hwinfo->model_string, f );
00097        fprintf( f, "\"/>\n");
00098     fprintf( f, "  <modelCode value=\"%d\"/>\n", hwinfo->model );
00099     fprintf( f, "  <cpuRevision value=\"%f\"/>\n", hwinfo->revision );
00100     fprintf( f, "  <cpuID>\n" );
00101     fprintf( f, "    <family value=\"%d\"/>\n", hwinfo->cpuid_family );
00102     fprintf( f, "    <model value=\"%d\"/>\n", hwinfo->cpuid_model );
00103     fprintf( f, "    <stepping value=\"%d\"/>\n", hwinfo->cpuid_stepping );
00104     fprintf( f, "  </cpuID>\n" );
00105     fprintf( f, "  <cpuMaxMegahertz value=\"%d\"/>\n", hwinfo->cpu_max_mhz );
00106     fprintf( f, "  <cpuMinMegahertz value=\"%d\"/>\n", hwinfo->cpu_min_mhz );
00107     fprintf( f, "  <threads value=\"%d\"/>\n", hwinfo->threads );
00108     fprintf( f, "  <cores value=\"%d\"/>\n", hwinfo->cores );
00109     fprintf( f, "  <sockets value=\"%d\"/>\n", hwinfo->sockets );
00110     fprintf( f, "  <nodes value=\"%d\"/>\n", hwinfo->nnodes );
00111     fprintf( f, "  <cpuPerNode value=\"%d\"/>\n", hwinfo->ncpu );
00112     fprintf( f, "  <totalCPUs value=\"%d\"/>\n", hwinfo->totalcpus );
00113     fprintf( f, "</hardware>\n" );
00114 
00115     return PAPI_OK;
00116 }

Here is the call graph for this function:

Here is the caller graph for this function:

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

Definition at line 276 of file event_info.c.

00276                                                      {
00277 
00278   int i,retval;
00279 
00280      for( i = 1; i < argc; i++ ) {
00281     if ( argv[i][0] == '-' ) {
00282        switch ( argv[i][1] ) {
00283           case 'c': 
00284                          /* only events for specified component */
00285 
00286                          /* UGH, what is this, the IOCCC? */
00287                          cidx = (i+1) < argc ? atoi( argv[(i++)+1] ) : -1;
00288              if ( cidx < 0 || cidx >= numc ) {
00289                 fprintf( stderr,"Error: component index %d out of bounds (0..%d)\n",
00290                      cidx, numc - 1 );
00291                 usage( argv );
00292                 exit(1);
00293              }
00294              break;
00295 
00296           case 'p':
00297                  /* only preset events */
00298              preset = 1;
00299              native = 0;
00300              break;
00301 
00302           case 'n':
00303                  /* only native events */
00304              native = 1;
00305              preset = 0;
00306              break;
00307 
00308           case 'h':
00309                  /* print help */
00310              usage( argv );
00311              exit(0);
00312              break;
00313 
00314           default:
00315              fprintf( stderr, 
00316                      "Error: unknown option: %s\n", argv[i] );
00317              usage( argv );
00318              exit(1);
00319        }
00320     } else {
00321 
00322        /* If event names are specified, add them to the */
00323        /* EventSet and test if other events can be run with them */
00324 
00325        int code = -1;
00326 
00327        retval = PAPI_event_name_to_code( argv[i], &code );
00328        retval = PAPI_query_event( code );
00329        if ( retval != PAPI_OK ) {
00330           fprintf( stderr, "Error: unknown event: %s\n", argv[i] );
00331           usage( argv );
00332           exit(1);
00333        }
00334 
00335        retval = PAPI_add_event( EventSet, code );
00336        if ( retval != PAPI_OK ) {
00337           fprintf( stderr, 
00338                        "Error: event %s cannot be counted with others\n",
00339                argv[i] );
00340           usage( argv );
00341           exit(1);
00342        }
00343     }
00344      }
00345 
00346 }

Here is the call graph for this function:

Here is the caller graph for this function:

static int test_event ( int  evt  )  [static]

Definition at line 126 of file event_info.c.

00127 {
00128     int retval;
00129 
00130     retval = PAPI_add_event( EventSet, evt );
00131     if ( retval != PAPI_OK ) {
00132         return retval;
00133     }
00134 
00135     if ( ( retval = PAPI_remove_event( EventSet, evt ) ) != PAPI_OK ) {
00136        fprintf( stderr, "Error removing event from eventset\n" );
00137        exit( 1 );
00138     }
00139     return PAPI_OK;
00140 }

Here is the call graph for this function:

Here is the caller graph for this function:

static void usage ( char *  argv[]  )  [static]

Definition at line 264 of file event_info.c.

00265 {
00266     fprintf( stderr, "Usage: %s [options] [[event1] event2 ...]\n", argv[0] );
00267     fprintf( stderr, "     options: -h     print help message\n" );
00268     fprintf( stderr, "              -p     print only preset events\n" );
00269     fprintf( stderr, "              -n     print only native events\n" );
00270     fprintf( stderr,"              -c n   print only events for component index n\n" );
00271     fprintf( stderr, "If event1, event2, etc., are specified, then only events\n");
00272     fprintf( stderr, "that can be run in addition to these events will be printed\n\n");
00273 }

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

Definition at line 46 of file event_info.c.

00047 {
00048     const char *op;
00049 
00050     if ( !msg )
00051         return PAPI_OK;
00052 
00053     for ( op = msg; *op != '\0'; op++ ) {
00054         switch ( *op ) {
00055         case '"':
00056             fprintf( f, "&quot;" );
00057             break;
00058         case '&':
00059             fprintf( f, "&amp;" );
00060             break;
00061         case '\'':
00062             fprintf( f, "&apos;" );
00063             break;
00064         case '<':
00065             fprintf( f, "&lt;" );
00066             break;
00067         case '>':
00068             fprintf( f, "&gt;" );
00069             break;
00070         default:
00071                 fprintf( f, "%c", *op);
00072         }
00073     }
00074 
00075     return PAPI_OK;
00076 }

Here is the caller graph for this function:

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

Definition at line 147 of file event_info.c.

00148 {
00149 
00150     if ( num >= 0 ) {
00151        fprintf( f, "    <event index=\"%d\" name=\"",num);
00152        xmlize( info->symbol, f );
00153        fprintf( f, "\" desc=\"");
00154        xmlize( info->long_descr, f );
00155        fprintf( f, "\">\n");
00156     }
00157     else {
00158        fprintf( f,"        <modifier name=\"");
00159        xmlize( info->symbol, f );
00160        fprintf( f,"\" desc=\"");
00161        xmlize( info->long_descr, f );
00162        fprintf( f,"\"> </modifier>\n");
00163     }
00164 
00165 }

Here is the call graph for this function:

Here is the caller graph for this function:


Variable Documentation

int cidx = -1 [static]

Definition at line 40 of file event_info.c.

int EventSet [static]

Definition at line 37 of file event_info.c.

int native = 1 [static]

Definition at line 39 of file event_info.c.

int preset = 1 [static]

Definition at line 38 of file event_info.c.


Generated on 26 Jan 2016 for PAPI by  doxygen 1.6.1