PAPI  5.6.0.0
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
net_values_by_code.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 <string.h>
17 
18 #include "papi.h"
19 #include "papi_test.h"
20 
21 #define IFNAME "lo"
22 #define PINGADDR "127.0.0.1"
23 
24 int main (int argc, char **argv)
25 {
26  int retval,cid,numcmp;
27  int EventSet = PAPI_NULL;
28  long long value;
29  int code;
31  int total_events=0;
32  int r;
33  const PAPI_component_info_t *cmpinfo = NULL;
34 
35  /* Set TESTS_QUIET variable */
36  tests_quiet( argc, argv );
37 
38  /* PAPI Initialization */
40  if ( retval != PAPI_VER_CURRENT ) {
41  test_fail(__FILE__, __LINE__,"PAPI_library_init failed\n",retval);
42  }
43 
44  if (!TESTS_QUIET) {
45  printf("Trying all net events\n");
46  }
47 
48  numcmp = PAPI_num_components();
49 
50  for(cid=0; cid<numcmp; cid++) {
51 
52  if ( (cmpinfo = PAPI_get_component_info(cid)) == NULL) {
53  test_fail(__FILE__, __LINE__,"PAPI_get_component_info failed\n",-1);
54  }
55 
56  if (!TESTS_QUIET) {
57  printf("Component %d - %d events - %s\n", cid,
58  cmpinfo->num_native_events, cmpinfo->name);
59  }
60 
61  if ( strstr(cmpinfo->name, "net") == NULL) {
62  continue;
63  }
64 
65  code = PAPI_NATIVE_MASK;
66 
67  r = PAPI_enum_cmp_event( &code, PAPI_ENUM_FIRST, cid );
68  while ( r == PAPI_OK ) {
69 
70  retval = PAPI_event_code_to_name( code, event_name );
71  if ( retval != PAPI_OK ) {
72  test_fail( __FILE__, __LINE__, "PAPI_event_code_to_name", retval );
73  }
74 
75  if (!TESTS_QUIET) {
76  printf("%#x %-24s = ", code, event_name);
77  }
78 
79  EventSet = PAPI_NULL;
80 
81  retval = PAPI_create_eventset( &EventSet );
82  if (retval != PAPI_OK) {
83  test_fail(__FILE__, __LINE__, "PAPI_create_eventset()", retval);
84  }
85 
86  retval = PAPI_add_event( EventSet, code );
87  if (retval != PAPI_OK) {
88  test_fail(__FILE__, __LINE__, "PAPI_add_event()", retval);
89  }
90 
91  retval = PAPI_start( EventSet );
92  if (retval != PAPI_OK) {
93  test_fail(__FILE__, __LINE__, "PAPI_start()", retval);
94  }
95 
96  if (strcmp(event_name, IFNAME ".rx.packets") == 0) {
97  /* generate some traffic
98  * the operation should take more than one second in order
99  * to guarantee that the network counters are updated */
100  retval = system("ping -c 4 " PINGADDR " > /dev/null");
101  if (retval < 0) {
102  test_fail(__FILE__, __LINE__, "Unable to start ping", retval);
103  }
104  }
105 
106  retval = PAPI_stop( EventSet, &value );
107  if (retval != PAPI_OK) {
108  test_fail(__FILE__, __LINE__, "PAPI_stop()", retval);
109  }
110 
111  if (!TESTS_QUIET) printf("%lld\n", value);
112 
113  retval = PAPI_cleanup_eventset( EventSet );
114  if (retval != PAPI_OK) {
115  test_fail(__FILE__, __LINE__, "PAPI_cleanup_eventset()", retval);
116  }
117 
118  retval = PAPI_destroy_eventset( &EventSet );
119  if (retval != PAPI_OK) {
120  test_fail(__FILE__, __LINE__, "PAPI_destroy_eventset()", retval);
121  }
122 
123  total_events++;
124 
125  r = PAPI_enum_cmp_event( &code, PAPI_ENUM_EVENTS, cid );
126  }
127 
128  }
129 
130  if (total_events==0) {
131  test_skip(__FILE__,__LINE__,"No net events found", 0);
132  }
133 
134  test_pass( __FILE__ );
135 
136  return 0;
137 }
138 
139 // vim:set ai ts=4 sw=4 sts=4 et:
char event_name[2][PAPI_MAX_STR_LEN]
Definition: data_range.c:29
char name[PAPI_MAX_STR_LEN]
Definition: papi.h:629
int PAPI_stop(int EventSet, long long *values)
Definition: papi.c:2314
#define PAPI_NATIVE_MASK
const PAPI_component_info_t * PAPI_get_component_info(int cidx)
Definition: papi.c:796
void test_pass(const char *filename)
Definition: test_utils.c:432
int PAPI_add_event(int EventSet, int EventCode)
Definition: papi.c:1663
#define PAPI_NULL
Definition: papi.h:292
int PAPI_num_components(void)
Definition: papi.c:4387
int EventSet
return PAPI_OK
Definition: linux-nvml.c:497
#define PINGADDR
void double value
Definition: iozone.c:18781
int int argc
Definition: iozone.c:1609
Return codes and api definitions.
void test_skip(const char *file, int line, const char *call, int retval)
Definition: test_utils.c:559
char ** argv
Definition: iozone.c:1610
int PAPI_library_init(int version)
Definition: papi.c:500
int PAPI_enum_cmp_event(int *EventCode, int modifier, int cidx)
Definition: papi.c:1357
int PAPI_cleanup_eventset(int EventSet)
Definition: papi.c:2890
int PAPI_create_eventset(int *EventSet)
Definition: papi.c:1464
int PAPI_event_code_to_name(int EventCode, char *out)
Definition: papi.c:915
#define IFNAME
Prints the value of every net event (by code)
printf("\tTry: -i 0 -i 1 \n\n")
int TESTS_QUIET
Definition: test_utils.c:18
int tests_quiet(int argc, char **argv)
Definition: test_utils.c:376
void test_fail(const char *file, int line, const char *call, int retval)
Definition: test_utils.c:468
int PAPI_destroy_eventset(int *EventSet)
Definition: papi.c:2014
#define PAPI_MAX_STR_LEN
Definition: papi.h:465
int PAPI_start(int EventSet)
Definition: papi.c:2096
int system()
ssize_t retval
Definition: libasync.c:338
#define PAPI_VER_CURRENT
Definition: papi.h:225
int main(int argc, char **argv)
List all appio events codes and names.