PAPI  5.6.0.0
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
api.c File Reference
Include dependency graph for api.c:

Go to the source code of this file.

Functions

int main (int argc, char **argv)
 

Function Documentation

int main ( int  argc,
char **  argv 
)

Definition at line 20 of file api.c.

21 {
22  const int NUM_COUNTERS = 1;
23  int Events[] = { PAPI_TOT_INS };
24  long long values[NUM_COUNTERS];
25  float rtime, ptime, ipc, mflips, mflops;
26  long long ins, flpins, flpops;
27  int retval;
28  int quiet=0;
29 
30  quiet=tests_quiet( argc, argv );
31 
32  /* Initialize PAPI */
34  if ( retval != PAPI_VER_CURRENT ) {
35  test_fail( __FILE__, __LINE__, "PAPI_library_init", retval );
36  }
37 
38  /****** High Level API ******/
39 
40  if ( !quiet ) printf( "Testing PAPI_num_components... " );
41 
42  /* get the number of components available on the system */
43  retval = PAPI_num_components( );
44  if ( !quiet ) printf( "%d\n", retval );
45 
46  if ( retval == 0) {
47  if ( !quiet ) printf( "No components found, skipping high level tests\n");
48  test_skip(__FILE__, __LINE__, "No components found", 0);
49  }
50 
51  if ( !quiet ) printf( "Testing PAPI_num_counters... " );
52 
53  /* get the number of hardware counters available on the system */
54  retval = PAPI_num_counters( );
55  if ( retval != PAPI_get_cmp_opt( PAPI_MAX_HWCTRS, NULL, 0 ) ) {
56  test_fail( __FILE__, __LINE__, "PAPI_num_counters", retval );
57  }
58  else if ( !quiet ) printf( "%d\n", retval );
59 
60 
61  /* Test PAPI_start_counters() */
62  if ( !quiet ) printf( "Testing PAPI_start_counters... " );
63  // pass invalid 1st argument
64  retval = PAPI_start_counters( NULL, NUM_COUNTERS );
65  if ( retval != PAPI_EINVAL ) {
66  test_fail( __FILE__, __LINE__, "PAPI_start_counters", retval );
67  }
68  // pass invalid 2nd argument
69  retval = PAPI_start_counters( Events, 0 );
70  if ( retval != PAPI_EINVAL ) {
71  test_fail( __FILE__, __LINE__, "PAPI_start_counters", retval );
72  }
73  /* Try PAPI_TOT_INS */
74  retval = PAPI_start_counters( Events, NUM_COUNTERS );
75  if ( retval != PAPI_OK ) {
76  if (!quiet) printf("\nCould not start PAPI_TOT_INS\n");
77  test_skip( __FILE__, __LINE__, "PAPI_TOT_INS not available.", retval );
78  }
79  else {
80  if ( !quiet ) printf( "started PAPI_TOT_INS\n" );
81  }
82 
83  /* Test PAPI_stop_counters() */
84  if ( !quiet ) printf( "Testing PAPI_stop_counters... " );
85  // pass invalid 1st argument
86  retval = PAPI_stop_counters( NULL, NUM_COUNTERS );
87  if ( retval != PAPI_EINVAL ) {
88  test_fail( __FILE__, __LINE__, "PAPI_stop_counters", retval );
89  }
90  // pass invalid 2nd argument
91  retval = PAPI_stop_counters( values, 0 );
92  if ( retval != PAPI_EINVAL ) {
93  test_fail( __FILE__, __LINE__, "PAPI_stop_counters", retval );
94  }
95  // stop counters and return current counts
96  retval = PAPI_stop_counters( values, NUM_COUNTERS );
97  if ( retval != PAPI_OK ) {
98  test_fail( __FILE__, __LINE__, "PAPI_stop_counters", retval );
99  }
100  else if ( !quiet ) printf( "stopped counting PAPI_TOT_INS\n" );
101  //NOTE: There are currently no checks on whether or not counter values are correct
102 
103 
104  // start counting hardware events again
105  retval = PAPI_start_counters( Events, NUM_COUNTERS );
106  if ( retval != PAPI_OK ) {
107  test_fail( __FILE__, __LINE__, "PAPI_start_counters", retval );
108  }
109 
110  /* Test PAPI_read_counters() */
111  if ( !quiet ) printf( "Testing PAPI_read_counters... " );
112  // pass invalid 1st argument
113  retval = PAPI_read_counters( NULL, NUM_COUNTERS );
114  if ( retval != PAPI_EINVAL ) {
115  test_fail( __FILE__, __LINE__, "PAPI_read_counters", retval );
116  }
117  // pass invalid 2nd argument
118  retval = PAPI_read_counters( values, 0 );
119  if ( retval != PAPI_EINVAL ) {
120  test_fail( __FILE__, __LINE__, "PAPI_read_counters", retval );
121  }
122  // copy current counts to array and reset counters
123  retval = PAPI_read_counters( values, NUM_COUNTERS );
124  if ( retval != PAPI_OK ) {
125  test_fail( __FILE__, __LINE__, "PAPI_read_counters", retval );
126  }
127  else {
128  if ( !quiet ) printf( "read PAPI_TOT_INS counts and reset counter\n" );
129  }
130  //NOTE: There are currently no checks on whether or not counter values are correct
131 
132 
133  /* Test PAPI_accum_counters() */
134  if ( !quiet ) printf( "Testing PAPI_accum_counters... " );
135  // pass invalid 1st argument
136  retval = PAPI_accum_counters( NULL, NUM_COUNTERS );
137  if ( retval != PAPI_EINVAL ) {
138  test_fail( __FILE__, __LINE__, "PAPI_accum_counters", retval );
139  }
140  // pass invalid 2nd argument
141  retval = PAPI_accum_counters( values, 0 );
142  if ( retval != PAPI_EINVAL ) {
143  test_fail( __FILE__, __LINE__, "PAPI_accum_counters", retval );
144  }
145  // add current counts to array and reset counters
146  retval = PAPI_accum_counters( values, NUM_COUNTERS );
147  if ( retval != PAPI_OK ) {
148  test_fail( __FILE__, __LINE__, "PAPI_accum_counters", retval );
149  }
150  else {
151  if ( !quiet ) printf( "added PAPI_TOT_INS counts and reset counter\n" );
152  }
153  //NOTE: There are currently no checks on whether or not counter values are correct
154 
155 
156  // stop counting hardware events
157  retval = PAPI_stop_counters( values, NUM_COUNTERS );
158  if ( retval != PAPI_OK ) {
159  test_fail( __FILE__, __LINE__, "PAPI_stop_counters", retval );
160  }
161 
162 
163  /* Test PAPI_ipc() */
164  if ( !quiet ) printf( "Testing PAPI_ipc... " );
165  // pass invalid 1st argument
166  retval = PAPI_ipc( NULL, &ptime, &ins, &ipc );
167  if ( retval != PAPI_EINVAL ) {
168  test_fail( __FILE__, __LINE__, "PAPI_ipc", retval );
169  }
170  // pass invalid 2nd argument
171  retval = PAPI_ipc( &rtime, NULL, &ins, &ipc );
172  if ( retval != PAPI_EINVAL ) {
173  test_fail( __FILE__, __LINE__, "PAPI_ipc", retval );
174  }
175  // pass invalid 3rd argument
176  retval = PAPI_ipc( &rtime, &ptime, NULL, &ipc );
177  if ( retval != PAPI_EINVAL ) {
178  test_fail( __FILE__, __LINE__, "PAPI_ipc", retval );
179  }
180  // pass invalid 4th argument
181  retval = PAPI_ipc( &rtime, &ptime, &ins, NULL );
182  if ( retval != PAPI_EINVAL ) {
183  test_fail( __FILE__, __LINE__, "PAPI_ipc", retval );
184  }
185  // get instructions per cycle, real and processor time
186  retval = PAPI_ipc( &rtime, &ptime, &ins, &ipc );
187  if ( retval != PAPI_OK ) {
188  test_fail( __FILE__, __LINE__, "PAPI_ipc", retval );
189  }
190  else {
191  if ( !quiet ) printf( "got instructions per cycle, real and processor time\n" );
192  }
193  //NOTE: There are currently no checks on whether or not returned values are correct
194 
195 
196  //NOTE: PAPI_flips and PAPI_flops fail if any other low-level calls have been made!
197  PAPI_shutdown( );
199  if ( retval != PAPI_VER_CURRENT ) {
200  test_fail( __FILE__, __LINE__, "PAPI_library_init", retval );
201  }
202 
203  /* Test PAPI_flips() */
204  if ( !quiet ) printf( "Testing PAPI_flips... " );
205  // pass invalid 1st argument
206  retval = PAPI_flips( NULL, &ptime, &flpins, &mflips );
207  if ( retval != PAPI_EINVAL ) {
208  test_fail( __FILE__, __LINE__, "PAPI_flips", retval );
209  }
210  // pass invalid 2nd argument
211  retval = PAPI_flips( &rtime, NULL, &flpins, &mflips );
212  if ( retval != PAPI_EINVAL ) {
213  test_fail( __FILE__, __LINE__, "PAPI_flips", retval );
214  }
215  // pass invalid 3rd argument
216  retval = PAPI_flips( &rtime, &ptime, NULL, &mflips );
217  if ( retval != PAPI_EINVAL ) {
218  test_fail( __FILE__, __LINE__, "PAPI_flips", retval );
219  }
220  // pass invalid 4th argument
221  retval = PAPI_flips( &rtime, &ptime, &flpins, NULL );
222  if ( retval != PAPI_EINVAL ) {
223  test_fail( __FILE__, __LINE__, "PAPI_flips", retval );
224  }
225  // get Mflips/s, real and processor time
226  retval = PAPI_flips( &rtime, &ptime, &flpins, &mflips );
227  if ( retval == PAPI_ENOEVNT ) {
228  test_warn( __FILE__, __LINE__, "PAPI_flips", retval);
229  }
230  else if ( retval != PAPI_OK ) {
231  test_fail( __FILE__, __LINE__, "PAPI_flips", retval );
232  }
233  else {
234  if ( !quiet ) printf( "got Mflips/s, real and processor time\n" );
235  }
236  //NOTE: There are currently no checks on whether or not returned values are correct
237 
238 
239  PAPI_shutdown( );
241  if ( retval != PAPI_VER_CURRENT ) {
242  test_fail( __FILE__, __LINE__, "PAPI_library_init", retval );
243  }
244 
245  /* Test PAPI_flops() */
246  if ( !quiet ) printf( "Testing PAPI_flops... " );
247  // pass invalid 1st argument
248  retval = PAPI_flops( NULL, &ptime, &flpops, &mflops );
249  if ( retval != PAPI_EINVAL ) {
250  test_fail( __FILE__, __LINE__, "PAPI_flops", retval );
251  }
252  // pass invalid 2nd argument
253  retval = PAPI_flops( &rtime, NULL, &flpops, &mflops );
254  if ( retval != PAPI_EINVAL ) {
255  test_fail( __FILE__, __LINE__, "PAPI_flops", retval );
256  }
257  // pass invalid 3rd argument
258  retval = PAPI_flops( &rtime, &ptime, NULL, &mflops );
259  if ( retval != PAPI_EINVAL ) {
260  test_fail( __FILE__, __LINE__, "PAPI_flops", retval );
261  }
262  // pass invalid 4th argument
263  retval = PAPI_flops( &rtime, &ptime, &flpops, NULL );
264  if ( retval != PAPI_EINVAL ) {
265  test_fail( __FILE__, __LINE__, "PAPI_flops", retval );
266  }
267  // get Mflops/s, real and processor time
268  retval = PAPI_flops( &rtime, &ptime, &flpops, &mflops );
269  if ( retval == PAPI_ENOEVNT ) {
270  test_warn( __FILE__, __LINE__, "PAPI_flops", retval);
271  }
272  else if ( retval != PAPI_OK ) {
273  test_fail( __FILE__, __LINE__, "PAPI_flops", retval );
274  }
275  else if ( !quiet ) {
276  printf( "got Mflops/s, real and processor time\n" );
277  }
278  //NOTE: There are currently no checks on whether or not returned values are correct
279 
280 
281  /***************************/
282  /****** Low Level API ******/
283  /***************************/
284 /*
285  int PAPI_accum(int EventSet, long long * values); // accumulate and reset hardware events from an event set
286  int PAPI_add_event(int EventSet, int Event); // add single PAPI preset or native hardware event to an event set
287  int PAPI_add_events(int EventSet, int *Events, int number); // add array of PAPI preset or native hardware events to an event set
288  int PAPI_assign_eventset_component(int EventSet, int cidx); // assign a component index to an existing but empty eventset
289  int PAPI_attach(int EventSet, unsigned long tid); // attach specified event set to a specific process or thread id
290  int PAPI_cleanup_eventset(int EventSet); // remove all PAPI events from an event set
291  int PAPI_create_eventset(int *EventSet); // create a new empty PAPI event set
292  int PAPI_detach(int EventSet); // detach specified event set from a previously specified process or thread id
293  int PAPI_destroy_eventset(int *EventSet); // deallocates memory associated with an empty PAPI event set
294  int PAPI_enum_event(int *EventCode, int modifier); // return the event code for the next available preset or natvie event
295  int PAPI_event_code_to_name(int EventCode, char *out); // translate an integer PAPI event code into an ASCII PAPI preset or native name
296  int PAPI_event_name_to_code(char *in, int *out); // translate an ASCII PAPI preset or native name into an integer PAPI event code
297  int PAPI_get_dmem_info(PAPI_dmem_info_t *dest); // get dynamic memory usage information
298  int PAPI_get_event_info(int EventCode, PAPI_event_info_t * info); // get the name and descriptions for a given preset or native event code
299  const PAPI_exe_info_t *PAPI_get_executable_info(void); // get the executable's address space information
300  const PAPI_hw_info_t *PAPI_get_hardware_info(void); // get information about the system hardware
301  const PAPI_component_info_t *PAPI_get_component_info(int cidx); // get information about the component features
302  int PAPI_get_multiplex(int EventSet); // get the multiplexing status of specified event set
303  int PAPI_get_opt(int option, PAPI_option_t * ptr); // query the option settings of the PAPI library or a specific event set
304  int PAPI_get_cmp_opt(int option, PAPI_option_t * ptr,int cidx); // query the component specific option settings of a specific event set
305  long long PAPI_get_real_cyc(void); // return the total number of cycles since some arbitrary starting point
306  long long PAPI_get_real_nsec(void); // return the total number of nanoseconds since some arbitrary starting point
307  long long PAPI_get_real_usec(void); // return the total number of microseconds since some arbitrary starting point
308  const PAPI_shlib_info_t *PAPI_get_shared_lib_info(void); // get information about the shared libraries used by the process
309  int PAPI_get_thr_specific(int tag, void **ptr); // return a pointer to a thread specific stored data structure
310  int PAPI_get_overflow_event_index(int Eventset, long long overflow_vector, int *array, int *number); // # decomposes an overflow_vector into an event index array
311  long long PAPI_get_virt_cyc(void); // return the process cycles since some arbitrary starting point
312  long long PAPI_get_virt_nsec(void); // return the process nanoseconds since some arbitrary starting point
313  long long PAPI_get_virt_usec(void); // return the process microseconds since some arbitrary starting point
314  int PAPI_is_initialized(void); // return the initialized state of the PAPI library
315  int PAPI_library_init(int version); // initialize the PAPI library
316  int PAPI_list_events(int EventSet, int *Events, int *number); // list the events that are members of an event set
317  int PAPI_list_threads(unsigned long *tids, int *number); // list the thread ids currently known to PAPI
318  int PAPI_lock(int); // lock one of two PAPI internal user mutex variables
319  int PAPI_multiplex_init(void); // initialize multiplex support in the PAPI library
320  int PAPI_num_hwctrs(void); // return the number of hardware counters for the cpu
321  int PAPI_num_cmp_hwctrs(int cidx); // return the number of hardware counters for a specified component
322  int PAPI_num_hwctrs(void); // for backward compatibility
323  int PAPI_num_events(int EventSet); // return the number of events in an event set
324  int PAPI_overflow(int EventSet, int EventCode, int threshold,
325  int flags, PAPI_overflow_handler_t handler); // set up an event set to begin registering overflows
326  int PAPI_perror( char *msg); // convert PAPI error codes to strings
327  int PAPI_profil(void *buf, unsigned bufsiz, caddr_t offset,
328  unsigned scale, int EventSet, int EventCode,
329  int threshold, int flags); // generate PC histogram data where hardware counter overflow occurs
330  int PAPI_query_event(int EventCode); // query if a PAPI event exists
331  int PAPI_read(int EventSet, long long * values); // read hardware events from an event set with no reset
332  int PAPI_read_ts(int EventSet, long long * values, long long *cyc);
333  int PAPI_register_thread(void); // inform PAPI of the existence of a new thread
334  int PAPI_remove_event(int EventSet, int EventCode); // remove a hardware event from a PAPI event set
335  int PAPI_remove_events(int EventSet, int *Events, int number); // remove an array of hardware events from a PAPI event set
336  int PAPI_reset(int EventSet); // reset the hardware event counts in an event set
337  int PAPI_set_debug(int level); // set the current debug level for PAPI
338  int PAPI_set_cmp_domain(int domain, int cidx); // set the component specific default execution domain for new event sets
339  int PAPI_set_domain(int domain); // set the default execution domain for new event sets
340  int PAPI_set_cmp_granularity(int granularity, int cidx); // set the component specific default granularity for new event sets
341  int PAPI_set_granularity(int granularity); //set the default granularity for new event sets
342  int PAPI_set_multiplex(int EventSet); // convert a standard event set to a multiplexed event set
343  int PAPI_set_opt(int option, PAPI_option_t * ptr); // change the option settings of the PAPI library or a specific event set
344  int PAPI_set_thr_specific(int tag, void *ptr); // save a pointer as a thread specific stored data structure
345  void PAPI_shutdown(void); // finish using PAPI and free all related resources
346  int PAPI_sprofil(PAPI_sprofil_t * prof, int profcnt, int EventSet, int EventCode, int threshold, int flags); // generate hardware counter profiles from multiple code regions
347  int PAPI_start(int EventSet); // start counting hardware events in an event set
348  int PAPI_state(int EventSet, int *status); // return the counting state of an event set
349  int PAPI_stop(int EventSet, long long * values); // stop counting hardware events in an event set and return current events
350  char *PAPI_strerror(int); // return a pointer to the error message corresponding to a specified error code
351  unsigned long PAPI_thread_id(void); // get the thread identifier of the current thread
352  int PAPI_thread_init(unsigned long (*id_fn) (void)); // initialize thread support in the PAPI library
353  int PAPI_unlock(int); // unlock one of two PAPI internal user mutex variables
354  int PAPI_unregister_thread(void); // inform PAPI that a previously registered thread is disappearing
355  int PAPI_write(int EventSet, long long * values); // write counter values into counters
356 */
357 
358  test_pass( __FILE__ );
359 
360  return 0;
361 }
#define PAPI_ENOEVNT
Definition: papi.h:260
void test_pass(const char *filename)
Definition: test_utils.c:432
static int Events[NUM_EVENTS]
Definition: init_fini.c:8
int PAPI_ipc(float *rtime, float *ptime, long long *ins, float *ipc)
Definition: papi_hl.c:316
int PAPI_flops(float *rtime, float *ptime, long long *flpops, float *mflops)
Definition: papi_hl.c:259
int PAPI_accum_counters(long long *values, int array_len)
Definition: papi_hl.c:756
int PAPI_num_components(void)
Definition: papi.c:4387
#define PAPI_TOT_INS
return PAPI_OK
Definition: linux-nvml.c:497
return PAPI_EINVAL
Definition: linux-nvml.c:436
void test_warn(const char *file, int line, const char *call, int retval)
Definition: test_utils.c:522
int int argc
Definition: iozone.c:1609
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_flips(float *rtime, float *ptime, long long *flpins, float *mflips)
Definition: papi_hl.c:204
int PAPI_library_init(int version)
Definition: papi.c:500
int PAPI_stop_counters(long long *values, int array_len)
Definition: papi_hl.c:803
void PAPI_shutdown(void)
Definition: papi.c:4461
int quiet
Definition: rapl_overflow.c:18
int PAPI_get_cmp_opt(int option, PAPI_option_t *ptr, int cidx)
Definition: papi.c:4335
printf("\tTry: -i 0 -i 1 \n\n")
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_read_counters(long long *values, int array_len)
Definition: papi_hl.c:706
int PAPI_num_counters(void)
Definition: papi_hl.c:537
int PAPI_start_counters(int *events, int array_len)
Definition: papi_hl.c:593
#define PAPI_MAX_HWCTRS
Definition: papi.h:443
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

Here is the call graph for this function: