|
PAPI
5.3.0.0
|
00001 /****************************/ 00002 /* THIS IS OPEN SOURCE CODE */ 00003 /****************************/ 00004 00015 #include <stdio.h> 00016 #include <stdlib.h> 00017 #include "papi_test.h" 00018 00019 #define NUM_EVENTS 1 00020 00021 int main (int argc, char **argv) 00022 { 00023 00024 int retval,cid,numcmp,coretemp_cid=-1; 00025 int EventSet = PAPI_NULL; 00026 long long values[NUM_EVENTS]; 00027 int code; 00028 char event_name[PAPI_MAX_STR_LEN]; 00029 int total_events=0; 00030 int r; 00031 const PAPI_component_info_t *cmpinfo = NULL; 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__, 00052 "PAPI_get_component_info failed\n", 0); 00053 } 00054 00055 if (strstr(cmpinfo->name,"coretemp")) { 00056 coretemp_cid=cid; 00057 if (!TESTS_QUIET) { 00058 printf("Found coretemp component at cid %d\n", coretemp_cid); 00059 } 00060 00061 if (cmpinfo->disabled) { 00062 if (!TESTS_QUIET) fprintf(stderr,"Coretemp component disabled: %s\n", 00063 cmpinfo->disabled_reason); 00064 test_skip(__FILE__, __LINE__, 00065 "Component disabled\n", 0); 00066 } 00067 } 00068 } 00069 00070 if (coretemp_cid==-1) { 00071 test_skip(__FILE__,__LINE__,"No coretemp component found",0); 00072 } 00073 00074 00075 code = PAPI_NATIVE_MASK; 00076 00077 r = PAPI_enum_cmp_event( &code, PAPI_ENUM_FIRST, coretemp_cid ); 00078 00079 while ( r == PAPI_OK ) { 00080 retval = PAPI_event_code_to_name( code, event_name ); 00081 if ( retval != PAPI_OK ) { 00082 printf("Error translating %#x\n",code); 00083 test_fail( __FILE__, __LINE__, 00084 "PAPI_event_code_to_name", retval ); 00085 } 00086 00087 if (!TESTS_QUIET) printf("%s ",event_name); 00088 00089 EventSet = PAPI_NULL; 00090 00091 retval = PAPI_create_eventset( &EventSet ); 00092 if (retval != PAPI_OK) { 00093 test_fail(__FILE__, __LINE__, 00094 "PAPI_create_eventset()",retval); 00095 } 00096 00097 retval = PAPI_add_event( EventSet, code ); 00098 if (retval != PAPI_OK) { 00099 test_fail(__FILE__, __LINE__, 00100 "PAPI_add_event()",retval); 00101 } 00102 00103 retval = PAPI_start( EventSet); 00104 if (retval != PAPI_OK) { 00105 test_fail(__FILE__, __LINE__, "PAPI_start()",retval); 00106 } 00107 00108 retval = PAPI_stop( EventSet, values); 00109 if (retval != PAPI_OK) { 00110 test_fail(__FILE__, __LINE__, "PAPI_start()",retval); 00111 } 00112 00113 if (!TESTS_QUIET) printf(" value: %lld\n",values[0]); 00114 00115 retval = PAPI_cleanup_eventset( EventSet ); 00116 if (retval != PAPI_OK) { 00117 test_fail(__FILE__, __LINE__, 00118 "PAPI_cleanup_eventset()",retval); 00119 } 00120 00121 retval = PAPI_destroy_eventset( &EventSet ); 00122 if (retval != PAPI_OK) { 00123 test_fail(__FILE__, __LINE__, 00124 "PAPI_destroy_eventset()",retval); 00125 } 00126 00127 total_events++; 00128 r = PAPI_enum_cmp_event( &code, PAPI_ENUM_EVENTS, coretemp_cid ); 00129 } 00130 00131 if (total_events==0) { 00132 test_skip(__FILE__,__LINE__,"No coretemp events found",0); 00133 } 00134 00135 test_pass( __FILE__, NULL, 0 ); 00136 00137 return 0; 00138 } 00139