net_values_by_code.c File Reference

Include dependency graph for net_values_by_code.c:

Go to the source code of this file.

Defines

#define IFNAME   "lo"
 Prints the value of every net event (by code).
#define PINGADDR   "127.0.0.1"

Functions

int main (int argc, char **argv)

Define Documentation

#define IFNAME   "lo"
Author:
Jose Pedro Oliveira

test case for the linux-net component

Definition at line 18 of file net_values_by_code.c.

#define PINGADDR   "127.0.0.1"

Definition at line 19 of file net_values_by_code.c.


Function Documentation

int main ( int  argc,
char **  argv 
)

Definition at line 21 of file net_values_by_code.c.

00022 {
00023     int retval,cid,numcmp;
00024     int EventSet = PAPI_NULL;
00025     long long value;
00026     int code;
00027     char event_name[PAPI_MAX_STR_LEN];
00028     int total_events=0;
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 net 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, "net") == NULL) {
00059             continue;
00060         }
00061 
00062         code = PAPI_NATIVE_MASK;
00063 
00064         r = PAPI_enum_cmp_event( &code, PAPI_ENUM_FIRST, cid );
00065         while ( r == PAPI_OK ) {
00066 
00067             retval = PAPI_event_code_to_name( code, event_name );
00068             if ( retval != PAPI_OK ) {
00069                 test_fail( __FILE__, __LINE__, "PAPI_event_code_to_name", retval );
00070             }
00071 
00072             if (!TESTS_QUIET) {
00073                 printf("%#x %-24s = ", code, event_name);
00074             }
00075 
00076             EventSet = PAPI_NULL;
00077 
00078             retval = PAPI_create_eventset( &EventSet );
00079             if (retval != PAPI_OK) {
00080                 test_fail(__FILE__, __LINE__, "PAPI_create_eventset()", retval);
00081             }
00082 
00083             retval = PAPI_add_event( EventSet, code );
00084             if (retval != PAPI_OK) {
00085                 test_fail(__FILE__, __LINE__, "PAPI_add_event()", retval);
00086             }
00087 
00088             retval = PAPI_start( EventSet );
00089             if (retval != PAPI_OK) {
00090                 test_fail(__FILE__, __LINE__, "PAPI_start()", retval);
00091             }
00092 
00093             if (strcmp(event_name, IFNAME ".rx.packets") == 0) {
00094                 /* generate some traffic
00095                  * the operation should take more than one second in order
00096                  * to guarantee that the network counters are updated */
00097                 retval = system("ping -c 4 " PINGADDR " > /dev/null");
00098                 if (retval < 0) {
00099                     test_fail(__FILE__, __LINE__, "Unable to start ping", retval);
00100                 }
00101             }
00102 
00103             retval = PAPI_stop( EventSet, &value );
00104             if (retval != PAPI_OK) {
00105                 test_fail(__FILE__, __LINE__, "PAPI_stop()", retval);
00106             }
00107 
00108             if (!TESTS_QUIET) printf("%lld\n", value);
00109 
00110             retval = PAPI_cleanup_eventset( EventSet );
00111             if (retval != PAPI_OK) {
00112                 test_fail(__FILE__, __LINE__, "PAPI_cleanup_eventset()", retval);
00113             }
00114 
00115             retval = PAPI_destroy_eventset( &EventSet );
00116             if (retval != PAPI_OK) {
00117                 test_fail(__FILE__, __LINE__, "PAPI_destroy_eventset()", retval);
00118             }
00119 
00120             total_events++;
00121 
00122             r = PAPI_enum_cmp_event( &code, PAPI_ENUM_EVENTS, cid );
00123         }
00124 
00125     }
00126 
00127     if (total_events==0) {
00128         test_skip(__FILE__,__LINE__,"No net events found", 0);
00129     }
00130 
00131     test_pass( __FILE__, NULL, 0 );
00132 
00133     return 0;
00134 }

Here is the call graph for this function:


Generated on 26 Jan 2016 for PAPI by  doxygen 1.6.1