PAPI  5.7.0.0
infiniband_umad_values_by_code.c
Go to the documentation of this file.
1 /****************************/
2 /* THIS IS OPEN SOURCE CODE */
3 /****************************/
4 
15 #include <stdio.h>
16 #include <stdlib.h>
17 #include <string.h>
18 
19 #include "papi.h"
20 #include "papi_test.h"
21 
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, "infiniband") == 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 
86  retval = PAPI_add_event( EventSet, code );
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, "_recv") == 0) {
97  /* XXX figure out a general method to generate some traffic
98  * for infiniband
99  * the operation should take more than one second in order
100  * to guarantee that the network counters are updated */
101  retval = system("ping -c 4 " PINGADDR " > /dev/null");
102  if (retval < 0) {
103  test_fail(__FILE__, __LINE__, "Unable to start ping", retval);
104  }
105  }
106 
107  retval = PAPI_stop( EventSet, &value );
108  if (retval != PAPI_OK) {
109  test_fail(__FILE__, __LINE__, "PAPI_stop()", retval);
110  }
111 
112  if (!TESTS_QUIET) printf("%lld\n", value);
113 
115  if (retval != PAPI_OK) {
116  test_fail(__FILE__, __LINE__, "PAPI_cleanup_eventset()", retval);
117  }
118 
120  if (retval != PAPI_OK) {
121  test_fail(__FILE__, __LINE__, "PAPI_destroy_eventset()", retval);
122  }
123 
124  total_events++;
125 
126  r = PAPI_enum_cmp_event( &code, PAPI_ENUM_EVENTS, cid );
127  }
128 
129  }
130 
131  if (total_events==0) {
132  test_skip(__FILE__,__LINE__,"No net events found", 0);
133  }
134 
135  test_pass( __FILE__ );
136 
137  return 0;
138 }
139 
140 // vim:set ai ts=4 sw=4 sts=4 et:
char event_name[2][PAPI_MAX_STR_LEN]
Definition: data_range.c:29
#define PAPI_OK
Definition: fpapi.h:105
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
int main(int argc, char **argv)
int PAPI_num_components(void)
Definition: papi.c:4387
#define PAPI_VER_CURRENT
Definition: fpapi.h:14
int EventSet
int retval
Definition: zero_fork.c:53
#define PINGADDR
Prints the value of every net event (by code)
Return codes and api definitions.
void test_skip(const char *file, int line, const char *call, int retval)
Definition: test_utils.c:561
int PAPI_library_init(int version)
Definition: papi.c:500
#define PAPI_NULL
Definition: fpapi.h:13
char name[PAPI_MAX_STR_LEN]
Definition: papi.h:630
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
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
int PAPI_start(int EventSet)
Definition: papi.c:2096
int system()
#define PAPI_MAX_STR_LEN
Definition: fpapi.h:43