|
PAPI
5.0.1.0
|
00001 /***************************************************************************** 00002 * PAPI_perror converts PAPI error codes to strings,it fills the string * 00003 * destination with the error message corresponding to the error code. * 00004 * The function copies length worth of the error description string * 00005 * corresponding to code into destination. The resulting string is always * 00006 * null terminated. If length is 0, then the string is printed on stderr. * 00007 * PAPI_strerror does similar but it just returns the corresponding * 00008 * error string from the code. * 00009 *****************************************************************************/ 00010 00011 #include <stdio.h> 00012 #include <stdlib.h> 00013 #include "papi.h" /* This needs to be included every time you use PAPI */ 00014 00015 00016 int main() 00017 { 00018 00019 int retval; 00020 int EventSet = PAPI_NULL; 00021 char error_str[PAPI_MAX_STR_LEN]; 00022 00023 /**************************************************************************** 00024 * This part initializes the library and compares the version number of the * 00025 * header file, to the version of the library, if these don't match then it * 00026 * is likely that PAPI won't work correctly.If there is an error, retval * 00027 * keeps track of the version number. * 00028 ****************************************************************************/ 00029 00030 if((retval = PAPI_library_init(PAPI_VER_CURRENT)) != PAPI_VER_CURRENT ) 00031 { 00032 exit(1); 00033 } 00034 00035 if ((retval = PAPI_create_eventset(&EventSet)) != PAPI_OK) 00036 { 00037 fprintf(stderr, "PAPI error %d: %s\n",retval,PAPI_strerror(retval)); 00038 exit(1); 00039 } 00040 00041 /* Add Total Instructions Executed to our EventSet */ 00042 00043 if ((retval = PAPI_add_event(EventSet, PAPI_TOT_INS)) != PAPI_OK) 00044 { 00045 PAPI_perror( "PAPI_add_event" ); 00046 exit(1); 00047 } 00048 00049 /* Start counting */ 00050 00051 if ((retval = PAPI_start(EventSet)) != PAPI_OK) 00052 { 00053 PAPI_perror( "PAPI_start" ); 00054 exit(1); 00055 } 00056 00057 /* We are trying to start the counter which has already been started, 00058 and this will give an error which will be passed to PAPI_perror via 00059 retval and the function will then display the error string on the 00060 screen. 00061 */ 00062 00063 if ((retval = PAPI_start(EventSet)) != PAPI_OK) 00064 { 00065 PAPI_perror( "PAPI_start" ); 00066 } 00067 00068 /* The function PAPI_strerror returns the corresponding error string 00069 from the error code */ 00070 if ((retval = PAPI_start(EventSet)) != PAPI_OK) 00071 { 00072 printf("%s\n",PAPI_strerror(retval)); 00073 } 00074 00075 /* finish using PAPI and free all related resources 00076 (this is optional, you don't have to use it 00077 */ 00078 PAPI_shutdown (); 00079 00080 exit(0); 00081 }