PAPI  5.6.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 <string.h>
18 #include <unistd.h>
19 
20 #include "papi.h"
21 #include "papi_test.h"
22 
23 int main (int argc, char **argv)
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 
73  EventSet = PAPI_NULL;
74 
75  retval = PAPI_create_eventset( &EventSet );
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 
86  retval = PAPI_event_code_to_name( code, &names[i*PAPI_MAX_STR_LEN] );
87  if ( retval != PAPI_OK ) {
88  test_fail( __FILE__, __LINE__, "PAPI_event_code_to_name", retval );
89  }
90  codes[i] = code;
91 
92  retval = PAPI_add_event( EventSet, code );
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 
103  retval = PAPI_start( EventSet );
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 
115  retval = PAPI_stop( EventSet, values);
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 
125  retval = PAPI_cleanup_eventset( EventSet );
126  if (retval != PAPI_OK) {
127  test_fail(__FILE__, __LINE__, "PAPI_cleanup_eventset()", retval);
128  }
129 
130  retval = PAPI_destroy_eventset( &EventSet );
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 }
148 
149 // vim:set ai ts=4 sw=4 sts=4 et:
char name[PAPI_MAX_STR_LEN]
Definition: papi.h:629
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
sleep(1)
int PAPI_add_event(int EventSet, int EventCode)
Definition: papi.c:1663
#define PAPI_NULL
Definition: papi.h:292
int PAPI_num_components(void)
Definition: papi.c:4387
int EventSet
return PAPI_OK
Definition: linux-nvml.c:497
int int argc
Definition: iozone.c:1609
Return codes and api definitions.
void test_skip(const char *file, int line, const char *call, int retval)
Definition: test_utils.c:559
char ** argv
Definition: iozone.c:1610
int PAPI_library_init(int version)
Definition: papi.c:500
int i
Definition: fileop.c:140
free(dummyfile[xx])
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
printf("\tTry: -i 0 -i 1 \n\n")
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
#define PAPI_MAX_STR_LEN
Definition: papi.h:465
int PAPI_start(int EventSet)
Definition: papi.c:2096
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:225
int main(int argc, char **argv)
List all appio events codes and names.
const char * names[NUM_EVENTS]