PAPI  5.3.0.0
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
example_multiple_components.c
Go to the documentation of this file.
1 /****************************/
2 /* THIS IS OPEN SOURCE CODE */
3 /****************************/
4 
17 #include <stdio.h>
18 #include <stdlib.h>
19 #include "papi_test.h"
20 
21 #define NUM_EVENTS 1
22 
23 int main (int argc, char **argv)
24 {
25 
26  int retval;
28  long long values1[NUM_EVENTS];
29  long long values2[NUM_EVENTS];
30  const PAPI_component_info_t *cmpinfo = NULL;
31  int numcmp,cid,example_cid=-1;
32  int code;
33 
34  /* Set TESTS_QUIET variable */
35  tests_quiet( argc, argv );
36 
37  /* PAPI Initialization */
39  if ( retval != PAPI_VER_CURRENT ) {
40  test_fail(__FILE__, __LINE__,"PAPI_library_init failed\n",retval);
41  }
42 
43  if (!TESTS_QUIET) {
44  printf( "Testing simultaneous component use with PAPI %d.%d.%d\n",
48  }
49 
50  /* Find our component */
51 
52  numcmp = PAPI_num_components();
53  for( cid=0; cid<numcmp; cid++) {
54  if ( (cmpinfo = PAPI_get_component_info(cid)) == NULL) {
55  test_fail(__FILE__, __LINE__,
56  "PAPI_get_component_info failed\n", 0);
57  }
58  if (!TESTS_QUIET) {
59  printf("\tComponent %d - %d events - %s\n", cid,
60  cmpinfo->num_native_events,
61  cmpinfo->name);
62  }
63  if (strstr(cmpinfo->name,"example")) {
64  /* FOUND! */
65  example_cid=cid;
66  }
67  }
68 
69 
70  if (example_cid<0) {
71  test_skip(__FILE__, __LINE__,
72  "Example component not found\n", 0);
73  }
74 
75  if (!TESTS_QUIET) {
76  printf("\nFound Example Component at id %d\n",example_cid);
77  }
78 
79 
80  /* Create an eventset for the Example component */
81 
82  retval = PAPI_create_eventset( &EventSet1 );
83  if ( retval != PAPI_OK ) {
84  test_fail( __FILE__, __LINE__,
85  "PAPI_create_eventset() failed\n", retval );
86  }
87 
88  retval = PAPI_event_name_to_code("EXAMPLE_CONSTANT", &code);
89  if ( retval != PAPI_OK ) {
90  test_fail( __FILE__, __LINE__,
91  "EXAMPLE_ZERO not found\n",retval );
92  }
93 
94  retval = PAPI_add_event( EventSet1, code);
95  if ( retval != PAPI_OK ) {
96  test_fail( __FILE__, __LINE__,
97  "PAPI_add_events failed\n", retval );
98  }
99 
100 
101  /* Create an eventset for the CPU component */
102 
103  retval = PAPI_create_eventset( &EventSet2 );
104  if ( retval != PAPI_OK ) {
105  test_fail( __FILE__, __LINE__,
106  "PAPI_create_eventset() failed\n", retval );
107  }
108 
109  retval = PAPI_event_name_to_code("PAPI_TOT_CYC", &code);
110  if ( retval != PAPI_OK ) {
111  test_skip( __FILE__, __LINE__,
112  "PAPI_TOT_CYC not available\n",retval );
113  }
114 
115  retval = PAPI_add_event( EventSet2, code);
116  if ( retval != PAPI_OK ) {
117  test_skip( __FILE__, __LINE__,
118  "NO CPU component found\n", retval );
119  }
120 
121  if (!TESTS_QUIET) printf("\nStarting EXAMPLE_CONSTANT and PAPI_TOT_CYC at the same time\n");
122 
123  /* Start CPU component event */
124  retval = PAPI_start( EventSet2 );
125  if ( retval != PAPI_OK ) {
126  test_fail( __FILE__, __LINE__,
127  "PAPI_start failed\n",retval );
128  }
129 
130  /* Start example component */
131  retval = PAPI_start( EventSet1 );
132  if ( retval != PAPI_OK ) {
133  test_fail( __FILE__, __LINE__,
134  "PAPI_start failed\n",retval );
135  }
136 
137 
138 
139 
140  /* Stop example component */
141  retval = PAPI_stop( EventSet1, values1 );
142  if ( retval != PAPI_OK ) {
143  test_fail( __FILE__, __LINE__, "PAPI_stop failed\n", retval);
144  }
145 
146  /* Stop CPU component */
147  retval = PAPI_stop( EventSet2, values2 );
148  if ( retval != PAPI_OK ) {
149  test_fail( __FILE__, __LINE__, "PAPI_stop failed\n", retval);
150  }
151 
152  if (!TESTS_QUIET) printf("Stopping EXAMPLE_CONSTANT and PAPI_TOT_CYC\n\n");
153 
154 
155  if (!TESTS_QUIET) printf("Results from EXAMPLE_CONSTANT: %lld\n",values1[0]);
156 
157  if (values1[0]!=42) {
158  test_fail( __FILE__, __LINE__, "Result should be 42!\n", 0);
159  }
160 
161  if (!TESTS_QUIET) printf("Results from PAPI_TOT_CYC: %lld\n\n",values2[0]);
162 
163  if (values2[0]<1) {
164  test_fail( __FILE__, __LINE__, "Result should greater than 0\n", 0);
165  }
166 
167  /* Cleanup EventSets */
168  retval = PAPI_cleanup_eventset(EventSet1);
169  if (retval != PAPI_OK) {
170  test_fail( __FILE__, __LINE__, "PAPI_cleanup_eventset!\n", retval);
171  }
172 
173  retval = PAPI_cleanup_eventset(EventSet2);
174  if (retval != PAPI_OK) {
175  test_fail( __FILE__, __LINE__, "PAPI_cleanup_eventset!\n", retval);
176  }
177 
178  /* Destroy EventSets */
179  retval = PAPI_destroy_eventset(&EventSet2);
180  if (retval != PAPI_OK) {
181  test_fail( __FILE__, __LINE__, "PAPI_destroy_eventset!\n", retval);
182  }
183 
184  test_pass( __FILE__, NULL, 0 );
185 
186  return 0;
187 }
188 
char name[PAPI_MAX_STR_LEN]
Definition: papi.h:625
int PAPI_stop(int EventSet, long long *values)
Definition: papi.c:2225
const PAPI_component_info_t * PAPI_get_component_info(int cidx)
Definition: papi.c:803
int PAPI_add_event(int EventSet, int EventCode)
Definition: papi.c:1597
#define PAPI_NULL
Definition: fpapi.h:13
void test_skip(char *file, int line, char *call, int retval)
Definition: test_utils.c:614
#define NUM_EVENTS
int PAPI_num_components(void)
Definition: papi.c:4272
return PAPI_OK
Definition: linux-nvml.c:458
#define PAPI_VERSION
Definition: fpapi.h:15
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:495
#define PAPI_VERSION_MAJOR(x)
Definition: papi.h:215
#define PAPI_VERSION_REVISION(x)
Definition: papi.h:217
#define PAPI_VER_CURRENT
Definition: fpapi.h:14
int EventSet2
Definition: rapl_overflow.c:12
#define PAPI_VERSION_MINOR(x)
Definition: papi.h:216
int PAPI_cleanup_eventset(int EventSet)
Definition: papi.c:2795
int PAPI_create_eventset(int *EventSet)
Definition: papi.c:1399
int PAPI_event_name_to_code(char *in, int *out)
Definition: papi.c:1003
int PAPI_destroy_eventset(int *EventSet)
Definition: papi.c:1937
int PAPI_start(int EventSet)
Definition: papi.c:2019
ssize_t retval
Definition: libasync.c:338
int main(int argc, char **argv)
List all appio events codes and names.
int EventSet1
Definition: zero_fork.c:40