PAPI 7.1.0.0
Loading...
Searching...
No Matches
infiniband_values_by_code.c File Reference
Include dependency graph for infiniband_values_by_code.c:

Go to the source code of this file.

Functions

int main (int argc, char **argv)
 Prints the value of every native event (by code)
 

Function Documentation

◆ main()

int main ( int  argc,
char **  argv 
)
Author
Jose Pedro Oliveira

test case for the linux-infiniband component Adapted from its counterpart in the net component.

Definition at line 23 of file infiniband_values_by_code.c.

24{
25 int retval,cid,numcmp;
26 int EventSet = PAPI_NULL;
27 long long *values = 0;
28 int *codes = 0;
29 char *names = 0;
30 int code, i;
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 infiniband 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, "infiniband") == NULL) {
62 continue;
63 }
64 if (cmpinfo->disabled) {
65 test_skip(__FILE__,__LINE__,"Component infiniband is disabled", 0);
66 continue;
67 }
68
69 values = (long long*) malloc(sizeof(long long) * cmpinfo->num_native_events);
70 codes = (int*) malloc(sizeof(int) * cmpinfo->num_native_events);
71 names = (char*) malloc(PAPI_MAX_STR_LEN * cmpinfo->num_native_events);
72
74
76 if (retval != PAPI_OK) {
77 test_fail(__FILE__, __LINE__, "PAPI_create_eventset()", retval);
78 }
79
80 code = PAPI_NATIVE_MASK;
81
82 r = PAPI_enum_cmp_event( &code, PAPI_ENUM_FIRST, cid );
83 i = 0;
84 while ( r == PAPI_OK ) {
85
87 if ( retval != PAPI_OK ) {
88 test_fail( __FILE__, __LINE__, "PAPI_event_code_to_name", retval );
89 }
90 codes[i] = code;
91
93 if (retval != PAPI_OK) {
94 test_fail(__FILE__, __LINE__, "PAPI_add_event()", retval);
95 }
96
97 total_events++;
98
99 r = PAPI_enum_cmp_event( &code, PAPI_ENUM_EVENTS, cid );
100 i += 1;
101 }
102
104 if (retval != PAPI_OK) {
105 test_fail(__FILE__, __LINE__, "PAPI_start()", retval);
106 }
107
108 /* XXX figure out a general method to generate some traffic
109 * for infiniband
110 * the operation should take more than one second in order
111 * to guarantee that the network counters are updated */
112 /* For now, just sleep for 10 seconds */
113 sleep(10);
114
116 if (retval != PAPI_OK) {
117 test_fail(__FILE__, __LINE__, "PAPI_stop()", retval);
118 }
119
120 if (!TESTS_QUIET) {
121 for (i=0 ; i<cmpinfo->num_native_events ; ++i)
122 printf("%#x %-24s = %lld\n", codes[i], names+i*PAPI_MAX_STR_LEN, values[i]);
123 }
124
126 if (retval != PAPI_OK) {
127 test_fail(__FILE__, __LINE__, "PAPI_cleanup_eventset()", retval);
128 }
129
131 if (retval != PAPI_OK) {
132 test_fail(__FILE__, __LINE__, "PAPI_destroy_eventset()", retval);
133 }
134
135 free(names);
136 free(codes);
137 free(values);
138 }
139
140 if (total_events==0) {
141 test_skip(__FILE__,__LINE__,"No infiniband events found", 0);
142 }
143
144 test_pass( __FILE__ );
145
146 return 0;
147}
int i
const char * names[NUM_EVENTS]
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.
#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
static long long values[NUM_EVENTS]
Definition: init_fini.c:10
int TESTS_QUIET
Definition: test_utils.c:18
#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: