|
PAPI
5.1.0.2
|
00001 /* 00002 * Test case for appio 00003 * Author: Tushar Mohan 00004 * tusharmohan@gmail.com 00005 * 00006 * Description: This test case does a strided read of /etc/group 00007 * and writes the output to stdout. 00008 */ 00009 #include <papi.h> 00010 #include <errno.h> 00011 #include <stdio.h> 00012 #include <stdlib.h> 00013 #include <sys/types.h> 00014 #include <sys/stat.h> 00015 #include <fcntl.h> 00016 #include <unistd.h> 00017 00018 #include "papi_test.h" 00019 00020 #define NUM_EVENTS 7 00021 00022 int main(int argc, char** argv) { 00023 int Events[NUM_EVENTS]; 00024 const char* names[NUM_EVENTS] = {"READ_CALLS", "READ_BYTES", "READ_BLOCK_SIZE", "READ_USEC", "SEEK_CALLS", "SEEK_USEC", "SEEK_ABS_STRIDE_SIZE"}; 00025 long long values[NUM_EVENTS]; 00026 00027 char *infile = "/etc/group"; 00028 00029 /* Set TESTS_QUIET variable */ 00030 tests_quiet( argc, argv ); 00031 00032 int version = PAPI_library_init (PAPI_VER_CURRENT); 00033 if (version != PAPI_VER_CURRENT) { 00034 fprintf(stderr, "PAPI_library_init version mismatch\n"); 00035 exit(1); 00036 } 00037 00038 int fdin; 00039 if (!TESTS_QUIET) printf("This program will do a strided read %s and write it to stdout\n", infile); 00040 int retval; 00041 int e; 00042 for (e=0; e<NUM_EVENTS; e++) { 00043 retval = PAPI_event_name_to_code((char*)names[e], &Events[e]); 00044 if (retval != PAPI_OK) { 00045 fprintf(stderr, "Error getting code for %s\n", names[e]); 00046 exit(2); 00047 } 00048 } 00049 00050 /* Start counting events */ 00051 if (PAPI_start_counters(Events, NUM_EVENTS) != PAPI_OK) { 00052 fprintf(stderr, "Error in PAPI_start_counters\n"); 00053 exit(1); 00054 } 00055 00056 fdin=open(infile, O_RDONLY); 00057 if (fdin < 0) perror("Could not open file for reading: \n"); 00058 int bytes = 0; 00059 char buf[1024]; 00060 00061 00062 //if (PAPI_read_counters(values, NUM_EVENTS) != PAPI_OK) 00063 // handle_error(1); 00064 //printf("After reading the counters: %lld\n",values[0]); 00065 00066 while ((bytes = read(fdin, buf, 32)) > 0) { 00067 write(1, buf, bytes); 00068 lseek(fdin, 16, SEEK_CUR); 00069 } 00070 00071 /* Closing the descriptors before doing the PAPI_stop 00072 means, OPEN_FDS will be reported as zero, which is 00073 right, since at the time of PAPI_stop, the descriptors 00074 we opened have been closed */ 00075 close (fdin); 00076 00077 /* Stop counting events */ 00078 if (PAPI_stop_counters(values, NUM_EVENTS) != PAPI_OK) { 00079 fprintf(stderr, "Error in PAPI_stop_counters\n"); 00080 } 00081 00082 if (!TESTS_QUIET) { 00083 printf("----\n"); 00084 for (e=0; e<NUM_EVENTS; e++) 00085 printf("%s: %lld\n", names[e], values[e]); 00086 } 00087 test_pass( __FILE__, NULL, 0 ); 00088 return 0; 00089 }