infiniband_values_by_code.c File Reference

Include dependency graph for infiniband_values_by_code.c:

Go to the source code of this file.

Functions

int main (int argc, char **argv)
 Prints the value of every native event (by code).

Function Documentation

int main ( int  argc,
char **  argv 
)
Author:
Jose Pedro Oliveira

test case for the linux-infiniband component Adapted from its counterpart in the net component.

Definition at line 19 of file infiniband_values_by_code.c.

00020 {
00021     int retval,cid,numcmp;
00022     int EventSet = PAPI_NULL;
00023     long long *values = 0;
00024     int *codes = 0;
00025     char *names = 0;
00026     int code, i;
00027     int total_events=0;
00028     int r;
00029     const PAPI_component_info_t *cmpinfo = NULL;
00030 
00031     /* Set TESTS_QUIET variable */
00032     tests_quiet( argc, argv );
00033 
00034     /* PAPI Initialization */
00035     retval = PAPI_library_init( PAPI_VER_CURRENT );
00036     if ( retval != PAPI_VER_CURRENT ) {
00037         test_fail(__FILE__, __LINE__,"PAPI_library_init failed\n",retval);
00038     }
00039 
00040     if (!TESTS_QUIET) {
00041         printf("Trying all infiniband events\n");
00042     }
00043 
00044     numcmp = PAPI_num_components();
00045 
00046     for(cid=0; cid<numcmp; cid++) {
00047 
00048         if ( (cmpinfo = PAPI_get_component_info(cid)) == NULL) {
00049             test_fail(__FILE__, __LINE__,"PAPI_get_component_info failed\n",-1);
00050         }
00051 
00052         if (!TESTS_QUIET) {
00053             printf("Component %d - %d events - %s\n", cid,
00054                 cmpinfo->num_native_events, cmpinfo->name);
00055         }
00056 
00057         if ( strstr(cmpinfo->name, "infiniband") == NULL) {
00058             continue;
00059         }
00060         if (cmpinfo->disabled) {
00061             test_skip(__FILE__,__LINE__,"Component infiniband is disabled", 0);
00062             continue;
00063         }
00064         
00065         values = (long long*) malloc(sizeof(long long) * cmpinfo->num_native_events);
00066         codes = (int*) malloc(sizeof(int) * cmpinfo->num_native_events);
00067         names = (char*) malloc(PAPI_MAX_STR_LEN * cmpinfo->num_native_events);
00068 
00069         EventSet = PAPI_NULL;
00070 
00071         retval = PAPI_create_eventset( &EventSet );
00072         if (retval != PAPI_OK) {
00073             test_fail(__FILE__, __LINE__, "PAPI_create_eventset()", retval);
00074         }
00075 
00076         code = PAPI_NATIVE_MASK;
00077 
00078         r = PAPI_enum_cmp_event( &code, PAPI_ENUM_FIRST, cid );
00079         i = 0;
00080         while ( r == PAPI_OK ) {
00081 
00082             retval = PAPI_event_code_to_name( code, &names[i*PAPI_MAX_STR_LEN] );
00083             if ( retval != PAPI_OK ) {
00084                 test_fail( __FILE__, __LINE__, "PAPI_event_code_to_name", retval );
00085             }
00086             codes[i] = code;
00087 
00088             retval = PAPI_add_event( EventSet, code );
00089             if (retval != PAPI_OK) {
00090                 test_fail(__FILE__, __LINE__, "PAPI_add_event()", retval);
00091             }
00092 
00093             total_events++;
00094 
00095             r = PAPI_enum_cmp_event( &code, PAPI_ENUM_EVENTS, cid );
00096             i += 1;
00097         }
00098 
00099         retval = PAPI_start( EventSet );
00100         if (retval != PAPI_OK) {
00101             test_fail(__FILE__, __LINE__, "PAPI_start()", retval);
00102         }
00103 
00104         /* XXX figure out a general method to  generate some traffic 
00105          * for infiniband
00106          * the operation should take more than one second in order
00107          * to guarantee that the network counters are updated */
00108         /* For now, just sleep for 10 seconds */
00109         sleep(10);
00110 
00111         retval = PAPI_stop( EventSet, values);
00112         if (retval != PAPI_OK) {
00113             test_fail(__FILE__, __LINE__, "PAPI_stop()", retval);
00114         }
00115 
00116         if (!TESTS_QUIET) {
00117            for (i=0 ; i<cmpinfo->num_native_events ; ++i)
00118                printf("%#x %-24s = %lld\n", codes[i], names+i*PAPI_MAX_STR_LEN, values[i]);
00119         }
00120 
00121         retval = PAPI_cleanup_eventset( EventSet );
00122         if (retval != PAPI_OK) {
00123             test_fail(__FILE__, __LINE__, "PAPI_cleanup_eventset()", retval);
00124         }
00125 
00126         retval = PAPI_destroy_eventset( &EventSet );
00127         if (retval != PAPI_OK) {
00128             test_fail(__FILE__, __LINE__, "PAPI_destroy_eventset()", retval);
00129         }
00130         
00131         free(names);
00132         free(codes);
00133         free(values);
00134     }
00135 
00136     if (total_events==0) {
00137         test_skip(__FILE__,__LINE__,"No infiniband events found", 0);
00138     }
00139 
00140     test_pass( __FILE__, NULL, 0 );
00141 
00142     return 0;
00143 }

Here is the call graph for this function:


Generated on 26 Jan 2016 for PAPI by  doxygen 1.6.1