PAPI  5.4.0.0
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
net_values_by_name.c
Go to the documentation of this file.
1 /****************************/
2 /* THIS IS OPEN SOURCE CODE */
3 /****************************/
4 
14 #include <stdio.h>
15 #include <stdlib.h>
16 #include "papi_test.h"
17 
18 /*
19 #define IFNAME "eth0"
20 */
21 #define IFNAME "lo"
22 #define PINGADDR "127.0.0.1"
23 
24 #define NUM_EVENTS 4
25 
26 int main (int argc, char **argv)
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 }
115 
116 // vim:set ai ts=4 sw=4 sts=4 et:
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:2258
#define PAPI_NULL
Definition: papi.h:290
int EventSet
Definition: data_range.c:25
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:5769
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:497
int i
Definition: fileop.c:140
int PAPI_cleanup_eventset(int EventSet)
Definition: papi.c:2834
int PAPI_create_eventset(int *EventSet)
Definition: papi.c:1424
int PAPI_event_name_to_code(char *in, int *out)
Definition: papi.c:1010
int PAPI_destroy_eventset(int *EventSet)
Definition: papi.c:1971
int PAPI_start(int EventSet)
Definition: papi.c:2053
int system()
ssize_t retval
Definition: libasync.c:338
#define PAPI_VER_CURRENT
Definition: papi.h:223
int main(int argc, char **argv)
List all appio events codes and names.