appio_values_by_code.c File Reference

Include dependency graph for appio_values_by_code.c:

Go to the source code of this file.

Defines

#define MAX_EVENTS   48
 Prints the value of every appio event (by code).

Functions

int main (int argc, char **argv)

Define Documentation

#define MAX_EVENTS   48
Author:
Tushar Mohan (adapted from code in linux-net) test case for the appio component

Definition at line 18 of file appio_values_by_code.c.


Function Documentation

int main ( int  argc,
char **  argv 
)

Definition at line 20 of file appio_values_by_code.c.

00021 {
00022     int retval,cid,numcmp;
00023     int EventSet = PAPI_NULL;
00024     int code;
00025     char event_names[MAX_EVENTS][PAPI_MAX_STR_LEN];
00026     int event_codes[MAX_EVENTS];
00027     long long event_values[MAX_EVENTS];
00028     int total_events=0; /* events added so far */
00029     int r;
00030     const PAPI_component_info_t *cmpinfo = NULL;
00031 
00032     /* Set TESTS_QUIET variable */
00033     tests_quiet( argc, argv );
00034 
00035     /* PAPI Initialization */
00036     retval = PAPI_library_init( PAPI_VER_CURRENT );
00037     if ( retval != PAPI_VER_CURRENT ) {
00038         test_fail(__FILE__, __LINE__,"PAPI_library_init failed\n",retval);
00039     }
00040 
00041     if (!TESTS_QUIET) {
00042         printf("Trying all appio events\n");
00043     }
00044 
00045     numcmp = PAPI_num_components();
00046 
00047     for(cid=0; cid<numcmp; cid++) {
00048 
00049         if ( (cmpinfo = PAPI_get_component_info(cid)) == NULL) {
00050             test_fail(__FILE__, __LINE__,"PAPI_get_component_info failed\n",-1);
00051         }
00052 
00053         if (!TESTS_QUIET) {
00054             printf("Component %d - %d events - %s\n", cid,
00055                 cmpinfo->num_native_events, cmpinfo->name);
00056         }
00057 
00058         if ( strstr(cmpinfo->name, "appio") == NULL) {
00059             continue;
00060         }
00061 
00062         code = PAPI_NATIVE_MASK;
00063 
00064         r = PAPI_enum_cmp_event( &code, PAPI_ENUM_FIRST, cid );
00065         /* Create and populate the EventSet */
00066         EventSet = PAPI_NULL;
00067 
00068         retval = PAPI_create_eventset( &EventSet );
00069          if (retval != PAPI_OK) {
00070              test_fail(__FILE__, __LINE__, "PAPI_create_eventset()", retval);
00071          }
00072 
00073         while ( r == PAPI_OK ) {
00074 
00075             retval = PAPI_event_code_to_name( code, event_names[total_events] );
00076             if ( retval != PAPI_OK ) {
00077                 test_fail( __FILE__, __LINE__, "PAPI_event_code_to_name", retval );
00078             }
00079             
00080             if (!TESTS_QUIET) {
00081               printf("Added event %s (code=%#x)\n", event_names[total_events], code);
00082             }
00083             event_codes[total_events++] = code;
00084             r = PAPI_enum_cmp_event( &code, PAPI_ENUM_EVENTS, cid );
00085         }
00086 
00087     }
00088 
00089     int fdin,fdout;
00090     const char* infile = "/etc/group";
00091     printf("This program will read %s and write it to /dev/null\n", infile);
00092     int bytes = 0;
00093     char buf[1024];
00094 
00095     retval = PAPI_add_events( EventSet, event_codes, total_events);
00096     if (retval != PAPI_OK) {
00097         test_fail(__FILE__, __LINE__, "PAPI_add_events()", retval);
00098     }
00099 
00100     retval = PAPI_start( EventSet );
00101     if (retval != PAPI_OK) {
00102         test_fail(__FILE__, __LINE__, "PAPI_start()", retval);
00103     }
00104 
00105     fdin=open(infile, O_RDONLY);
00106     if (fdin < 0) perror("Could not open file for reading: \n");
00107     fdout = open("/dev/null", O_WRONLY);
00108     if (fdout < 0) perror("Could not open /dev/null for writing: \n");
00109 
00110     while ((bytes = read(fdin, buf, 1024)) > 0) {
00111       write(fdout, buf, bytes);
00112     }
00113 
00114     retval = PAPI_stop( EventSet, event_values );
00115     if (retval != PAPI_OK) {
00116         test_fail(__FILE__, __LINE__, "PAPI_stop()", retval);
00117     }
00118     close(fdin);
00119     close(fdout);
00120 
00121     int i;
00122     if (!TESTS_QUIET) {
00123         for ( i=0; i<total_events; i++ ) {
00124             printf("%#x %-24s = %lld\n",
00125                 event_codes[i], event_names[i], event_values[i]);
00126         }
00127     }
00128 
00129     retval = PAPI_cleanup_eventset( EventSet );
00130     if (retval != PAPI_OK) {
00131         test_fail(__FILE__, __LINE__, "PAPI_cleanup_eventset()", retval);
00132     }
00133 
00134     retval = PAPI_destroy_eventset( &EventSet );
00135     if (retval != PAPI_OK) {
00136         test_fail(__FILE__, __LINE__, "PAPI_destroy_eventset()", retval);
00137     }
00138 
00139     if (total_events==0) {
00140         test_skip(__FILE__,__LINE__,"No appio events found", 0);
00141     }
00142 
00143     test_pass( __FILE__, NULL, 0 );
00144 
00145     retval = PAPI_cleanup_eventset( EventSet );
00146     if (retval != PAPI_OK) {
00147         test_fail(__FILE__, __LINE__, "PAPI_cleanup_eventset()", retval);
00148     }
00149 
00150     retval = PAPI_destroy_eventset( &EventSet );
00151     if (retval != PAPI_OK) {
00152         test_fail(__FILE__, __LINE__, "PAPI_destroy_eventset()", retval);
00153     }
00154     return 0;
00155 }

Here is the call graph for this function:


Generated on 26 Jan 2016 for PAPI by  doxygen 1.6.1