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

Go to the source code of this file.

Macros

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

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

22 {
23  int retval,cid,numcmp;
24  int EventSet = PAPI_NULL;
25  long long value;
26  int code;
28  int total_events=0;
29  int r;
30  const PAPI_component_info_t *cmpinfo = NULL;
31 
32  /* Set TESTS_QUIET variable */
33  tests_quiet( argc, argv );
34 
35  /* PAPI Initialization */
37  if ( retval != PAPI_VER_CURRENT ) {
38  test_fail(__FILE__, __LINE__,"PAPI_library_init failed\n",retval);
39  }
40 
41  if (!TESTS_QUIET) {
42  printf("Trying all net events\n");
43  }
44 
45  numcmp = PAPI_num_components();
46 
47  for(cid=0; cid<numcmp; cid++) {
48 
49  if ( (cmpinfo = PAPI_get_component_info(cid)) == NULL) {
50  test_fail(__FILE__, __LINE__,"PAPI_get_component_info failed\n",-1);
51  }
52 
53  if (!TESTS_QUIET) {
54  printf("Component %d - %d events - %s\n", cid,
55  cmpinfo->num_native_events, cmpinfo->name);
56  }
57 
58  if ( strstr(cmpinfo->name, "net") == NULL) {
59  continue;
60  }
61 
62  code = PAPI_NATIVE_MASK;
63 
64  r = PAPI_enum_cmp_event( &code, PAPI_ENUM_FIRST, cid );
65  while ( r == PAPI_OK ) {
66 
67  retval = PAPI_event_code_to_name( code, event_name );
68  if ( retval != PAPI_OK ) {
69  test_fail( __FILE__, __LINE__, "PAPI_event_code_to_name", retval );
70  }
71 
72  if (!TESTS_QUIET) {
73  printf("%#x %-24s = ", code, event_name);
74  }
75 
76  EventSet = PAPI_NULL;
77 
78  retval = PAPI_create_eventset( &EventSet );
79  if (retval != PAPI_OK) {
80  test_fail(__FILE__, __LINE__, "PAPI_create_eventset()", retval);
81  }
82 
83  retval = PAPI_add_event( EventSet, code );
84  if (retval != PAPI_OK) {
85  test_fail(__FILE__, __LINE__, "PAPI_add_event()", retval);
86  }
87 
88  retval = PAPI_start( EventSet );
89  if (retval != PAPI_OK) {
90  test_fail(__FILE__, __LINE__, "PAPI_start()", retval);
91  }
92 
93  if (strcmp(event_name, IFNAME ".rx.packets") == 0) {
94  /* generate some traffic
95  * the operation should take more than one second in order
96  * to guarantee that the network counters are updated */
97  retval = system("ping -c 4 " PINGADDR " > /dev/null");
98  if (retval < 0) {
99  test_fail(__FILE__, __LINE__, "Unable to start ping", retval);
100  }
101  }
102 
103  retval = PAPI_stop( EventSet, &value );
104  if (retval != PAPI_OK) {
105  test_fail(__FILE__, __LINE__, "PAPI_stop()", retval);
106  }
107 
108  if (!TESTS_QUIET) printf("%lld\n", value);
109 
110  retval = PAPI_cleanup_eventset( EventSet );
111  if (retval != PAPI_OK) {
112  test_fail(__FILE__, __LINE__, "PAPI_cleanup_eventset()", retval);
113  }
114 
115  retval = PAPI_destroy_eventset( &EventSet );
116  if (retval != PAPI_OK) {
117  test_fail(__FILE__, __LINE__, "PAPI_destroy_eventset()", retval);
118  }
119 
120  total_events++;
121 
122  r = PAPI_enum_cmp_event( &code, PAPI_ENUM_EVENTS, cid );
123  }
124 
125  }
126 
127  if (total_events==0) {
128  test_skip(__FILE__,__LINE__,"No net events found", 0);
129  }
130 
131  test_pass( __FILE__, NULL, 0 );
132 
133  return 0;
134 }
char event_name[2][PAPI_MAX_STR_LEN]
Definition: data_range.c:23
char name[PAPI_MAX_STR_LEN]
Definition: papi.h:625
int PAPI_stop(int EventSet, long long *values)
Definition: papi.c:2232
#define PAPI_NATIVE_MASK
const PAPI_component_info_t * PAPI_get_component_info(int cidx)
Definition: papi.c:805
int PAPI_add_event(int EventSet, int EventCode)
Definition: papi.c:1604
#define PAPI_NULL
Definition: fpapi.h:13
#define PAPI_MAX_STR_LEN
Definition: fpapi.h:43
void test_skip(char *file, int line, char *call, int retval)
Definition: test_utils.c:614
int PAPI_num_components(void)
Definition: papi.c:4285
return PAPI_OK
Definition: linux-nvml.c:458
tests_quiet(argc, argv)
#define PINGADDR
#define printf
Definition: papi_test.h:125
void double value
Definition: iozone.c:18781
test_pass(__FILE__, NULL, 0)
int int argc
Definition: iozone.c:1609
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
#define PAPI_VER_CURRENT
Definition: fpapi.h:14
int PAPI_enum_cmp_event(int *EventCode, int modifier, int cidx)
Definition: papi.c:1311
int PAPI_cleanup_eventset(int EventSet)
Definition: papi.c:2805
int PAPI_create_eventset(int *EventSet)
Definition: papi.c:1406
int PAPI_event_code_to_name(int EventCode, char *out)
Definition: papi.c:924
int EventSet
#define IFNAME
Prints the value of every net event (by code)
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: