PAPI 7.1.0.0
Loading...
Searching...
No Matches
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.
 
#define PINGADDR   "127.0.0.1"
 
#define NUM_EVENTS   4
 

Functions

int main (int argc, char **argv)
 

Macro Definition Documentation

◆ IFNAME

#define IFNAME   "lo"
Author
Jose Pedro Oliveira

test case for the linux-net component

Definition at line 24 of file net_values_by_name.c.

◆ NUM_EVENTS

#define NUM_EVENTS   4

Definition at line 27 of file net_values_by_name.c.

◆ PINGADDR

#define PINGADDR   "127.0.0.1"

Definition at line 25 of file net_values_by_name.c.

Function Documentation

◆ main()

int main ( int  argc,
char **  argv 
)

Definition at line 29 of file net_values_by_name.c.

30{
31 int i, retval;
32 int EventSet = PAPI_NULL;
33 char *event_name[NUM_EVENTS] = {
34 IFNAME ":rx:bytes",
35 IFNAME ":rx:packets",
36 IFNAME ":tx:bytes",
37 IFNAME ":tx:packets",
38 };
39 int event_code[NUM_EVENTS] = { 0, 0, 0, 0};
40 long long event_value[NUM_EVENTS];
41 int total_events=0;
42
43 /* Set TESTS_QUIET variable */
44 tests_quiet( argc, argv );
45
46 /* PAPI Initialization */
48 if ( retval != PAPI_VER_CURRENT ) {
49 test_fail(__FILE__, __LINE__,"PAPI_library_init failed\n",retval);
50 }
51
52 if (!TESTS_QUIET) {
53 printf("Net events by name\n");
54 }
55
56 /* Map names to codes */
57 for ( i=0; i<NUM_EVENTS; i++ ) {
58 retval = PAPI_event_name_to_code( event_name[i], &event_code[i]);
59 if ( retval != PAPI_OK ) {
60 test_fail( __FILE__, __LINE__, "PAPI_event_name_to_code", retval );
61 }
62
63 total_events++;
64 }
65
66 /* Create and populate the EventSet */
68
70 if (retval != PAPI_OK) {
71 test_fail(__FILE__, __LINE__, "PAPI_create_eventset()", retval);
72 }
73
75 if (retval != PAPI_OK) {
76 test_fail(__FILE__, __LINE__, "PAPI_add_events()", retval);
77 }
78
80 if (retval != PAPI_OK) {
81 test_fail(__FILE__, __LINE__, "PAPI_start()", retval);
82 }
83
84 /* generate some traffic
85 * the operation should take more than one second in order
86 * to guarantee that the network counters are updated */
87 retval = system("ping -c 4 " PINGADDR " > /dev/null");
88 if (retval < 0) {
89 test_fail(__FILE__, __LINE__, "Unable to start ping", retval);
90 }
91
92 retval = PAPI_stop( EventSet, event_value );
93 if (retval != PAPI_OK) {
94 test_fail(__FILE__, __LINE__, "PAPI_start()", retval);
95 }
96
97 if (!TESTS_QUIET) {
98 for ( i=0; i<NUM_EVENTS; i++ ) {
99 printf("%#x %-24s = %lld\n",
100 event_code[i], event_name[i], event_value[i]);
101 }
102 }
103
105 if (retval != PAPI_OK) {
106 test_fail(__FILE__, __LINE__, "PAPI_cleanup_eventset()", retval);
107 }
108
110 if (retval != PAPI_OK) {
111 test_fail(__FILE__, __LINE__, "PAPI_destroy_eventset()", retval);
112 }
113
114 test_pass( __FILE__ );
115
116 return 0;
117}
int i
add multiple PAPI presets or native hardware events to an event set
Empty and destroy an EventSet.
Create a new empty PAPI EventSet.
Empty and destroy an EventSet.
Convert a name to a numeric hardware event code.
initialize the PAPI library.
Start counting hardware events in an event set.
Stop counting hardware events in an event set.
char event_name[2][PAPI_MAX_STR_LEN]
Definition: data_range.c:29
#define PAPI_VER_CURRENT
Definition: f90papi.h:54
#define PAPI_OK
Definition: f90papi.h:73
#define PAPI_NULL
Definition: f90papi.h:78
static int EventSet
Definition: init_fini.c:8
int TESTS_QUIET
Definition: test_utils.c:18
#define IFNAME
Prints the values of several net events specified by names.
#define PINGADDR
#define NUM_EVENTS
int tests_quiet(int argc, char **argv)
Definition: test_utils.c:376
void PAPI_NORETURN test_fail(const char *file, int line, const char *call, int retval)
Definition: test_utils.c:491
void PAPI_NORETURN test_pass(const char *filename)
Definition: test_utils.c:432
int retval
Definition: zero_fork.c:53
Here is the call graph for this function: