api.c File Reference

Include dependency graph for api.c:

Go to the source code of this file.

Functions

int main (int argc, char **argv)

Function Documentation

int main ( int  argc,
char **  argv 
)

Definition at line 16 of file api.c.

00017 {
00018     const int NUM_COUNTERS = 1;
00019     int Events[] = { PAPI_TOT_INS };
00020     long long values[NUM_COUNTERS];
00021     float rtime, ptime, ipc, mflips, mflops;
00022     long long ins, flpins, flpops;
00023     int retval;
00024 
00025     tests_quiet( argc, argv );
00026 
00027     retval = PAPI_library_init( PAPI_VER_CURRENT );
00028     if ( retval != PAPI_VER_CURRENT )
00029         test_fail( __FILE__, __LINE__, "PAPI_library_init", retval );
00030 
00031 
00032     /****** High Level API ******/
00033 
00034     if ( !TESTS_QUIET )
00035         printf( "Testing PAPI_num_components... " );
00036 
00037     /* get the number of components available on the system */
00038     retval = PAPI_num_components(  );
00039     if ( !TESTS_QUIET ) printf( "%d\n", retval );
00040 
00041     if ( retval == 0) {
00042        if ( !TESTS_QUIET ) printf( "No components found, skipping high level tests\n");
00043     }
00044 
00045     else {
00046     
00047        if ( !TESTS_QUIET ) printf( "Testing PAPI_num_counters... " );
00048 
00049        /* get the number of hardware counters available on the system  */
00050            retval = PAPI_num_counters(  );  
00051        if ( retval != PAPI_get_cmp_opt( PAPI_MAX_HWCTRS, NULL, 0 ) )
00052           test_fail_exit( __FILE__, __LINE__, "PAPI_num_counters", retval );
00053        else if ( !TESTS_QUIET ) printf( "%d\n", retval );
00054 
00055 
00056        if ( !TESTS_QUIET ) printf( "Testing PAPI_start_counters... " );
00057        retval = PAPI_start_counters( NULL, NUM_COUNTERS );  // pass invalid 1st argument
00058        if ( retval != PAPI_EINVAL )
00059         test_fail_exit( __FILE__, __LINE__, "PAPI_start_counters", retval );
00060        retval = PAPI_start_counters( Events, 0 );   // pass invalid 2nd argument
00061        if ( retval != PAPI_EINVAL )
00062         test_fail_exit( __FILE__, __LINE__, "PAPI_start_counters", retval );
00063        retval = PAPI_start_counters( Events, NUM_COUNTERS );    // start counting hardware events
00064        if ( retval != PAPI_OK )
00065         test_fail_exit( __FILE__, __LINE__, "PAPI_start_counters", retval );
00066        else if ( !TESTS_QUIET )
00067         printf( "started PAPI_TOT_INS\n" );
00068 
00069 
00070        if ( !TESTS_QUIET )
00071         printf( "Testing PAPI_stop_counters... " );
00072        retval = PAPI_stop_counters( NULL, NUM_COUNTERS );   // pass invalid 1st argument
00073        if ( retval != PAPI_EINVAL )
00074         test_fail_exit( __FILE__, __LINE__, "PAPI_stop_counters", retval );
00075        retval = PAPI_stop_counters( values, 0 );    // pass invalid 2nd argument
00076        if ( retval != PAPI_EINVAL )
00077         test_fail_exit( __FILE__, __LINE__, "PAPI_stop_counters", retval );
00078        retval = PAPI_stop_counters( values, NUM_COUNTERS ); // stop counters and return current counts
00079        if ( retval != PAPI_OK )
00080         test_fail_exit( __FILE__, __LINE__, "PAPI_stop_counters", retval );
00081        else if ( !TESTS_QUIET )
00082         printf( "stopped counting PAPI_TOT_INS\n" );
00083     //NOTE: There are currently no checks on whether or not counter values are correct 
00084 
00085 
00086        retval = PAPI_start_counters( Events, NUM_COUNTERS );    // start counting hardware events again
00087        if ( retval != PAPI_OK )
00088         test_fail_exit( __FILE__, __LINE__, "PAPI_start_counters", retval );
00089 
00090 
00091        if ( !TESTS_QUIET )
00092         printf( "Testing PAPI_read_counters... " );
00093        retval = PAPI_read_counters( NULL, NUM_COUNTERS );   // pass invalid 1st argument
00094        if ( retval != PAPI_EINVAL )
00095         test_fail_exit( __FILE__, __LINE__, "PAPI_read_counters", retval );
00096        retval = PAPI_read_counters( values, 0 );    // pass invalid 2nd argument
00097        if ( retval != PAPI_EINVAL )
00098         test_fail_exit( __FILE__, __LINE__, "PAPI_read_counters", retval );
00099        retval = PAPI_read_counters( values, NUM_COUNTERS ); // copy current counts to array and reset counters
00100        if ( retval != PAPI_OK )
00101         test_fail_exit( __FILE__, __LINE__, "PAPI_read_counters", retval );
00102        else if ( !TESTS_QUIET )
00103         printf( "read PAPI_TOT_INS counts and reset counter\n" );
00104     //NOTE: There are currently no checks on whether or not counter values are correct 
00105 
00106 
00107        if ( !TESTS_QUIET )
00108         printf( "Testing PAPI_accum_counters... " );
00109        retval = PAPI_accum_counters( NULL, NUM_COUNTERS );  // pass invalid 1st argument
00110        if ( retval != PAPI_EINVAL )
00111         test_fail_exit( __FILE__, __LINE__, "PAPI_accum_counters", retval );
00112        retval = PAPI_accum_counters( values, 0 );   // pass invalid 2nd argument
00113        if ( retval != PAPI_EINVAL )
00114         test_fail_exit( __FILE__, __LINE__, "PAPI_accum_counters", retval );
00115        retval = PAPI_accum_counters( values, NUM_COUNTERS );    // add current counts to array and reset counters
00116        if ( retval != PAPI_OK )
00117         test_fail_exit( __FILE__, __LINE__, "PAPI_accum_counters", retval );
00118        else if ( !TESTS_QUIET )
00119         printf( "added PAPI_TOT_INS counts and reset counter\n" );
00120     //NOTE: There are currently no checks on whether or not counter values are correct 
00121 
00122 
00123        retval = PAPI_stop_counters( values, NUM_COUNTERS ); // stop counting hardware events 
00124        if ( retval != PAPI_OK )
00125         test_fail_exit( __FILE__, __LINE__, "PAPI_stop_counters", retval );
00126 
00127 
00128        if ( !TESTS_QUIET )
00129         printf( "Testing PAPI_ipc... " );
00130        retval = PAPI_ipc( NULL, &ptime, &ins, &ipc );   // pass invalid 1st argument
00131        if ( retval != PAPI_EINVAL )
00132         test_fail_exit( __FILE__, __LINE__, "PAPI_ipc", retval );
00133        retval = PAPI_ipc( &rtime, NULL, &ins, &ipc );   // pass invalid 2nd argument
00134        if ( retval != PAPI_EINVAL )
00135         test_fail_exit( __FILE__, __LINE__, "PAPI_ipc", retval );
00136        retval = PAPI_ipc( &rtime, &ptime, NULL, &ipc ); // pass invalid 3rd argument
00137        if ( retval != PAPI_EINVAL )
00138         test_fail_exit( __FILE__, __LINE__, "PAPI_ipc", retval );
00139        retval = PAPI_ipc( &rtime, &ptime, &ins, NULL ); // pass invalid 4th argument
00140        if ( retval != PAPI_EINVAL )
00141         test_fail_exit( __FILE__, __LINE__, "PAPI_ipc", retval );
00142        retval = PAPI_ipc( &rtime, &ptime, &ins, &ipc ); // get instructions per cycle, real and processor time 
00143        if ( retval != PAPI_OK )
00144         test_fail_exit( __FILE__, __LINE__, "PAPI_ipc", retval );
00145        else if ( !TESTS_QUIET )
00146         printf( "got instructions per cycle, real and processor time\n" );
00147     //NOTE: There are currently no checks on whether or not returned values are correct 
00148 
00149 
00150     //NOTE: PAPI_flips and PAPI_flops fail if any other low-level calls have been made!
00151        PAPI_shutdown(  );
00152        retval = PAPI_library_init( PAPI_VER_CURRENT );
00153        if ( retval != PAPI_VER_CURRENT )
00154         test_fail( __FILE__, __LINE__, "PAPI_library_init", retval );
00155 
00156 
00157        if ( !TESTS_QUIET )
00158         printf( "Testing PAPI_flips... " );
00159        retval = PAPI_flips( NULL, &ptime, &flpins, &mflips );   // pass invalid 1st argument
00160        if ( retval != PAPI_EINVAL )
00161         test_fail_exit( __FILE__, __LINE__, "PAPI_flips", retval );
00162        retval = PAPI_flips( &rtime, NULL, &flpins, &mflips );   // pass invalid 2nd argument
00163        if ( retval != PAPI_EINVAL )
00164         test_fail_exit( __FILE__, __LINE__, "PAPI_flips", retval );
00165        retval = PAPI_flips( &rtime, &ptime, NULL, &mflips );    // pass invalid 3rd argument
00166        if ( retval != PAPI_EINVAL )
00167         test_fail_exit( __FILE__, __LINE__, "PAPI_flips", retval );
00168        retval = PAPI_flips( &rtime, &ptime, &flpins, NULL );    // pass invalid 4th argument
00169        if ( retval != PAPI_EINVAL )
00170         test_fail_exit( __FILE__, __LINE__, "PAPI_flips", retval );
00171        retval = PAPI_flips( &rtime, &ptime, &flpins, &mflips ); // get Mflips/s, real and processor time 
00172        if ( retval == PAPI_ENOEVNT )
00173         test_warn( __FILE__, __LINE__, "PAPI_flips", retval);
00174        else if ( retval != PAPI_OK )
00175         test_fail_exit( __FILE__, __LINE__, "PAPI_flips", retval );
00176        else if ( !TESTS_QUIET )
00177         printf( "got Mflips/s, real and processor time\n" );
00178     //NOTE: There are currently no checks on whether or not returned values are correct 
00179 
00180 
00181        PAPI_shutdown(  );
00182        retval = PAPI_library_init( PAPI_VER_CURRENT );
00183        if ( retval != PAPI_VER_CURRENT )
00184         test_fail( __FILE__, __LINE__, "PAPI_library_init", retval );
00185 
00186 
00187        if ( !TESTS_QUIET )
00188         printf( "Testing PAPI_flops... " );
00189        retval = PAPI_flops( NULL, &ptime, &flpops, &mflops );   // pass invalid 1st argument
00190        if ( retval != PAPI_EINVAL )
00191         test_fail_exit( __FILE__, __LINE__, "PAPI_flops", retval );
00192        retval = PAPI_flops( &rtime, NULL, &flpops, &mflops );   // pass invalid 2nd argument
00193        if ( retval != PAPI_EINVAL )
00194         test_fail_exit( __FILE__, __LINE__, "PAPI_flops", retval );
00195        retval = PAPI_flops( &rtime, &ptime, NULL, &mflops );    // pass invalid 3rd argument
00196        if ( retval != PAPI_EINVAL )
00197         test_fail_exit( __FILE__, __LINE__, "PAPI_flops", retval );
00198        retval = PAPI_flops( &rtime, &ptime, &flpops, NULL );    // pass invalid 4th argument
00199        if ( retval != PAPI_EINVAL )
00200         test_fail_exit( __FILE__, __LINE__, "PAPI_flops", retval );
00201        retval = PAPI_flops( &rtime, &ptime, &flpops, &mflops ); // get Mflops/s, real and processor time 
00202        if ( retval == PAPI_ENOEVNT )
00203         test_warn( __FILE__, __LINE__, "PAPI_flops", retval);
00204        else if ( retval != PAPI_OK ) {
00205         test_fail_exit( __FILE__, __LINE__, "PAPI_flops", retval ); }
00206        else if ( !TESTS_QUIET ) {
00207         printf( "got Mflops/s, real and processor time\n" ); }
00208     //NOTE: There are currently no checks on whether or not returned values are correct 
00209     }
00210 
00211         /***************************/
00212     /****** Low Level API ******/
00213     /***************************/
00214 /*
00215    int   PAPI_accum(int EventSet, long long * values); // accumulate and reset hardware events from an event set
00216    int   PAPI_add_event(int EventSet, int Event); // add single PAPI preset or native hardware event to an event set
00217    int   PAPI_add_events(int EventSet, int *Events, int number); // add array of PAPI preset or native hardware events to an event set
00218    int   PAPI_assign_eventset_component(int EventSet, int cidx); // assign a component index to an existing but empty eventset
00219    int   PAPI_attach(int EventSet, unsigned long tid); // attach specified event set to a specific process or thread id
00220    int   PAPI_cleanup_eventset(int EventSet); // remove all PAPI events from an event set
00221    int   PAPI_create_eventset(int *EventSet); // create a new empty PAPI event set
00222    int   PAPI_detach(int EventSet); // detach specified event set from a previously specified process or thread id
00223    int   PAPI_destroy_eventset(int *EventSet); // deallocates memory associated with an empty PAPI event set
00224    int   PAPI_enum_event(int *EventCode, int modifier); // return the event code for the next available preset or natvie event
00225    int   PAPI_event_code_to_name(int EventCode, char *out); // translate an integer PAPI event code into an ASCII PAPI preset or native name
00226    int   PAPI_event_name_to_code(char *in, int *out); // translate an ASCII PAPI preset or native name into an integer PAPI event code
00227    int  PAPI_get_dmem_info(PAPI_dmem_info_t *dest); // get dynamic memory usage information
00228    int   PAPI_get_event_info(int EventCode, PAPI_event_info_t * info); // get the name and descriptions for a given preset or native event code
00229    const PAPI_exe_info_t *PAPI_get_executable_info(void); // get the executable's address space information
00230    const PAPI_hw_info_t *PAPI_get_hardware_info(void); // get information about the system hardware
00231    const PAPI_component_info_t *PAPI_get_component_info(int cidx); // get information about the component features
00232    int   PAPI_get_multiplex(int EventSet); // get the multiplexing status of specified event set
00233    int   PAPI_get_opt(int option, PAPI_option_t * ptr); // query the option settings of the PAPI library or a specific event set
00234    int   PAPI_get_cmp_opt(int option, PAPI_option_t * ptr,int cidx); // query the component specific option settings of a specific event set
00235    long long PAPI_get_real_cyc(void); // return the total number of cycles since some arbitrary starting point
00236    long long PAPI_get_real_nsec(void); // return the total number of nanoseconds since some arbitrary starting point
00237    long long PAPI_get_real_usec(void); // return the total number of microseconds since some arbitrary starting point
00238    const PAPI_shlib_info_t *PAPI_get_shared_lib_info(void); // get information about the shared libraries used by the process
00239    int   PAPI_get_thr_specific(int tag, void **ptr); // return a pointer to a thread specific stored data structure
00240    int   PAPI_get_overflow_event_index(int Eventset, long long overflow_vector, int *array, int *number); // # decomposes an overflow_vector into an event index array
00241    long long PAPI_get_virt_cyc(void); // return the process cycles since some arbitrary starting point
00242    long long PAPI_get_virt_nsec(void); // return the process nanoseconds since some arbitrary starting point
00243    long long PAPI_get_virt_usec(void); // return the process microseconds since some arbitrary starting point
00244    int   PAPI_is_initialized(void); // return the initialized state of the PAPI library
00245    int   PAPI_library_init(int version); // initialize the PAPI library
00246    int   PAPI_list_events(int EventSet, int *Events, int *number); // list the events that are members of an event set
00247    int   PAPI_list_threads(unsigned long *tids, int *number); // list the thread ids currently known to PAPI
00248    int   PAPI_lock(int); // lock one of two PAPI internal user mutex variables
00249    int   PAPI_multiplex_init(void); // initialize multiplex support in the PAPI library
00250    int   PAPI_num_hwctrs(void); // return the number of hardware counters for the cpu
00251    int   PAPI_num_cmp_hwctrs(int cidx); // return the number of hardware counters for a specified component
00252    int   PAPI_num_hwctrs(void); // for backward compatibility
00253    int   PAPI_num_events(int EventSet); // return the number of events in an event set
00254    int   PAPI_overflow(int EventSet, int EventCode, int threshold,
00255                      int flags, PAPI_overflow_handler_t handler); // set up an event set to begin registering overflows
00256    int   PAPI_perror( char *msg); // convert PAPI error codes to strings
00257    int   PAPI_profil(void *buf, unsigned bufsiz, caddr_t offset, 
00258                      unsigned scale, int EventSet, int EventCode, 
00259                      int threshold, int flags); // generate PC histogram data where hardware counter overflow occurs
00260    int   PAPI_query_event(int EventCode); // query if a PAPI event exists
00261    int   PAPI_read(int EventSet, long long * values); // read hardware events from an event set with no reset
00262    int   PAPI_read_ts(int EventSet, long long * values, long long *cyc);
00263    int   PAPI_register_thread(void); // inform PAPI of the existence of a new thread
00264    int   PAPI_remove_event(int EventSet, int EventCode); // remove a hardware event from a PAPI event set
00265    int   PAPI_remove_events(int EventSet, int *Events, int number); // remove an array of hardware events from a PAPI event set
00266    int   PAPI_reset(int EventSet); // reset the hardware event counts in an event set
00267    int   PAPI_set_debug(int level); // set the current debug level for PAPI
00268    int   PAPI_set_cmp_domain(int domain, int cidx); // set the component specific default execution domain for new event sets
00269    int   PAPI_set_domain(int domain); // set the default execution domain for new event sets 
00270    int   PAPI_set_cmp_granularity(int granularity, int cidx); // set the component specific default granularity for new event sets
00271    int   PAPI_set_granularity(int granularity); //set the default granularity for new event sets
00272    int   PAPI_set_multiplex(int EventSet); // convert a standard event set to a multiplexed event set
00273    int   PAPI_set_opt(int option, PAPI_option_t * ptr); // change the option settings of the PAPI library or a specific event set
00274    int   PAPI_set_thr_specific(int tag, void *ptr); // save a pointer as a thread specific stored data structure
00275    void  PAPI_shutdown(void); // finish using PAPI and free all related resources
00276    int   PAPI_sprofil(PAPI_sprofil_t * prof, int profcnt, int EventSet, int EventCode, int threshold, int flags); // generate hardware counter profiles from multiple code regions
00277    int   PAPI_start(int EventSet); // start counting hardware events in an event set
00278    int   PAPI_state(int EventSet, int *status); // return the counting state of an event set
00279    int   PAPI_stop(int EventSet, long long * values); // stop counting hardware events in an event set and return current events
00280    char *PAPI_strerror(int); // return a pointer to the error message corresponding to a specified error code
00281    unsigned long PAPI_thread_id(void); // get the thread identifier of the current thread
00282    int   PAPI_thread_init(unsigned long (*id_fn) (void)); // initialize thread support in the PAPI library
00283    int   PAPI_unlock(int); // unlock one of two PAPI internal user mutex variables
00284    int   PAPI_unregister_thread(void); // inform PAPI that a previously registered thread is disappearing
00285    int   PAPI_write(int EventSet, long long * values); // write counter values into counters
00286 */
00287     test_pass( __FILE__, NULL, 0 );
00288     exit( 1 );
00289 }

Here is the call graph for this function:


Generated on 17 Nov 2016 for PAPI by  doxygen 1.6.1