|
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 MAX_EVENTS 32 00019 00020 int main (int argc, char **argv) 00021 { 00022 int retval,cid,numcmp; 00023 int EventSet = PAPI_NULL; 00024 long long value; 00025 int code; 00026 char event_names[MAX_EVENTS][PAPI_MAX_STR_LEN]; 00027 int event_codes[MAX_EVENTS]; 00028 long long event_values[MAX_EVENTS]; 00029 int total_events=0; /* events added so far */ 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 appio 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",-1); 00052 } 00053 00054 if (!TESTS_QUIET) { 00055 printf("Component %d - %d events - %s\n", cid, 00056 cmpinfo->num_native_events, cmpinfo->name); 00057 } 00058 00059 if ( strstr(cmpinfo->name, "appio") == NULL) { 00060 continue; 00061 } 00062 00063 code = PAPI_NATIVE_MASK; 00064 00065 r = PAPI_enum_cmp_event( &code, PAPI_ENUM_FIRST, cid ); 00066 /* Create and populate the EventSet */ 00067 EventSet = PAPI_NULL; 00068 00069 retval = PAPI_create_eventset( &EventSet ); 00070 if (retval != PAPI_OK) { 00071 test_fail(__FILE__, __LINE__, "PAPI_create_eventset()", retval); 00072 } 00073 00074 while ( r == PAPI_OK ) { 00075 00076 retval = PAPI_event_code_to_name( code, event_names[total_events] ); 00077 if ( retval != PAPI_OK ) { 00078 test_fail( __FILE__, __LINE__, "PAPI_event_code_to_name", retval ); 00079 } 00080 00081 if (!TESTS_QUIET) { 00082 printf("Added event %s (code=0x%x)\n", event_names[total_events], code); 00083 } 00084 event_codes[total_events++] = code; 00085 r = PAPI_enum_cmp_event( &code, PAPI_ENUM_EVENTS, cid ); 00086 } 00087 00088 } 00089 00090 int fdin,fdout; 00091 const char* infile = "/etc/group"; 00092 printf("This program will read %s and write it to /dev/null\n", infile); 00093 int bytes = 0; 00094 char buf[1024]; 00095 00096 retval = PAPI_add_events( EventSet, event_codes, total_events); 00097 if (retval != PAPI_OK) { 00098 test_fail(__FILE__, __LINE__, "PAPI_add_events()", retval); 00099 } 00100 00101 retval = PAPI_start( EventSet ); 00102 if (retval != PAPI_OK) { 00103 test_fail(__FILE__, __LINE__, "PAPI_start()", retval); 00104 } 00105 00106 fdin=open(infile, O_RDONLY); 00107 if (fdin < 0) perror("Could not open file for reading: \n"); 00108 fdout = open("/dev/null", O_WRONLY); 00109 if (fdout < 0) perror("Could not open /dev/null for writing: \n"); 00110 00111 while ((bytes = read(fdin, buf, 1024)) > 0) { 00112 write(fdout, buf, bytes); 00113 } 00114 00115 retval = PAPI_stop( EventSet, event_values ); 00116 if (retval != PAPI_OK) { 00117 test_fail(__FILE__, __LINE__, "PAPI_stop()", retval); 00118 } 00119 close(fdin); 00120 close(fdout); 00121 00122 int i; 00123 if (!TESTS_QUIET) { 00124 for ( i=0; i<total_events; i++ ) { 00125 printf("0x%x %-24s = %lld\n", 00126 event_codes[i], event_names[i], event_values[i]); 00127 } 00128 } 00129 00130 retval = PAPI_cleanup_eventset( EventSet ); 00131 if (retval != PAPI_OK) { 00132 test_fail(__FILE__, __LINE__, "PAPI_cleanup_eventset()", retval); 00133 } 00134 00135 retval = PAPI_destroy_eventset( &EventSet ); 00136 if (retval != PAPI_OK) { 00137 test_fail(__FILE__, __LINE__, "PAPI_destroy_eventset()", retval); 00138 } 00139 00140 if (total_events==0) { 00141 test_skip(__FILE__,__LINE__,"No appio events found", 0); 00142 } 00143 00144 test_pass( __FILE__, NULL, 0 ); 00145 00146 retval = PAPI_cleanup_eventset( EventSet ); 00147 if (retval != PAPI_OK) { 00148 test_fail(__FILE__, __LINE__, "PAPI_cleanup_eventset()", retval); 00149 } 00150 00151 retval = PAPI_destroy_eventset( &EventSet ); 00152 if (retval != PAPI_OK) { 00153 test_fail(__FILE__, __LINE__, "PAPI_destroy_eventset()", retval); 00154 } 00155 return 0; 00156 } 00157 00158 // vim:set ai ts=4 sw=4 sts=4 et: