PAPI  5.3.2.0
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
init_fini.c
Go to the documentation of this file.
1 #include <stdio.h>
2 #include <stdlib.h>
3 #include <sys/types.h>
4 #include <unistd.h>
5 #include "papi.h"
6 
7 #define NUM_EVENTS 6
8 static int Events[NUM_EVENTS];
9 static const char* names[NUM_EVENTS] = {"READ_CALLS", "READ_BYTES","READ_USEC","WRITE_CALLS","WRITE_BYTES","WRITE_USEC"};
10 static long long values[NUM_EVENTS];
11 
12 __attribute__ ((constructor)) void my_init(void) {
13  //fprintf(stderr, "appio: constructor started\n");
15  if (version != PAPI_VER_CURRENT) {
16  fprintf(stderr, "PAPI_library_init version mismatch\n");
17  exit(1);
18  }
19  else {
20  fprintf(stderr, "appio: PAPI library initialized\n");
21  }
22  int retval;
23  int e;
24  for (e=0; e<NUM_EVENTS; e++) {
25  retval = PAPI_event_name_to_code((char*)names[e], &Events[e]);
26  if (retval != PAPI_OK) {
27  fprintf(stderr, "Error getting code for %s\n", names[e]);
28  exit(2);
29  }
30  }
31 
32  /* Start counting events */
33  fprintf(stderr, "appio: starting PAPI counters; main program will follow\n");
34  if (PAPI_start_counters(Events, NUM_EVENTS) != PAPI_OK) {
35  fprintf(stderr, "Error in PAPI_start_counters\n");
36  exit(1);
37  }
38  return;
39 }
40 
41 __attribute__ ((destructor)) void my_fini(void) {
42  int e;
43  //fprintf(stderr, "appio: destructor called\n");
45  fprintf(stderr, "Error in PAPI_stop_counters\n");
46  }
47  fprintf(stderr, "\nappio: PAPI counts (for pid=%6d)\n"
48  "appio: ----------------------------\n", (int)getpid());
49  for (e=0; e<NUM_EVENTS; e++)
50  fprintf(stderr, "appio: %s : %lld\n", names[e], values[e]);
51  return;
52 }
static int Events[NUM_EVENTS]
Definition: init_fini.c:8
return PAPI_OK
Definition: linux-nvml.c:458
void
Definition: iozone.c:18627
Return codes and api definitions.
int PAPI_library_init(int version)
Definition: papi.c:495
int PAPI_stop_counters(long long *values, int array_len)
Definition: papi_hl.c:803
__attribute__((constructor))
Definition: init_fini.c:12
#define PAPI_VER_CURRENT
Definition: fpapi.h:14
char version[]
Definition: fileop.c:134
int PAPI_event_name_to_code(char *in, int *out)
Definition: papi.c:1008
int PAPI_start_counters(int *events, int array_len)
Definition: papi_hl.c:593
static long long values[NUM_EVENTS]
Definition: init_fini.c:10
ssize_t retval
Definition: libasync.c:338
const char * names[NUM_EVENTS]
void exit()
#define NUM_EVENTS
Definition: init_fini.c:7