PAPI  5.6.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 <string.h>
20 
21 #include "papi.h"
22 #include "papi_test.h"
23 
24 #define NUM_EVENTS 1
25 
26 int main (int argc, char **argv)
27 {
28 
29  int retval;
31  long long values1[NUM_EVENTS];
32  long long values2[NUM_EVENTS];
33  const PAPI_component_info_t *cmpinfo = NULL;
34  int numcmp,cid,example_cid=-1;
35  int code;
36  int quiet=0;
37 
38  /* Set TESTS_QUIET variable */
39  quiet=tests_quiet( argc, argv );
40 
41  /* PAPI Initialization */
43  if ( retval != PAPI_VER_CURRENT ) {
44  test_fail(__FILE__, __LINE__,"PAPI_library_init failed\n",retval);
45  }
46 
47  if (!quiet) {
48  printf( "Testing simultaneous component use with PAPI %d.%d.%d\n",
52  }
53 
54  /* Find our component */
55 
56  numcmp = PAPI_num_components();
57  for( cid=0; cid<numcmp; cid++) {
58  if ( (cmpinfo = PAPI_get_component_info(cid)) == NULL) {
59  test_fail(__FILE__, __LINE__,
60  "PAPI_get_component_info failed\n", 0);
61  }
62  if (!quiet) {
63  printf("\tComponent %d - %d events - %s\n", cid,
64  cmpinfo->num_native_events,
65  cmpinfo->name);
66  }
67  if (strstr(cmpinfo->name,"example")) {
68  /* FOUND! */
69  example_cid=cid;
70  }
71  }
72 
73 
74  if (example_cid<0) {
75  test_skip(__FILE__, __LINE__,
76  "Example component not found\n", 0);
77  }
78 
79  if (!quiet) {
80  printf("\nFound Example Component at id %d\n",example_cid);
81  }
82 
83 
84  /* Create an eventset for the Example component */
85 
86  retval = PAPI_create_eventset( &EventSet1 );
87  if ( retval != PAPI_OK ) {
88  test_fail( __FILE__, __LINE__,
89  "PAPI_create_eventset() failed\n", retval );
90  }
91 
92  retval = PAPI_event_name_to_code("EXAMPLE_CONSTANT", &code);
93  if ( retval != PAPI_OK ) {
94  test_fail( __FILE__, __LINE__,
95  "EXAMPLE_ZERO not found\n",retval );
96  }
97 
98  retval = PAPI_add_event( EventSet1, code);
99  if ( retval != PAPI_OK ) {
100  test_fail( __FILE__, __LINE__,
101  "PAPI_add_events failed\n", retval );
102  }
103 
104 
105  /* Create an eventset for the CPU component */
106 
107  retval = PAPI_create_eventset( &EventSet2 );
108  if ( retval != PAPI_OK ) {
109  test_fail( __FILE__, __LINE__,
110  "PAPI_create_eventset() failed\n", retval );
111  }
112 
113  retval = PAPI_event_name_to_code("PAPI_TOT_CYC", &code);
114  if ( retval != PAPI_OK ) {
115  test_skip( __FILE__, __LINE__,
116  "PAPI_TOT_CYC not available\n",retval );
117  }
118 
119  retval = PAPI_add_event( EventSet2, code);
120  if ( retval != PAPI_OK ) {
121  test_skip( __FILE__, __LINE__,
122  "NO CPU component found\n", retval );
123  }
124 
125  if (!quiet) printf("\nStarting EXAMPLE_CONSTANT and PAPI_TOT_CYC at the same time\n");
126 
127  /* Start CPU component event */
128  retval = PAPI_start( EventSet2 );
129  if ( retval != PAPI_OK ) {
130  test_fail( __FILE__, __LINE__,
131  "PAPI_start failed\n",retval );
132  }
133 
134  /* Start example component */
135  retval = PAPI_start( EventSet1 );
136  if ( retval != PAPI_OK ) {
137  test_fail( __FILE__, __LINE__,
138  "PAPI_start failed\n",retval );
139  }
140 
141 
142 
143 
144  /* Stop example component */
145  retval = PAPI_stop( EventSet1, values1 );
146  if ( retval != PAPI_OK ) {
147  test_fail( __FILE__, __LINE__, "PAPI_stop failed\n", retval);
148  }
149 
150  /* Stop CPU component */
151  retval = PAPI_stop( EventSet2, values2 );
152  if ( retval != PAPI_OK ) {
153  test_fail( __FILE__, __LINE__, "PAPI_stop failed\n", retval);
154  }
155 
156  if (!quiet) printf("Stopping EXAMPLE_CONSTANT and PAPI_TOT_CYC\n\n");
157 
158 
159  if (!quiet) printf("Results from EXAMPLE_CONSTANT: %lld\n",values1[0]);
160 
161  if (values1[0]!=42) {
162  test_fail( __FILE__, __LINE__, "Result should be 42!\n", 0);
163  }
164 
165  if (!quiet) printf("Results from PAPI_TOT_CYC: %lld\n\n",values2[0]);
166 
167  if (values2[0]<1) {
168  test_fail( __FILE__, __LINE__, "Result should greater than 0\n", 0);
169  }
170 
171  /* Cleanup EventSets */
172  retval = PAPI_cleanup_eventset(EventSet1);
173  if (retval != PAPI_OK) {
174  test_fail( __FILE__, __LINE__, "PAPI_cleanup_eventset!\n", retval);
175  }
176 
177  retval = PAPI_cleanup_eventset(EventSet2);
178  if (retval != PAPI_OK) {
179  test_fail( __FILE__, __LINE__, "PAPI_cleanup_eventset!\n", retval);
180  }
181 
182  /* Destroy EventSets */
183  retval = PAPI_destroy_eventset(&EventSet2);
184  if (retval != PAPI_OK) {
185  test_fail( __FILE__, __LINE__, "PAPI_destroy_eventset!\n", retval);
186  }
187 
188  test_pass( __FILE__ );
189 
190  return 0;
191 }
192 
char name[PAPI_MAX_STR_LEN]
Definition: papi.h:629
int PAPI_stop(int EventSet, long long *values)
Definition: papi.c:2314
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
#define NUM_EVENTS
#define PAPI_NULL
Definition: papi.h:292
int PAPI_num_components(void)
Definition: papi.c:4387
return PAPI_OK
Definition: linux-nvml.c:497
int PAPI_event_name_to_code(const char *in, int *out)
Definition: papi.c:1004
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
#define PAPI_VERSION_MAJOR(x)
Definition: papi.h:217
int quiet
Definition: rapl_overflow.c:18
#define PAPI_VERSION_REVISION(x)
Definition: papi.h:219
int EventSet2
Definition: rapl_overflow.c:16
#define PAPI_VERSION_MINOR(x)
Definition: papi.h:218
int PAPI_cleanup_eventset(int EventSet)
Definition: papi.c:2890
int PAPI_create_eventset(int *EventSet)
Definition: papi.c:1464
printf("\tTry: -i 0 -i 1 \n\n")
#define PAPI_VERSION
Definition: papi.h:224
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
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.
int EventSet1
Definition: zero_fork.c:47