coretemp_pretty.c File Reference

Include dependency graph for coretemp_pretty.c:

Go to the source code of this file.

Defines

#define NUM_EVENTS   1
 Shows "pretty" coretemp output.

Functions

int main (int argc, char **argv)

Define Documentation

#define NUM_EVENTS   1
Author:
Vince Weaver

test case that displays "pretty" coretemp output

Definition at line 18 of file coretemp_pretty.c.


Function Documentation

int main ( int  argc,
char **  argv 
)

Definition at line 20 of file coretemp_pretty.c.

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->disabled) {
00059            if (!TESTS_QUIET) fprintf(stderr,"Coretemp component disabled: %s\n",
00060                cmpinfo->disabled_reason);
00061            test_skip(__FILE__, __LINE__,
00062                "Component disabled\n", 0);
00063        }
00064            if (cmpinfo->num_native_events==0) {
00065               test_skip(__FILE__,__LINE__,"No coretemp events found",0);
00066            }
00067        break;
00068     }
00069      }
00070 
00071 
00072 
00073 
00074      code = PAPI_NATIVE_MASK;
00075 
00076      r = PAPI_enum_cmp_event( &code, PAPI_ENUM_FIRST, coretemp_cid );
00077 
00078      while ( r == PAPI_OK ) {
00079 
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     retval = PAPI_get_event_info(code,&evinfo);
00088     if (retval != PAPI_OK) {
00089       test_fail( __FILE__, __LINE__,
00090              "Error getting event info\n",retval);
00091     }
00092 
00093        /****************************/
00094        /* Print Temperature Inputs */
00095        /****************************/
00096     if (strstr(event_name,"temp")) {
00097       
00098          /* Only print inputs */
00099       if (strstr(event_name,"_input")) {
00100 
00101          if (!TESTS_QUIET) printf("%s ",event_name);
00102 
00103              EventSet = PAPI_NULL;
00104 
00105          retval = PAPI_create_eventset( &EventSet );
00106          if (retval != PAPI_OK) {
00107             test_fail(__FILE__, __LINE__, 
00108                               "PAPI_create_eventset()",retval);
00109          }
00110 
00111              retval = PAPI_add_event( EventSet, code );
00112              if (retval != PAPI_OK) {
00113             test_fail(__FILE__, __LINE__, 
00114                                  "PAPI_add_event()",retval);
00115          }
00116 
00117              retval = PAPI_start( EventSet);
00118          if (retval != PAPI_OK) {
00119             test_fail(__FILE__, __LINE__, "PAPI_start()",retval);
00120          }
00121 
00122          retval = PAPI_stop( EventSet, values);
00123          if (retval != PAPI_OK) {
00124             test_fail(__FILE__, __LINE__, "PAPI_start()",retval);
00125          }
00126 
00127          temperature=(values[0]/1000.0);
00128 
00129              if (!TESTS_QUIET) printf("\tvalue: %.2lf %s\n",
00130                       temperature,
00131                       evinfo.long_descr
00132                       );
00133 
00134          retval = PAPI_cleanup_eventset( EventSet );
00135          if (retval != PAPI_OK) {
00136             test_fail(__FILE__, __LINE__, 
00137                               "PAPI_cleanup_eventset()",retval);
00138          }
00139 
00140          retval = PAPI_destroy_eventset( &EventSet );
00141              if (retval != PAPI_OK) {
00142             test_fail(__FILE__, __LINE__, 
00143                               "PAPI_destroy_eventset()",retval);
00144          }
00145       }
00146     }
00147 
00148        /****************************/
00149        /* Print Voltage Inputs */
00150        /****************************/
00151     if (strstr(event_name,".in")) {
00152       
00153          /* Only print inputs */
00154       if (strstr(event_name,"_input")) {
00155 
00156          if (!TESTS_QUIET) printf("%s ",event_name);
00157 
00158              EventSet = PAPI_NULL;
00159 
00160          retval = PAPI_create_eventset( &EventSet );
00161          if (retval != PAPI_OK) {
00162             test_fail(__FILE__, __LINE__, 
00163                               "PAPI_create_eventset()",retval);
00164          }
00165 
00166              retval = PAPI_add_event( EventSet, code );
00167              if (retval != PAPI_OK) {
00168             test_fail(__FILE__, __LINE__, 
00169                                  "PAPI_add_event()",retval);
00170          }
00171 
00172              retval = PAPI_start( EventSet);
00173          if (retval != PAPI_OK) {
00174             test_fail(__FILE__, __LINE__, "PAPI_start()",retval);
00175          }
00176 
00177          retval = PAPI_stop( EventSet, values);
00178          if (retval != PAPI_OK) {
00179             test_fail(__FILE__, __LINE__, "PAPI_start()",retval);
00180          }
00181 
00182          temperature=(values[0]/1000.0);
00183 
00184              if (!TESTS_QUIET) printf("\tvalue: %.2lf %s\n",
00185                       temperature,
00186                       evinfo.long_descr
00187                       );
00188 
00189          retval = PAPI_cleanup_eventset( EventSet );
00190          if (retval != PAPI_OK) {
00191             test_fail(__FILE__, __LINE__, 
00192                               "PAPI_cleanup_eventset()",retval);
00193          }
00194 
00195          retval = PAPI_destroy_eventset( &EventSet );
00196              if (retval != PAPI_OK) {
00197             test_fail(__FILE__, __LINE__, 
00198                               "PAPI_destroy_eventset()",retval);
00199          }
00200       }
00201     }
00202     /********************/
00203     /* Print Fan Inputs */
00204     /********************/
00205     else if (strstr(event_name,"fan")) {
00206 
00207          /* Only print inputs */
00208       if (strstr(event_name,"_input")) {
00209            
00210              if (!TESTS_QUIET) printf("%s ",event_name);
00211 
00212              EventSet = PAPI_NULL;
00213 
00214          retval = PAPI_create_eventset( &EventSet );
00215          if (retval != PAPI_OK) {
00216             test_fail(__FILE__, __LINE__, 
00217                               "PAPI_create_eventset()",retval);
00218          }
00219 
00220              retval = PAPI_add_event( EventSet, code );
00221              if (retval != PAPI_OK) {
00222             test_fail(__FILE__, __LINE__, 
00223                                  "PAPI_add_event()",retval);
00224          }
00225 
00226              retval = PAPI_start( EventSet);
00227          if (retval != PAPI_OK) {
00228             test_fail(__FILE__, __LINE__, "PAPI_start()",retval);
00229          }
00230 
00231          retval = PAPI_stop( EventSet, values);
00232          if (retval != PAPI_OK) {
00233             test_fail(__FILE__, __LINE__, "PAPI_start()",retval);
00234          }
00235 
00236              if (!TESTS_QUIET) printf("\tvalue: %lld %s\n",values[0],
00237                       evinfo.long_descr);
00238 
00239          retval = PAPI_cleanup_eventset( EventSet );
00240          if (retval != PAPI_OK) {
00241             test_fail(__FILE__, __LINE__, 
00242                               "PAPI_cleanup_eventset()",retval);
00243          }
00244 
00245          retval = PAPI_destroy_eventset( &EventSet );
00246              if (retval != PAPI_OK) {
00247             test_fail(__FILE__, __LINE__, 
00248                               "PAPI_destroy_eventset()",retval);
00249          }
00250       }
00251 
00252     }
00253     else {
00254       /* Skip unknown */
00255     }
00256           
00257         r = PAPI_enum_cmp_event( &code, PAPI_ENUM_EVENTS, coretemp_cid );
00258      }
00259         
00260      test_pass( __FILE__, NULL, 0 );
00261         
00262      return 0;
00263 }

Here is the call graph for this function:


Generated on 8 Sep 2016 for PAPI by  doxygen 1.6.1