appio_test_read_write.c File Reference

Include dependency graph for appio_test_read_write.c:

Go to the source code of this file.

Defines

#define NUM_EVENTS   12

Functions

int main (int argc, char **argv)

Define Documentation

#define NUM_EVENTS   12

Definition at line 21 of file appio_test_read_write.c.


Function Documentation

int main ( int  argc,
char **  argv 
)

Definition at line 23 of file appio_test_read_write.c.

00023                                 {
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   char *infile = "/etc/group";
00029 
00030   /* Set TESTS_QUIET variable */
00031   tests_quiet( argc, argv );
00032 
00033   int version = PAPI_library_init (PAPI_VER_CURRENT);
00034   if (version != PAPI_VER_CURRENT) {
00035     fprintf(stderr, "PAPI_library_init version mismatch\n");
00036     exit(1);
00037   }
00038 
00039   int fdin;
00040   if (!TESTS_QUIET) printf("This program will read %s and write it to /dev/null\n", infile);
00041   int retval;
00042   int e;
00043   for (e=0; e<NUM_EVENTS; e++) {
00044     retval = PAPI_event_name_to_code((char*)names[e], &Events[e]);
00045     if (retval != PAPI_OK) {
00046       fprintf(stderr, "Error getting code for %s\n", names[e]);
00047       exit(2);
00048     } 
00049   }
00050 
00051   /* Start counting events */
00052   if (PAPI_start_counters(Events, NUM_EVENTS) != PAPI_OK) {
00053     fprintf(stderr, "Error in PAPI_start_counters\n");
00054     exit(1);
00055   }
00056 
00057   fdin=open(infile, O_RDONLY);
00058   if (fdin < 0) perror("Could not open file for reading: \n");
00059   int fdout;
00060   fdout=open("/dev/null", O_WRONLY);
00061   if (fdout < 0) perror("Could not open file for writing: \n");
00062   int bytes = 0;
00063   char buf[1024];
00064 
00065  
00066 //if (PAPI_read_counters(values, NUM_EVENTS) != PAPI_OK)
00067 //   handle_error(1);
00068 //printf("After reading the counters: %lld\n",values[0]);
00069 
00070   while ((bytes = read(fdin, buf, 1024)) > 0) {
00071     write(fdout, buf, bytes);
00072   }
00073 
00074   /* Closing the descriptors before doing the PAPI_stop
00075      means, OPEN_FDS will be reported as zero, which is
00076      right, since at the time of PAPI_stop, the descriptors
00077      we opened have been closed */
00078   close (fdin);
00079   close (fdout);
00080 
00081   /* Stop counting events */
00082   if (PAPI_stop_counters(values, NUM_EVENTS) != PAPI_OK) {
00083     fprintf(stderr, "Error in PAPI_stop_counters\n");
00084   }
00085  
00086   if (!TESTS_QUIET) { 
00087     printf("----\n");
00088     for (e=0; e<NUM_EVENTS; e++)  
00089       printf("%s: %lld\n", names[e], values[e]);
00090   }
00091   test_pass( __FILE__, NULL, 0 );
00092   return 0;
00093 }

Here is the call graph for this function:


Generated on 26 Jan 2016 for PAPI by  doxygen 1.6.1