PAPI  5.3.2.0
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
net_values_by_name.c File Reference
Include dependency graph for net_values_by_name.c:

Go to the source code of this file.

Macros

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

Functions

int main (int argc, char **argv)
 

Macro Definition 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.

27 {
28  int i, retval;
29  int EventSet = PAPI_NULL;
30  char *event_name[NUM_EVENTS] = {
31  IFNAME ":rx:bytes",
32  IFNAME ":rx:packets",
33  IFNAME ":tx:bytes",
34  IFNAME ":tx:packets",
35  };
36  int event_code[NUM_EVENTS] = { 0, 0, 0, 0};
37  long long event_value[NUM_EVENTS];
38  int total_events=0;
39 
40  /* Set TESTS_QUIET variable */
41  tests_quiet( argc, argv );
42 
43  /* PAPI Initialization */
45  if ( retval != PAPI_VER_CURRENT ) {
46  test_fail(__FILE__, __LINE__,"PAPI_library_init failed\n",retval);
47  }
48 
49  if (!TESTS_QUIET) {
50  printf("Net events by name\n");
51  }
52 
53  /* Map names to codes */
54  for ( i=0; i<NUM_EVENTS; i++ ) {
55  retval = PAPI_event_name_to_code( event_name[i], &event_code[i]);
56  if ( retval != PAPI_OK ) {
57  test_fail( __FILE__, __LINE__, "PAPI_event_name_to_code", retval );
58  }
59 
60  total_events++;
61  }
62 
63  /* Create and populate the EventSet */
64  EventSet = PAPI_NULL;
65 
66  retval = PAPI_create_eventset( &EventSet );
67  if (retval != PAPI_OK) {
68  test_fail(__FILE__, __LINE__, "PAPI_create_eventset()", retval);
69  }
70 
71  retval = PAPI_add_events( EventSet, event_code, NUM_EVENTS);
72  if (retval != PAPI_OK) {
73  test_fail(__FILE__, __LINE__, "PAPI_add_events()", retval);
74  }
75 
76  retval = PAPI_start( EventSet );
77  if (retval != PAPI_OK) {
78  test_fail(__FILE__, __LINE__, "PAPI_start()", retval);
79  }
80 
81  /* generate some traffic
82  * the operation should take more than one second in order
83  * to guarantee that the network counters are updated */
84  retval = system("ping -c 4 " PINGADDR " > /dev/null");
85  if (retval < 0) {
86  test_fail(__FILE__, __LINE__, "Unable to start ping", retval);
87  }
88 
89  retval = PAPI_stop( EventSet, event_value );
90  if (retval != PAPI_OK) {
91  test_fail(__FILE__, __LINE__, "PAPI_start()", retval);
92  }
93 
94  if (!TESTS_QUIET) {
95  for ( i=0; i<NUM_EVENTS; i++ ) {
96  printf("%#x %-24s = %lld\n",
97  event_code[i], event_name[i], event_value[i]);
98  }
99  }
100 
101  retval = PAPI_cleanup_eventset( EventSet );
102  if (retval != PAPI_OK) {
103  test_fail(__FILE__, __LINE__, "PAPI_cleanup_eventset()", retval);
104  }
105 
106  retval = PAPI_destroy_eventset( &EventSet );
107  if (retval != PAPI_OK) {
108  test_fail(__FILE__, __LINE__, "PAPI_destroy_eventset()", retval);
109  }
110 
111  test_pass( __FILE__, NULL, 0 );
112 
113  return 0;
114 }
char event_name[2][PAPI_MAX_STR_LEN]
Definition: data_range.c:23
#define IFNAME
Prints the values of several net events specified by names.
int PAPI_stop(int EventSet, long long *values)
Definition: papi.c:2232
#define PAPI_NULL
Definition: fpapi.h:13
return PAPI_OK
Definition: linux-nvml.c:458
tests_quiet(argc, argv)
#define PINGADDR
#define NUM_EVENTS
#define printf
Definition: papi_test.h:125
test_pass(__FILE__, NULL, 0)
int int argc
Definition: iozone.c:1609
int PAPI_add_events(int EventSet, int *Events, int number)
Definition: papi.c:5720
int TESTS_QUIET
Definition: test_utils.c:11
char ** argv
Definition: iozone.c:1610
test_fail(__FILE__, __LINE__,"PAPI_library_init", retval)
int PAPI_library_init(int version)
Definition: papi.c:495
int i
Definition: fileop.c:140
#define PAPI_VER_CURRENT
Definition: fpapi.h:14
int PAPI_cleanup_eventset(int EventSet)
Definition: papi.c:2805
int PAPI_create_eventset(int *EventSet)
Definition: papi.c:1406
int PAPI_event_name_to_code(char *in, int *out)
Definition: papi.c:1008
int EventSet
int PAPI_destroy_eventset(int *EventSet)
Definition: papi.c:1944
int PAPI_start(int EventSet)
Definition: papi.c:2026
int system()
ssize_t retval
Definition: libasync.c:338

Here is the call graph for this function: