net_values_by_name.c File Reference

Include dependency graph for net_values_by_name.c:

Go to the source code of this file.

Defines

#define IFNAME   "lo"
 Prints the values of several net events specified by names.
#define PINGADDR   "127.0.0.1"
#define NUM_EVENTS   4

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 21 of file net_values_by_name.c.

#define NUM_EVENTS   4

Definition at line 24 of file net_values_by_name.c.

#define PINGADDR   "127.0.0.1"

Definition at line 22 of file net_values_by_name.c.


Function Documentation

int main ( int  argc,
char **  argv 
)

Definition at line 26 of file net_values_by_name.c.

00027 {
00028     int i, retval;
00029     int EventSet = PAPI_NULL;
00030     char *event_name[NUM_EVENTS] = {
00031         IFNAME ":rx:bytes",
00032         IFNAME ":rx:packets",
00033         IFNAME ":tx:bytes",
00034         IFNAME ":tx:packets",
00035     };
00036     int event_code[NUM_EVENTS] = { 0, 0, 0, 0};
00037     long long event_value[NUM_EVENTS];
00038     int total_events=0;
00039 
00040     /* Set TESTS_QUIET variable */
00041     tests_quiet( argc, argv );
00042 
00043     /* PAPI Initialization */
00044     retval = PAPI_library_init( PAPI_VER_CURRENT );
00045     if ( retval != PAPI_VER_CURRENT ) {
00046         test_fail(__FILE__, __LINE__,"PAPI_library_init failed\n",retval);
00047     }
00048 
00049     if (!TESTS_QUIET) {
00050         printf("Net events by name\n");
00051     }
00052 
00053     /* Map names to codes */
00054     for ( i=0; i<NUM_EVENTS; i++ ) {
00055         retval = PAPI_event_name_to_code( event_name[i], &event_code[i]);
00056         if ( retval != PAPI_OK ) {
00057             test_fail( __FILE__, __LINE__, "PAPI_event_name_to_code", retval );
00058         }
00059 
00060         total_events++;
00061     }
00062 
00063     /* Create and populate the EventSet */
00064     EventSet = PAPI_NULL;
00065 
00066     retval = PAPI_create_eventset( &EventSet );
00067     if (retval != PAPI_OK) {
00068         test_fail(__FILE__, __LINE__, "PAPI_create_eventset()", retval);
00069     }
00070 
00071     retval = PAPI_add_events( EventSet, event_code, NUM_EVENTS);
00072     if (retval != PAPI_OK) {
00073         test_fail(__FILE__, __LINE__, "PAPI_add_events()", retval);
00074     }
00075 
00076     retval = PAPI_start( EventSet );
00077     if (retval != PAPI_OK) {
00078         test_fail(__FILE__, __LINE__, "PAPI_start()", retval);
00079     }
00080 
00081     /* generate some traffic
00082      * the operation should take more than one second in order
00083      * to guarantee that the network counters are updated */
00084     retval = system("ping -c 4 " PINGADDR " > /dev/null");
00085     if (retval < 0) {
00086         test_fail(__FILE__, __LINE__, "Unable to start ping", retval);
00087     }
00088 
00089     retval = PAPI_stop( EventSet, event_value );
00090     if (retval != PAPI_OK) {
00091         test_fail(__FILE__, __LINE__, "PAPI_start()", retval);
00092     }
00093 
00094     if (!TESTS_QUIET) {
00095         for ( i=0; i<NUM_EVENTS; i++ ) {
00096             printf("%#x %-24s = %lld\n",
00097                 event_code[i], event_name[i], event_value[i]);
00098         }
00099     }
00100 
00101     retval = PAPI_cleanup_eventset( EventSet );
00102     if (retval != PAPI_OK) {
00103         test_fail(__FILE__, __LINE__, "PAPI_cleanup_eventset()", retval);
00104     }
00105 
00106     retval = PAPI_destroy_eventset( &EventSet );
00107     if (retval != PAPI_OK) {
00108         test_fail(__FILE__, __LINE__, "PAPI_destroy_eventset()", retval);
00109     }
00110 
00111     test_pass( __FILE__, NULL, 0 );
00112 
00113     return 0;
00114 }

Here is the call graph for this function:


Generated on 17 Nov 2016 for PAPI by  doxygen 1.6.1