|
PAPI
5.0.1.0
|
00001 /* 00002 * Test case for appio 00003 * Author: Tushar Mohan 00004 * tusharmohan@gmail.com 00005 * 00006 * Description: This test case reads from standard linux /etc/group 00007 * and writes the output to /dev/null 00008 * Fread and fwrite are used for I/O. 00009 * Statistics are printed at the end of the run., 00010 */ 00011 #include <papi.h> 00012 #include <errno.h> 00013 #include <stdio.h> 00014 #include <stdlib.h> 00015 #include <sys/types.h> 00016 #include <sys/stat.h> 00017 #include <fcntl.h> 00018 #include <unistd.h> 00019 #include "papi_test.h" 00020 00021 00022 #define NUM_EVENTS 8 00023 00024 int main(int argc, char** argv) { 00025 int Events[NUM_EVENTS]; 00026 const char* names[NUM_EVENTS] = {"READ_CALLS", "READ_BYTES","READ_USEC","READ_ERR", "READ_EOF", "WRITE_CALLS","WRITE_BYTES","WRITE_USEC"}; 00027 long long values[NUM_EVENTS]; 00028 00029 char *infile = "/etc/group"; 00030 00031 /* Set TESTS_QUIET variable */ 00032 tests_quiet( argc, argv ); 00033 00034 int version = PAPI_library_init (PAPI_VER_CURRENT); 00035 if (version != PAPI_VER_CURRENT) { 00036 fprintf(stderr, "PAPI_library_init version mismatch\n"); 00037 exit(1); 00038 } 00039 if (!TESTS_QUIET) printf("This program will read %s and write it to /dev/null\n", infile); 00040 FILE* fdin=fopen(infile, "r"); 00041 if (fdin == NULL) perror("Could not open file for reading: \n"); 00042 FILE* fout=fopen("/dev/null", "w"); 00043 if (fout == NULL) perror("Could not open file for writing: \n"); 00044 int bytes = 0; 00045 char buf[1024]; 00046 00047 int retval; 00048 int e; 00049 for (e=0; e<NUM_EVENTS; e++) { 00050 retval = PAPI_event_name_to_code((char*)names[e], &Events[e]); 00051 if (retval != PAPI_OK) { 00052 fprintf(stderr, "Error getting code for %s\n", names[e]); 00053 exit(2); 00054 } 00055 } 00056 00057 /* Start counting events */ 00058 if (PAPI_start_counters(Events, NUM_EVENTS) != PAPI_OK) { 00059 fprintf(stderr, "Error in PAPI_start_counters\n"); 00060 exit(1); 00061 } 00062 00063 //if (PAPI_read_counters(values, NUM_EVENTS) != PAPI_OK) 00064 // handle_error(1); 00065 //printf("After reading the counters: %lld\n",values[0]); 00066 00067 while ((bytes = fread(buf, 1, 1024, fdin)) > 0) { 00068 fwrite(buf, 1, bytes, fout); 00069 } 00070 00071 fclose(fdin); 00072 fclose(fout); 00073 00074 /* Stop counting events */ 00075 if (PAPI_stop_counters(values, NUM_EVENTS) != PAPI_OK) { 00076 fprintf(stderr, "Error in PAPI_stop_counters\n"); 00077 } 00078 00079 if (!TESTS_QUIET) { 00080 printf("----\n"); 00081 for (e=0; e<NUM_EVENTS; e++) 00082 printf("%s: %lld\n", names[e], values[e]); 00083 } 00084 test_pass( __FILE__, NULL, 0 ); 00085 return 0; 00086 }