|
PAPI
5.0.1.0
|
00001 /****************************/ 00002 /* THIS IS OPEN SOURCE CODE */ 00003 /****************************/ 00004 00014 #include <stdio.h> 00015 #include <stdlib.h> 00016 #include "papi_test.h" 00017 00018 #define NUM_EVENTS 1 00019 00020 int main (int argc, char **argv) 00021 { 00022 00023 int retval,cid,coretemp_cid=-1,numcmp; 00024 int EventSet = PAPI_NULL; 00025 long long values[NUM_EVENTS]; 00026 int code; 00027 char event_name[PAPI_MAX_STR_LEN]; 00028 int r; 00029 const PAPI_component_info_t *cmpinfo = NULL; 00030 PAPI_event_info_t evinfo; 00031 double temperature; 00032 00033 /* Set TESTS_QUIET variable */ 00034 tests_quiet( argc, argv ); 00035 00036 /* PAPI Initialization */ 00037 retval = PAPI_library_init( PAPI_VER_CURRENT ); 00038 if ( retval != PAPI_VER_CURRENT ) { 00039 test_fail(__FILE__, __LINE__,"PAPI_library_init failed\n",retval); 00040 } 00041 00042 if (!TESTS_QUIET) { 00043 printf("Trying all coretemp events\n"); 00044 } 00045 00046 numcmp = PAPI_num_components(); 00047 00048 for(cid=0; cid<numcmp; cid++) { 00049 00050 if ( (cmpinfo = PAPI_get_component_info(cid)) == NULL) { 00051 test_fail(__FILE__, __LINE__,"PAPI_get_component_info failed\n", 0); 00052 } 00053 00054 if (strstr(cmpinfo->name,"coretemp")) { 00055 coretemp_cid=cid; 00056 if (!TESTS_QUIET) printf("Found coretemp component at cid %d\n", 00057 coretemp_cid); 00058 if (cmpinfo->num_native_events==0) { 00059 test_skip(__FILE__,__LINE__,"No coretemp events found",0); 00060 } 00061 break; 00062 } 00063 } 00064 00065 00066 00067 00068 code = PAPI_NATIVE_MASK; 00069 00070 r = PAPI_enum_cmp_event( &code, PAPI_ENUM_FIRST, coretemp_cid ); 00071 00072 while ( r == PAPI_OK ) { 00073 00074 retval = PAPI_event_code_to_name( code, event_name ); 00075 if ( retval != PAPI_OK ) { 00076 printf("Error translating %x\n",code); 00077 test_fail( __FILE__, __LINE__, 00078 "PAPI_event_code_to_name", retval ); 00079 } 00080 00081 retval = PAPI_get_event_info(code,&evinfo); 00082 if (retval != PAPI_OK) { 00083 test_fail( __FILE__, __LINE__, 00084 "Error getting event info\n",retval); 00085 } 00086 00087 /****************************/ 00088 /* Print Temperature Inputs */ 00089 /****************************/ 00090 if (strstr(event_name,"temp")) { 00091 00092 /* Only print inputs */ 00093 if (strstr(event_name,"_input")) { 00094 00095 if (!TESTS_QUIET) printf("%s ",event_name); 00096 00097 EventSet = PAPI_NULL; 00098 00099 retval = PAPI_create_eventset( &EventSet ); 00100 if (retval != PAPI_OK) { 00101 test_fail(__FILE__, __LINE__, 00102 "PAPI_create_eventset()",retval); 00103 } 00104 00105 retval = PAPI_add_event( EventSet, code ); 00106 if (retval != PAPI_OK) { 00107 test_fail(__FILE__, __LINE__, 00108 "PAPI_add_event()",retval); 00109 } 00110 00111 retval = PAPI_start( EventSet); 00112 if (retval != PAPI_OK) { 00113 test_fail(__FILE__, __LINE__, "PAPI_start()",retval); 00114 } 00115 00116 retval = PAPI_stop( EventSet, values); 00117 if (retval != PAPI_OK) { 00118 test_fail(__FILE__, __LINE__, "PAPI_start()",retval); 00119 } 00120 00121 temperature=(values[0]/1000.0); 00122 00123 if (!TESTS_QUIET) printf("\tvalue: %.2lf %s\n", 00124 temperature, 00125 evinfo.long_descr 00126 ); 00127 00128 retval = PAPI_cleanup_eventset( EventSet ); 00129 if (retval != PAPI_OK) { 00130 test_fail(__FILE__, __LINE__, 00131 "PAPI_cleanup_eventset()",retval); 00132 } 00133 00134 retval = PAPI_destroy_eventset( &EventSet ); 00135 if (retval != PAPI_OK) { 00136 test_fail(__FILE__, __LINE__, 00137 "PAPI_destroy_eventset()",retval); 00138 } 00139 } 00140 } 00141 00142 /****************************/ 00143 /* Print Voltage Inputs */ 00144 /****************************/ 00145 if (strstr(event_name,".in")) { 00146 00147 /* Only print inputs */ 00148 if (strstr(event_name,"_input")) { 00149 00150 if (!TESTS_QUIET) printf("%s ",event_name); 00151 00152 EventSet = PAPI_NULL; 00153 00154 retval = PAPI_create_eventset( &EventSet ); 00155 if (retval != PAPI_OK) { 00156 test_fail(__FILE__, __LINE__, 00157 "PAPI_create_eventset()",retval); 00158 } 00159 00160 retval = PAPI_add_event( EventSet, code ); 00161 if (retval != PAPI_OK) { 00162 test_fail(__FILE__, __LINE__, 00163 "PAPI_add_event()",retval); 00164 } 00165 00166 retval = PAPI_start( EventSet); 00167 if (retval != PAPI_OK) { 00168 test_fail(__FILE__, __LINE__, "PAPI_start()",retval); 00169 } 00170 00171 retval = PAPI_stop( EventSet, values); 00172 if (retval != PAPI_OK) { 00173 test_fail(__FILE__, __LINE__, "PAPI_start()",retval); 00174 } 00175 00176 temperature=(values[0]/1000.0); 00177 00178 if (!TESTS_QUIET) printf("\tvalue: %.2lf %s\n", 00179 temperature, 00180 evinfo.long_descr 00181 ); 00182 00183 retval = PAPI_cleanup_eventset( EventSet ); 00184 if (retval != PAPI_OK) { 00185 test_fail(__FILE__, __LINE__, 00186 "PAPI_cleanup_eventset()",retval); 00187 } 00188 00189 retval = PAPI_destroy_eventset( &EventSet ); 00190 if (retval != PAPI_OK) { 00191 test_fail(__FILE__, __LINE__, 00192 "PAPI_destroy_eventset()",retval); 00193 } 00194 } 00195 } 00196 /********************/ 00197 /* Print Fan Inputs */ 00198 /********************/ 00199 else if (strstr(event_name,"fan")) { 00200 00201 /* Only print inputs */ 00202 if (strstr(event_name,"_input")) { 00203 00204 if (!TESTS_QUIET) printf("%s ",event_name); 00205 00206 EventSet = PAPI_NULL; 00207 00208 retval = PAPI_create_eventset( &EventSet ); 00209 if (retval != PAPI_OK) { 00210 test_fail(__FILE__, __LINE__, 00211 "PAPI_create_eventset()",retval); 00212 } 00213 00214 retval = PAPI_add_event( EventSet, code ); 00215 if (retval != PAPI_OK) { 00216 test_fail(__FILE__, __LINE__, 00217 "PAPI_add_event()",retval); 00218 } 00219 00220 retval = PAPI_start( EventSet); 00221 if (retval != PAPI_OK) { 00222 test_fail(__FILE__, __LINE__, "PAPI_start()",retval); 00223 } 00224 00225 retval = PAPI_stop( EventSet, values); 00226 if (retval != PAPI_OK) { 00227 test_fail(__FILE__, __LINE__, "PAPI_start()",retval); 00228 } 00229 00230 if (!TESTS_QUIET) printf("\tvalue: %lld %s\n",values[0], 00231 evinfo.long_descr); 00232 00233 retval = PAPI_cleanup_eventset( EventSet ); 00234 if (retval != PAPI_OK) { 00235 test_fail(__FILE__, __LINE__, 00236 "PAPI_cleanup_eventset()",retval); 00237 } 00238 00239 retval = PAPI_destroy_eventset( &EventSet ); 00240 if (retval != PAPI_OK) { 00241 test_fail(__FILE__, __LINE__, 00242 "PAPI_destroy_eventset()",retval); 00243 } 00244 } 00245 00246 } 00247 else { 00248 /* Skip unknown */ 00249 } 00250 00251 r = PAPI_enum_cmp_event( &code, PAPI_ENUM_EVENTS, coretemp_cid ); 00252 } 00253 00254 test_pass( __FILE__, NULL, 0 ); 00255 00256 return 0; 00257 } 00258