|
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 stdout. 00008 * Statistics are printed at the end of the run., 00009 */ 00010 #include <papi.h> 00011 #include <errno.h> 00012 #include <stdio.h> 00013 #include <stdlib.h> 00014 #include <sys/types.h> 00015 #include <sys/stat.h> 00016 #include <fcntl.h> 00017 #include <unistd.h> 00018 00019 #include "papi_test.h" 00020 00021 #define NUM_EVENTS 12 00022 00023 int main(int argc, char** argv) { 00024 int Events[NUM_EVENTS]; 00025 const char* names[NUM_EVENTS] = {"OPEN_CALLS", "OPEN_FDS", "READ_CALLS", "READ_BYTES", "READ_USEC", "READ_ERR", "READ_INTERRUPTED", "READ_WOULD_BLOCK", "WRITE_CALLS","WRITE_BYTES","WRITE_USEC", "WRITE_WOULD_BLOCK"}; 00026 long long values[NUM_EVENTS]; 00027 00028 /* Set TESTS_QUIET variable */ 00029 tests_quiet( argc, argv ); 00030 00031 int version = PAPI_library_init (PAPI_VER_CURRENT); 00032 if (version != PAPI_VER_CURRENT) { 00033 fprintf(stderr, "PAPI_library_init version mismatch\n"); 00034 exit(1); 00035 } 00036 00037 if (!TESTS_QUIET) fprintf(stderr, "This program will read from stdin and echo it to stdout\n"); 00038 int retval; 00039 int e; 00040 for (e=0; e<NUM_EVENTS; e++) { 00041 retval = PAPI_event_name_to_code((char*)names[e], &Events[e]); 00042 if (retval != PAPI_OK) { 00043 fprintf(stderr, "Error getting code for %s\n", names[e]); 00044 exit(2); 00045 } 00046 } 00047 00048 /* Start counting events */ 00049 if (PAPI_start_counters(Events, NUM_EVENTS) != PAPI_OK) { 00050 fprintf(stderr, "Error in PAPI_start_counters\n"); 00051 exit(1); 00052 } 00053 00054 int bytes = 0; 00055 char buf[1024]; 00056 00057 00058 //if (PAPI_read_counters(values, NUM_EVENTS) != PAPI_OK) 00059 // handle_error(1); 00060 //printf("After reading the counters: %lld\n",values[0]); 00061 00062 while ((bytes = read(0, buf, 1024)) > 0) { 00063 write(1, buf, bytes); 00064 } 00065 00066 00067 /* Stop counting events */ 00068 if (PAPI_stop_counters(values, NUM_EVENTS) != PAPI_OK) { 00069 fprintf(stderr, "Error in PAPI_stop_counters\n"); 00070 } 00071 00072 if (!TESTS_QUIET) { 00073 printf("----\n"); 00074 for (e=0; e<NUM_EVENTS; e++) 00075 printf("%s: %lld\n", names[e], values[e]); 00076 } 00077 test_pass( __FILE__, NULL, 0 ); 00078 return 0; 00079 }