PAPI  5.3.2.0
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
vmware_basic.c
Go to the documentation of this file.
1 
11 #include <stdio.h>
12 #include <stdlib.h>
13 #include "papi_test.h"
14 
15 #define NUM_EVENTS 1
16 
17 int main (int argc, char **argv)
18 {
19 
20  int retval,cid,numcmp;
21  int EventSet = PAPI_NULL;
22  long long values[NUM_EVENTS];
23  int code;
25  int total_events=0;
26  int r;
27  const PAPI_component_info_t *cmpinfo = NULL;
28 
29  /* Set TESTS_QUIET variable */
30  tests_quiet( argc, argv );
31 
32  /* PAPI Initialization */
34  if ( retval != PAPI_VER_CURRENT ) {
35  test_fail(__FILE__, __LINE__,"PAPI_library_init failed\n",retval);
36  }
37 
38  if (!TESTS_QUIET) {
39  printf("Trying all vmware events\n");
40  }
41 
42  /* Find our Component */
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", 0);
50  }
51 
52  if (strstr(cmpinfo->name,"vmware")) {
53  if (!TESTS_QUIET) printf("\tFound vmware component %d - %s\n", cid, cmpinfo->name);
54  }
55  else {
56  continue;
57  }
58 
59  PAPI_event_info_t info;
60 
61  /* Try all events one by one */
62 
63  code = PAPI_NATIVE_MASK;
64 
65  r = PAPI_enum_cmp_event( &code, PAPI_ENUM_FIRST, cid );
66 
67  while ( r == PAPI_OK ) {
68 
69  retval=PAPI_get_event_info(code,&info);
70  if (retval!=PAPI_OK) {
71  printf("Error getting event info\n");
72  test_fail( __FILE__, __LINE__,
73  "PAPI_get_event_info", retval );
74  }
75 
76  retval = PAPI_event_code_to_name( code, event_name );
77  if ( retval != PAPI_OK ) {
78  printf("Error translating %#x\n",code);
79  test_fail( __FILE__, __LINE__,
80  "PAPI_event_code_to_name", retval );
81  }
82 
83  if (!TESTS_QUIET) printf(" %s ",event_name);
84 
85  EventSet = PAPI_NULL;
86 
87  retval = PAPI_create_eventset( &EventSet );
88  if (retval != PAPI_OK) {
89  test_fail(__FILE__, __LINE__,
90  "PAPI_create_eventset()",retval);
91  }
92 
93  retval = PAPI_add_event( EventSet, code );
94  if (retval != PAPI_OK) {
95  test_fail(__FILE__, __LINE__,
96  "PAPI_add_event()",retval);
97  }
98 
99  /* start */
100  retval = PAPI_start( EventSet);
101  if (retval != PAPI_OK) {
102  test_fail(__FILE__, __LINE__, "PAPI_start()",retval);
103  }
104 
105  /* do something */
106  usleep(100);
107 
108  /* stop */
109  retval = PAPI_stop( EventSet, values);
110  if (retval != PAPI_OK) {
111  test_fail(__FILE__, __LINE__, "PAPI_start()",retval);
112  }
113 
114  if (!TESTS_QUIET) printf(" value: %lld %s\n",values[0],
115  info.units);
116 
117  retval = PAPI_cleanup_eventset( EventSet );
118  if (retval != PAPI_OK) {
119  test_fail(__FILE__, __LINE__,
120  "PAPI_cleanup_eventset()",retval);
121  }
122 
123  retval = PAPI_destroy_eventset( &EventSet );
124  if (retval != PAPI_OK) {
125  test_fail(__FILE__, __LINE__,
126  "PAPI_destroy_eventset()",retval);
127  }
128 
129  total_events++;
130 
131  r = PAPI_enum_cmp_event( &code, PAPI_ENUM_EVENTS, cid );
132  }
133  }
134 
135  if (total_events==0) {
136  test_skip(__FILE__,__LINE__,"No vmware events found",0);
137  }
138 
139  if (!TESTS_QUIET) {
140  printf("\n");
141  }
142 
143  test_pass( __FILE__, NULL, 0 );
144 
145  return 0;
146 }
147 
char event_name[2][PAPI_MAX_STR_LEN]
Definition: data_range.c:23
char name[PAPI_MAX_STR_LEN]
Definition: papi.h:625
int PAPI_stop(int EventSet, long long *values)
Definition: papi.c:2232
#define PAPI_NATIVE_MASK
const PAPI_component_info_t * PAPI_get_component_info(int cidx)
Definition: papi.c:805
int PAPI_add_event(int EventSet, int EventCode)
Definition: papi.c:1604
#define PAPI_NULL
Definition: fpapi.h:13
#define PAPI_MAX_STR_LEN
Definition: fpapi.h:43
#define NUM_EVENTS
Tests basic vmware functionality.
Definition: vmware_basic.c:15
void test_skip(char *file, int line, char *call, int retval)
Definition: test_utils.c:614
int PAPI_num_components(void)
Definition: papi.c:4285
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 PAPI_get_event_info(int EventCode, PAPI_event_info_t *info)
Definition: papi.c:844
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:495
#define PAPI_VER_CURRENT
Definition: fpapi.h:14
int PAPI_enum_cmp_event(int *EventCode, int modifier, int cidx)
Definition: papi.c:1311
int PAPI_cleanup_eventset(int EventSet)
Definition: papi.c:2805
int PAPI_create_eventset(int *EventSet)
Definition: papi.c:1406
int PAPI_event_code_to_name(int EventCode, char *out)
Definition: papi.c:924
int EventSet
int PAPI_destroy_eventset(int *EventSet)
Definition: papi.c:1944
int PAPI_start(int EventSet)
Definition: papi.c:2026
static long long values[NUM_EVENTS]
Definition: init_fini.c:10
ssize_t retval
Definition: libasync.c:338
int main(int argc, char **argv)
List all appio events codes and names.
char units[PAPI_MIN_STR_LEN]
Definition: papi.h:970