appio_values_by_name.c File Reference

Include dependency graph for appio_values_by_name.c:

Go to the source code of this file.

Defines

#define NUM_EVENTS   11
 Prints the values of several (but not all) appio events specified by names.

Functions

int main (int argc, char **argv)

Define Documentation

#define NUM_EVENTS   11
Author:
Tushar Mohan

test case for the appio component (adapted from test in linux-net component)

Definition at line 25 of file appio_values_by_name.c.


Function Documentation

int main ( int  argc,
char **  argv 
)

Definition at line 27 of file appio_values_by_name.c.

00028 {
00029     int i, retval;
00030     int EventSet = PAPI_NULL;
00031     char *event_name[NUM_EVENTS] = {
00032         "READ_BYTES",
00033         "READ_CALLS",
00034         "READ_USEC",
00035         "READ_EOF",
00036         "READ_SHORT",
00037         "READ_ERR",
00038         "WRITE_BYTES",
00039         "WRITE_CALLS",
00040         "WRITE_USEC",
00041         "WRITE_ERR",
00042         "WRITE_SHORT"
00043     };
00044     int event_code[NUM_EVENTS] = { 0, 0, 0, 0, 0, 0, 0, 0, 0};
00045     long long event_value[NUM_EVENTS];
00046     int total_events=0;
00047 
00048     /* Set TESTS_QUIET variable */
00049     tests_quiet( argc, argv );
00050 
00051     /* PAPI Initialization */
00052     retval = PAPI_library_init( PAPI_VER_CURRENT );
00053     if ( retval != PAPI_VER_CURRENT ) {
00054         test_fail(__FILE__, __LINE__,"PAPI_library_init failed\n",retval);
00055     }
00056 
00057     if (!TESTS_QUIET) {
00058         printf("Appio events by name\n");
00059     }
00060 
00061     /* Map names to codes */
00062     for ( i=0; i<NUM_EVENTS; i++ ) {
00063         retval = PAPI_event_name_to_code( event_name[i], &event_code[i]);
00064         if ( retval != PAPI_OK ) {
00065             test_fail( __FILE__, __LINE__, "PAPI_event_name_to_code", retval );
00066         }
00067 
00068         total_events++;
00069     }
00070 
00071     int fdin,fdout;
00072     const char* infile = "/etc/group";
00073     if (!TESTS_QUIET) printf("This program will read %s and write it to /dev/null\n", infile);
00074     int bytes = 0;
00075     char buf[1024];
00076 
00077     /* Create and populate the EventSet */
00078     EventSet = PAPI_NULL;
00079 
00080     retval = PAPI_create_eventset( &EventSet );
00081     if (retval != PAPI_OK) {
00082         test_fail(__FILE__, __LINE__, "PAPI_create_eventset()", retval);
00083     }
00084 
00085     retval = PAPI_add_events( EventSet, event_code, NUM_EVENTS);
00086     if (retval != PAPI_OK) {
00087         test_fail(__FILE__, __LINE__, "PAPI_add_events()", retval);
00088     }
00089 
00090     retval = PAPI_start( EventSet );
00091     if (retval != PAPI_OK) {
00092         test_fail(__FILE__, __LINE__, "PAPI_start()", retval);
00093     }
00094 
00095     fdin=open(infile, O_RDONLY);
00096     if (fdin < 0) perror("Could not open file for reading: \n");
00097     fdout=open("/dev/null", O_WRONLY);
00098     if (fdout < 0) perror("Could not open /dev/null for writing: \n");
00099 
00100     while ((bytes = read(fdin, buf, 1024)) > 0) {
00101       write(fdout, buf, bytes);
00102     }
00103     close(fdin);
00104     close(fdout);
00105 
00106     retval = PAPI_stop( EventSet, event_value );
00107     if (retval != PAPI_OK) {
00108         test_fail(__FILE__, __LINE__, "PAPI_start()", retval);
00109     }
00110 
00111     if (!TESTS_QUIET) {
00112         for ( i=0; i<NUM_EVENTS; i++ ) {
00113             printf("%#x %-24s = %lld\n",
00114                 event_code[i], event_name[i], event_value[i]);
00115         }
00116     }
00117 
00118     retval = PAPI_cleanup_eventset( EventSet );
00119     if (retval != PAPI_OK) {
00120         test_fail(__FILE__, __LINE__, "PAPI_cleanup_eventset()", retval);
00121     }
00122 
00123     retval = PAPI_destroy_eventset( &EventSet );
00124     if (retval != PAPI_OK) {
00125         test_fail(__FILE__, __LINE__, "PAPI_destroy_eventset()", retval);
00126     }
00127 
00128     if (total_events==0) {
00129         test_skip(__FILE__,__LINE__,"No appio events found", 0);
00130     }
00131 
00132     test_pass( __FILE__, NULL, 0 );
00133 
00134     return 0;
00135 }

Here is the call graph for this function:


Generated on 26 Jan 2016 for PAPI by  doxygen 1.6.1