|
PAPI
5.0.1.0
|
00001 /* file command_line.c 00002 * This simply tries to add the events listed on the command line one at a time 00003 * then starts and stops the counters and prints the results 00004 */ 00005 00028 #include "papi_test.h" 00029 00030 int 00031 main( int argc, char **argv ) 00032 { 00033 int retval; 00034 int num_events; 00035 long long *values; 00036 char *success; 00037 int EventSet = PAPI_NULL; 00038 int i, j, event; 00039 char errstr[PAPI_HUGE_STR_LEN]; 00040 00041 tests_quiet( argc, argv ); /* Set TESTS_QUIET variable */ 00042 00043 00044 if ( ( retval = 00045 PAPI_library_init( PAPI_VER_CURRENT ) ) != PAPI_VER_CURRENT ) 00046 test_fail( __FILE__, __LINE__, "PAPI_library_init", retval ); 00047 00048 if ( ( retval = PAPI_create_eventset( &EventSet ) ) != PAPI_OK ) 00049 test_fail( __FILE__, __LINE__, "PAPI_create_eventset", retval ); 00050 00051 if ( TESTS_QUIET ) 00052 i = 2; 00053 else 00054 i = 1; 00055 00056 num_events = argc - i; 00057 00058 /* Automatically pass if no events, for run_tests.sh */ 00059 if ( num_events == 0 ) 00060 test_pass( __FILE__, NULL, 0 ); 00061 00062 values = 00063 ( long long * ) malloc( sizeof ( long long ) * ( size_t ) num_events ); 00064 success = ( char * ) malloc( ( size_t ) argc ); 00065 00066 if ( success == NULL || values == NULL ) 00067 test_fail_exit( __FILE__, __LINE__, "malloc", PAPI_ESYS ); 00068 00069 for ( ; i < argc; i++ ) { 00070 if ( ( retval = 00071 PAPI_event_name_to_code( argv[i], &event ) ) != PAPI_OK ) 00072 test_fail_exit( __FILE__, __LINE__, "PAPI_event_name_to_code", retval ); 00073 00074 if ( ( retval = PAPI_add_event( EventSet, event ) ) != PAPI_OK ) { 00075 PAPI_perror( "PAPI_add_event"); 00076 printf( "Failed adding: %s\nbecause: %s\n", argv[i], errstr ); 00077 success[i] = 0; 00078 } else { 00079 success[i] = 1; 00080 printf( "Successfully added: %s\n", argv[i] ); 00081 } 00082 } 00083 printf( "\n" ); 00084 00085 do_flops( 1 ); 00086 do_flush( ); 00087 00088 if ( ( retval = PAPI_start( EventSet ) ) != PAPI_OK ) 00089 test_fail_exit( __FILE__, __LINE__, "PAPI_start", retval ); 00090 00091 do_flops( NUM_FLOPS ); 00092 do_misses( 1, L1_MISS_BUFFER_SIZE_INTS ); 00093 00094 if ( ( retval = PAPI_stop( EventSet, values ) ) != PAPI_OK ) 00095 test_fail_exit( __FILE__, __LINE__, "PAPI_stop", retval ); 00096 00097 for ( i = 1, j = 0; i < argc; i++ ) { 00098 if ( success[i] ) { 00099 printf( "%s : \t%lld\n", argv[i], values[j++] ); 00100 } else { 00101 printf( "%s : \t---------\n", argv[i] ); 00102 } 00103 } 00104 00105 printf( "\n----------------------------------\n" ); 00106 printf 00107 ( "Verification: Checks for valid event name.\n This utility lets you add events from the command line interface to see if they work.\n" ); 00108 test_pass( __FILE__, NULL, 0 ); 00109 exit( 1 ); 00110 }