command_line.c File Reference

Include dependency graph for command_line.c:

Go to the source code of this file.

Functions

static void print_help (char **argv)
int main (int argc, char **argv)

Function Documentation

int main ( int  argc,
char **  argv 
)

Definition at line 51 of file command_line.c.

00052 {
00053     int retval;
00054     int num_events;
00055     long long *values;
00056     char *success;
00057     PAPI_event_info_t info;
00058     int EventSet = PAPI_NULL;
00059     int i, j, event, data_type = PAPI_DATATYPE_INT64;
00060     int u_format = 0;
00061     int hex_format = 0;
00062 
00063     tests_quiet( argc, argv );  /* Set TESTS_QUIET variable */
00064 
00065     if ( ( retval =
00066            PAPI_library_init( PAPI_VER_CURRENT ) ) != PAPI_VER_CURRENT )
00067         test_fail( __FILE__, __LINE__, "PAPI_library_init", retval );
00068 
00069     if ( ( retval = PAPI_create_eventset( &EventSet ) ) != PAPI_OK )
00070         test_fail( __FILE__, __LINE__, "PAPI_create_eventset", retval );
00071 
00072     /* Automatically pass if no events, for run_tests.sh */
00073     if ((( TESTS_QUIET ) && ( argc == 2)) || ( argc == 1 )) {
00074         test_pass( __FILE__, NULL, 0 );
00075     }
00076 
00077     values =
00078         ( long long * ) malloc( sizeof ( long long ) * ( size_t ) argc );
00079     success = ( char * ) malloc( ( size_t ) argc );
00080 
00081     if ( success == NULL || values == NULL )
00082         test_fail_exit( __FILE__, __LINE__, "malloc", PAPI_ESYS );
00083 
00084     for ( num_events = 0, i = 1; i < argc; i++ ) {
00085         if ( !strcmp( argv[i], "-h" ) ) {
00086             print_help( argv );
00087             exit( 1 );
00088         } else if ( !strcmp( argv[i], "-u" ) ) {
00089             u_format = 1;
00090         } else if ( !strcmp( argv[i], "-x" ) ) {
00091             hex_format = 1;
00092         } else {
00093             if ( ( retval = PAPI_add_named_event( EventSet, argv[i] ) ) != PAPI_OK ) {
00094                 printf( "Failed adding: %s\nbecause: %s\n", argv[i], 
00095                     PAPI_strerror(retval));
00096             } else {
00097                 success[num_events++] = i;
00098                 printf( "Successfully added: %s\n", argv[i] );
00099             }
00100         }
00101     }
00102 
00103     /* Automatically pass if no events, for run_tests.sh */
00104     if ( num_events == 0 ) {
00105         test_pass( __FILE__, NULL, 0 );
00106     }
00107 
00108 
00109     printf( "\n" );
00110 
00111     do_flops( 1 );
00112     do_flush(  );
00113 
00114     if ( ( retval = PAPI_start( EventSet ) ) != PAPI_OK ) {
00115        test_fail_exit( __FILE__, __LINE__, "PAPI_start", retval );
00116     }
00117 
00118     do_flops( NUM_FLOPS );
00119     do_misses( 1, L1_MISS_BUFFER_SIZE_INTS );
00120 
00121     if ( ( retval = PAPI_stop( EventSet, values ) ) != PAPI_OK )
00122         test_fail_exit( __FILE__, __LINE__, "PAPI_stop", retval );
00123 
00124     for ( j = 0; j < num_events; j++ ) {
00125         i = success[j];
00126         if (! (u_format || hex_format) ) {
00127             retval = PAPI_event_name_to_code( argv[i], &event );
00128             if (retval == PAPI_OK) {
00129                 retval = PAPI_get_event_info(event, &info);
00130                 if (retval == PAPI_OK) data_type = info.data_type;
00131                 else data_type = PAPI_DATATYPE_INT64;
00132             }
00133             switch (data_type) {
00134               case PAPI_DATATYPE_UINT64:
00135                 printf( "%s : \t%llu(u)", argv[i], (unsigned long long)values[j] );
00136                 break;
00137               case PAPI_DATATYPE_FP64:
00138                 printf( "%s : \t%0.3f", argv[i], *((double *)(&values[j])) );
00139                 break;
00140               case PAPI_DATATYPE_BIT64:
00141                 printf( "%s : \t%#llX", argv[i], values[j] );
00142                 break;
00143               case PAPI_DATATYPE_INT64:
00144               default:
00145                 printf( "%s : \t%lld", argv[i], values[j] );
00146                 break;
00147             }
00148             if (retval == PAPI_OK)  printf( " %s", info.units );
00149             printf( "\n" );
00150         }
00151         if (u_format) printf( "%s : \t%llu(u)\n", argv[i], (unsigned long long)values[j] );
00152         if (hex_format) printf( "%s : \t%#llX\n", argv[i], values[j] );
00153     }
00154 
00155     printf( "\n----------------------------------\n" );
00156     printf
00157         ( "Verification: Checks for valid event name.\n This utility lets you add events from the command line interface to see if they work.\n" );
00158     test_pass( __FILE__, NULL, 0 );
00159     exit( 1 );
00160 }

Here is the call graph for this function:

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

Definition at line 35 of file command_line.c.

00036 {
00037     printf( "Usage: %s [options] [EVENTNAMEs]\n", argv[0] );
00038     printf( "Options:\n\n" );
00039     printf( "General command options:\n" );
00040     printf( "\t-u          Display output values as unsigned integers\n" );
00041     printf( "\t-x          Display output values as hexadecimal\n" );
00042     printf( "\t-h          Print this help message\n" );
00043     printf( "\tEVENTNAMEs  Specify one or more preset or native events\n" );
00044     printf( "\n" );
00045     printf( "This utility performs work while measuring the specified events.\n" );
00046     printf( "It can be useful for sanity checks on given events and sets of events.\n" );
00047 }

Here is the caller graph for this function:


Generated on 26 Jan 2016 for PAPI by  doxygen 1.6.1