|
PAPI
5.0.1.0
|
00001 #include <stdio.h> 00002 #include <stdlib.h> 00003 #include <sys/types.h> 00004 #include <unistd.h> 00005 #include "papi.h" 00006 00007 #define NUM_EVENTS 6 00008 static int Events[NUM_EVENTS]; 00009 static const char* names[NUM_EVENTS] = {"READ_CALLS", "READ_BYTES","READ_USEC","WRITE_CALLS","WRITE_BYTES","WRITE_USEC"}; 00010 static long long values[NUM_EVENTS]; 00011 00012 __attribute__ ((constructor)) void my_init(void) { 00013 //fprintf(stderr, "appio: constructor started\n"); 00014 int version = PAPI_library_init (PAPI_VER_CURRENT); 00015 if (version != PAPI_VER_CURRENT) { 00016 fprintf(stderr, "PAPI_library_init version mismatch\n"); 00017 exit(1); 00018 } 00019 else { 00020 fprintf(stderr, "appio: PAPI library initialized\n"); 00021 } 00022 int retval; 00023 int e; 00024 for (e=0; e<NUM_EVENTS; e++) { 00025 retval = PAPI_event_name_to_code((char*)names[e], &Events[e]); 00026 if (retval != PAPI_OK) { 00027 fprintf(stderr, "Error getting code for %s\n", names[e]); 00028 exit(2); 00029 } 00030 } 00031 00032 /* Start counting events */ 00033 fprintf(stderr, "appio: starting PAPI counters; main program will follow\n"); 00034 if (PAPI_start_counters(Events, NUM_EVENTS) != PAPI_OK) { 00035 fprintf(stderr, "Error in PAPI_start_counters\n"); 00036 exit(1); 00037 } 00038 return; 00039 } 00040 00041 __attribute__ ((destructor)) void my_fini(void) { 00042 int e; 00043 //fprintf(stderr, "appio: destructor called\n"); 00044 if (PAPI_stop_counters(values, NUM_EVENTS) != PAPI_OK) { 00045 fprintf(stderr, "Error in PAPI_stop_counters\n"); 00046 } 00047 fprintf(stderr, "\nappio: PAPI counts (for pid=%6d)\n" 00048 "appio: ----------------------------\n", (int)getpid()); 00049 for (e=0; e<NUM_EVENTS; e++) 00050 fprintf(stderr, "appio: %s : %lld\n", names[e], values[e]); 00051 return; 00052 }