PAPI 7.1.0.0
Loading...
Searching...
No Matches
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
8static int EventSet = PAPI_NULL;
9static const char* names[NUM_EVENTS] = {"READ_CALLS", "READ_BYTES","READ_USEC","WRITE_CALLS","WRITE_BYTES","WRITE_USEC"};
10static long long values[NUM_EVENTS];
11
12__attribute__ ((constructor)) void my_init(void) {
13 //fprintf(stderr, "appio: constructor started\n");
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
23 /* Create the Event Set */
25 fprintf(stderr, "Error creating event set\n");
26 exit(2);
27 }
28
29 int retval;
30 int e;
31 int event_code;
32 for (e=0; e<NUM_EVENTS; e++) {
33 retval = PAPI_event_name_to_code((char*)names[e], &event_code);
34 if (retval != PAPI_OK) {
35 fprintf(stderr, "Error getting code for %s\n", names[e]);
36 exit(2);
37 }
38 retval = PAPI_add_event(EventSet, event_code);
39 if (retval != PAPI_OK) {
40 fprintf(stderr, "Error adding %s to event set\n", names[e]);
41 exit(2);
42 }
43 }
44
45 /* Start counting events */
46 fprintf(stderr, "appio: starting PAPI counters; main program will follow\n");
47 if (PAPI_start(EventSet) != PAPI_OK) {
48 fprintf(stderr, "Error in PAPI_start\n");
49 exit(1);
50 }
51 return;
52}
53
54__attribute__ ((destructor)) void my_fini(void) {
55 int e;
56 //fprintf(stderr, "appio: destructor called\n");
58 fprintf(stderr, "Error in PAPI_stop_counters\n");
59 }
60 fprintf(stderr, "\nappio: PAPI counts (for pid=%6d)\n"
61 "appio: ----------------------------\n", (int)getpid());
62 for (e=0; e<NUM_EVENTS; e++)
63 fprintf(stderr, "appio: %s : %lld\n", names[e], values[e]);
64 return;
65}
add PAPI preset or native hardware event to an event set
Create a new empty PAPI EventSet.
Convert a name to a numeric hardware event code.
initialize the PAPI library.
Start counting hardware events in an event set.
Stop counting hardware events in an event set.
#define PAPI_VER_CURRENT
Definition: f90papi.h:54
#define PAPI_OK
Definition: f90papi.h:73
#define PAPI_NULL
Definition: f90papi.h:78
static const char * names[NUM_EVENTS]
Definition: init_fini.c:9
static int EventSet
Definition: init_fini.c:8
static long long values[NUM_EVENTS]
Definition: init_fini.c:10
#define NUM_EVENTS
Definition: init_fini.c:7
uint8_t version
unsigned long AO_t __attribute__((__aligned__(4)))
Definition: m68k.h:21
Return codes and api definitions.
FILE * stderr
int retval
Definition: zero_fork.c:53