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

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 21 of file net_values_by_code.c.

◆ PINGADDR

#define PINGADDR   "127.0.0.1"

Definition at line 22 of file net_values_by_code.c.

Function Documentation

◆ main()

int main ( int  argc,
char **  argv 
)

Definition at line 24 of file net_values_by_code.c.

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
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
80
82 if (retval != PAPI_OK) {
83 test_fail(__FILE__, __LINE__, "PAPI_create_eventset()", retval);
84 }
85
87 if (retval != PAPI_OK) {
88 test_fail(__FILE__, __LINE__, "PAPI_add_event()", retval);
89 }
90
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
114 if (retval != PAPI_OK) {
115 test_fail(__FILE__, __LINE__, "PAPI_cleanup_eventset()", retval);
116 }
117
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}
add PAPI preset or native hardware event to an event set
Empty and destroy an EventSet.
Create a new empty PAPI EventSet.
Empty and destroy an EventSet.
Enumerate PAPI preset or native events for a given component.
Convert a numeric hardware event code to a name.
get information about a specific software component
initialize the PAPI library.
Get the number of components available on the system.
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_ENUM_EVENTS
Definition: f90papi.h:224
#define PAPI_OK
Definition: f90papi.h:73
#define PAPI_ENUM_FIRST
Definition: f90papi.h:85
#define PAPI_NULL
Definition: f90papi.h:78
#define PAPI_MAX_STR_LEN
Definition: f90papi.h:77
static int EventSet
Definition: init_fini.c:8
int TESTS_QUIET
Definition: test_utils.c:18
#define IFNAME
Prints the value of every net event (by code)
#define PINGADDR
#define PAPI_NATIVE_MASK
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
void PAPI_NORETURN test_skip(const char *file, int line, const char *call, int retval)
Definition: test_utils.c:584
char name[PAPI_MAX_STR_LEN]
Definition: papi.h:627
int retval
Definition: zero_fork.c:53
Here is the call graph for this function: