PAPI  5.4.0.0
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
infiniband_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 "papi_test.h"
18 
19 int main (int argc, char **argv)
20 {
21  int retval,cid,numcmp;
22  int EventSet = PAPI_NULL;
23  long long *values = 0;
24  int *codes = 0;
25  char *names = 0;
26  int code, i;
27  int total_events=0;
28  int r;
29  const PAPI_component_info_t *cmpinfo = NULL;
30 
31  /* Set TESTS_QUIET variable */
32  tests_quiet( argc, argv );
33 
34  /* PAPI Initialization */
36  if ( retval != PAPI_VER_CURRENT ) {
37  test_fail(__FILE__, __LINE__,"PAPI_library_init failed\n",retval);
38  }
39 
40  if (!TESTS_QUIET) {
41  printf("Trying all infiniband events\n");
42  }
43 
44  numcmp = PAPI_num_components();
45 
46  for(cid=0; cid<numcmp; cid++) {
47 
48  if ( (cmpinfo = PAPI_get_component_info(cid)) == NULL) {
49  test_fail(__FILE__, __LINE__,"PAPI_get_component_info failed\n",-1);
50  }
51 
52  if (!TESTS_QUIET) {
53  printf("Component %d - %d events - %s\n", cid,
54  cmpinfo->num_native_events, cmpinfo->name);
55  }
56 
57  if ( strstr(cmpinfo->name, "infiniband") == NULL) {
58  continue;
59  }
60  if (cmpinfo->disabled) {
61  test_skip(__FILE__,__LINE__,"Component infiniband is disabled", 0);
62  continue;
63  }
64 
65  values = (long long*) malloc(sizeof(long long) * cmpinfo->num_native_events);
66  codes = (int*) malloc(sizeof(int) * cmpinfo->num_native_events);
67  names = (char*) malloc(PAPI_MAX_STR_LEN * cmpinfo->num_native_events);
68 
69  EventSet = PAPI_NULL;
70 
71  retval = PAPI_create_eventset( &EventSet );
72  if (retval != PAPI_OK) {
73  test_fail(__FILE__, __LINE__, "PAPI_create_eventset()", retval);
74  }
75 
76  code = PAPI_NATIVE_MASK;
77 
78  r = PAPI_enum_cmp_event( &code, PAPI_ENUM_FIRST, cid );
79  i = 0;
80  while ( r == PAPI_OK ) {
81 
82  retval = PAPI_event_code_to_name( code, &names[i*PAPI_MAX_STR_LEN] );
83  if ( retval != PAPI_OK ) {
84  test_fail( __FILE__, __LINE__, "PAPI_event_code_to_name", retval );
85  }
86  codes[i] = code;
87 
88  retval = PAPI_add_event( EventSet, code );
89  if (retval != PAPI_OK) {
90  test_fail(__FILE__, __LINE__, "PAPI_add_event()", retval);
91  }
92 
93  total_events++;
94 
95  r = PAPI_enum_cmp_event( &code, PAPI_ENUM_EVENTS, cid );
96  i += 1;
97  }
98 
99  retval = PAPI_start( EventSet );
100  if (retval != PAPI_OK) {
101  test_fail(__FILE__, __LINE__, "PAPI_start()", retval);
102  }
103 
104  /* XXX figure out a general method to generate some traffic
105  * for infiniband
106  * the operation should take more than one second in order
107  * to guarantee that the network counters are updated */
108  /* For now, just sleep for 10 seconds */
109  sleep(10);
110 
111  retval = PAPI_stop( EventSet, values);
112  if (retval != PAPI_OK) {
113  test_fail(__FILE__, __LINE__, "PAPI_stop()", retval);
114  }
115 
116  if (!TESTS_QUIET) {
117  for (i=0 ; i<cmpinfo->num_native_events ; ++i)
118  printf("%#x %-24s = %lld\n", codes[i], names+i*PAPI_MAX_STR_LEN, values[i]);
119  }
120 
121  retval = PAPI_cleanup_eventset( EventSet );
122  if (retval != PAPI_OK) {
123  test_fail(__FILE__, __LINE__, "PAPI_cleanup_eventset()", retval);
124  }
125 
126  retval = PAPI_destroy_eventset( &EventSet );
127  if (retval != PAPI_OK) {
128  test_fail(__FILE__, __LINE__, "PAPI_destroy_eventset()", retval);
129  }
130 
131  free(names);
132  free(codes);
133  free(values);
134  }
135 
136  if (total_events==0) {
137  test_skip(__FILE__,__LINE__,"No infiniband events found", 0);
138  }
139 
140  test_pass( __FILE__, NULL, 0 );
141 
142  return 0;
143 }
144 
145 // vim:set ai ts=4 sw=4 sts=4 et:
char name[PAPI_MAX_STR_LEN]
Definition: papi.h:626
int PAPI_stop(int EventSet, long long *values)
Definition: papi.c:2258
#define PAPI_NATIVE_MASK
const PAPI_component_info_t * PAPI_get_component_info(int cidx)
Definition: papi.c:807
sleep(1)
int PAPI_add_event(int EventSet, int EventCode)
Definition: papi.c:1622
void test_skip(char *file, int line, char *call, int retval)
Definition: test_utils.c:614
#define PAPI_NULL
Definition: papi.h:290
int EventSet
Definition: data_range.c:25
int PAPI_num_components(void)
Definition: papi.c:4326
return PAPI_OK
Definition: linux-nvml.c:458
tests_quiet(argc, argv)
#define printf
Definition: papi_test.h:125
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:497
int i
Definition: fileop.c:140
free(dummyfile[xx])
int PAPI_enum_cmp_event(int *EventCode, int modifier, int cidx)
Definition: papi.c:1324
int PAPI_cleanup_eventset(int EventSet)
Definition: papi.c:2834
int PAPI_create_eventset(int *EventSet)
Definition: papi.c:1424
int PAPI_event_code_to_name(int EventCode, char *out)
Definition: papi.c:926
int PAPI_destroy_eventset(int *EventSet)
Definition: papi.c:1971
#define PAPI_MAX_STR_LEN
Definition: papi.h:463
int PAPI_start(int EventSet)
Definition: papi.c:2053
static long long values[NUM_EVENTS]
Definition: init_fini.c:10
ssize_t retval
Definition: libasync.c:338
#define PAPI_VER_CURRENT
Definition: papi.h:223
int main(int argc, char **argv)
List all appio events codes and names.
const char * names[NUM_EVENTS]