|
PAPI
5.0.1.0
|
00001 00011 #include <stdio.h> 00012 #include <stdlib.h> 00013 #include "papi_test.h" 00014 00015 #define NUM_EVENTS 1 00016 00017 int main (int argc, char **argv) 00018 { 00019 00020 int retval,cid,numcmp; 00021 int EventSet = PAPI_NULL; 00022 long long values[NUM_EVENTS]; 00023 int code; 00024 char event_name[PAPI_MAX_STR_LEN]; 00025 int total_events=0; 00026 int r; 00027 const PAPI_component_info_t *cmpinfo = NULL; 00028 00029 /* Set TESTS_QUIET variable */ 00030 tests_quiet( argc, argv ); 00031 00032 /* PAPI Initialization */ 00033 retval = PAPI_library_init( PAPI_VER_CURRENT ); 00034 if ( retval != PAPI_VER_CURRENT ) { 00035 test_fail(__FILE__, __LINE__,"PAPI_library_init failed\n",retval); 00036 } 00037 00038 if (!TESTS_QUIET) { 00039 printf("Trying all vmware events\n"); 00040 } 00041 00042 /* Find our Component */ 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", 0); 00050 } 00051 00052 if (strstr(cmpinfo->name,"vmware")) { 00053 if (!TESTS_QUIET) printf("\tFound vmware component %d - %s\n", cid, cmpinfo->name); 00054 } 00055 else { 00056 continue; 00057 } 00058 00059 PAPI_event_info_t info; 00060 00061 /* Try all events one by one */ 00062 00063 code = PAPI_NATIVE_MASK; 00064 00065 r = PAPI_enum_cmp_event( &code, PAPI_ENUM_FIRST, cid ); 00066 00067 while ( r == PAPI_OK ) { 00068 00069 retval=PAPI_get_event_info(code,&info); 00070 if (retval!=PAPI_OK) { 00071 printf("Error getting event info\n"); 00072 test_fail( __FILE__, __LINE__, 00073 "PAPI_get_event_info", retval ); 00074 } 00075 00076 retval = PAPI_event_code_to_name( code, event_name ); 00077 if ( retval != PAPI_OK ) { 00078 printf("Error translating %x\n",code); 00079 test_fail( __FILE__, __LINE__, 00080 "PAPI_event_code_to_name", retval ); 00081 } 00082 00083 if (!TESTS_QUIET) printf(" %s ",event_name); 00084 00085 EventSet = PAPI_NULL; 00086 00087 retval = PAPI_create_eventset( &EventSet ); 00088 if (retval != PAPI_OK) { 00089 test_fail(__FILE__, __LINE__, 00090 "PAPI_create_eventset()",retval); 00091 } 00092 00093 retval = PAPI_add_event( EventSet, code ); 00094 if (retval != PAPI_OK) { 00095 test_fail(__FILE__, __LINE__, 00096 "PAPI_add_event()",retval); 00097 } 00098 00099 /* start */ 00100 retval = PAPI_start( EventSet); 00101 if (retval != PAPI_OK) { 00102 test_fail(__FILE__, __LINE__, "PAPI_start()",retval); 00103 } 00104 00105 /* do something */ 00106 usleep(100); 00107 00108 /* stop */ 00109 retval = PAPI_stop( EventSet, values); 00110 if (retval != PAPI_OK) { 00111 test_fail(__FILE__, __LINE__, "PAPI_start()",retval); 00112 } 00113 00114 if (!TESTS_QUIET) printf(" value: %lld %s\n",values[0], 00115 info.units); 00116 00117 retval = PAPI_cleanup_eventset( EventSet ); 00118 if (retval != PAPI_OK) { 00119 test_fail(__FILE__, __LINE__, 00120 "PAPI_cleanup_eventset()",retval); 00121 } 00122 00123 retval = PAPI_destroy_eventset( &EventSet ); 00124 if (retval != PAPI_OK) { 00125 test_fail(__FILE__, __LINE__, 00126 "PAPI_destroy_eventset()",retval); 00127 } 00128 00129 total_events++; 00130 00131 r = PAPI_enum_cmp_event( &code, PAPI_ENUM_EVENTS, cid ); 00132 } 00133 } 00134 00135 if (total_events==0) { 00136 test_skip(__FILE__,__LINE__,"No vmware events found",0); 00137 } 00138 00139 if (!TESTS_QUIET) { 00140 printf("\n"); 00141 } 00142 00143 test_pass( __FILE__, NULL, 0 ); 00144 00145 return 0; 00146 } 00147