PAPI_overflow.c File Reference

Include dependency graph for PAPI_overflow.c:

Go to the source code of this file.

Defines

#define OVER_FMT   "handler(%d ) Overflow at %p! bit=%#llx \n"
#define THRESHOLD   100000
#define ERROR_RETURN(retval)   { fprintf(stderr, "Error %d %s:line %d: \n", retval,__FILE__,__LINE__); exit(retval); }

Functions

void handler (int EventSet, void *address, long long overflow_vector, void *context)
int main ()

Variables

int total = 0

Define Documentation

#define ERROR_RETURN ( retval   )     { fprintf(stderr, "Error %d %s:line %d: \n", retval,__FILE__,__LINE__); exit(retval); }

Definition at line 13 of file PAPI_overflow.c.

#define OVER_FMT   "handler(%d ) Overflow at %p! bit=%#llx \n"

Definition at line 11 of file PAPI_overflow.c.

#define THRESHOLD   100000

Definition at line 12 of file PAPI_overflow.c.


Function Documentation

void handler ( int  EventSet,
void *  address,
long long  overflow_vector,
void *  context 
)

Definition at line 19 of file PAPI_overflow.c.

00020 {
00021    fprintf(stderr, OVER_FMT, EventSet, address, overflow_vector);
00022    total++;
00023 }

int main (  ) 

Definition at line 26 of file PAPI_overflow.c.

00027 {
00028    int EventSet = PAPI_NULL;    
00029    /* must be set to null before calling PAPI_create_eventset */
00030 
00031    char errstring[PAPI_MAX_STR_LEN];
00032    long long (values[2])[2];
00033    int retval, i;
00034    double tmp = 0;
00035    int PAPI_event;      /* a place holder for an event preset */
00036    char event_name[PAPI_MAX_STR_LEN];
00037 
00038 
00039    /****************************************************************************
00040    *  This part initializes the library and compares the version number of the *
00041    * header file, to the version of the library, if these don't match then it  *
00042    * is likely that PAPI won't work correctly.If there is an error, retval     *
00043    * keeps track of the version number.                                        *
00044    ****************************************************************************/
00045 
00046    if ((retval = PAPI_library_init (PAPI_VER_CURRENT)) != PAPI_VER_CURRENT)
00047    {
00048       printf("Library initialization error! \n");
00049       exit(1);
00050    }
00051 
00052    /* Here we create the eventset */
00053    if ((retval=PAPI_create_eventset (&EventSet)) != PAPI_OK)
00054       ERROR_RETURN(retval);
00055 
00056    PAPI_event = PAPI_TOT_INS;
00057 
00058    /* Here we are querying for the existence of the PAPI presets  */
00059    if (PAPI_query_event (PAPI_TOT_INS) != PAPI_OK)
00060    {
00061       PAPI_event = PAPI_TOT_CYC;
00062 
00063       if ((retval=PAPI_query_event (PAPI_TOT_INS)) != PAPI_OK)
00064          ERROR_RETURN(retval);
00065 
00066       printf ("PAPI_TOT_INS not available on this platform.");
00067       printf (" so subst PAPI_event with PAPI_TOT_CYC !\n\n");
00068 
00069    }
00070 
00071 
00072    /* PAPI_event_code_to_name is used to convert a PAPI preset from 
00073      its integer value to its string name. */
00074    if ((retval = PAPI_event_code_to_name (PAPI_event, event_name)) != PAPI_OK)
00075       ERROR_RETURN(retval);
00076 
00077    /* add event to the event set */
00078    if ((retval = PAPI_add_event (EventSet, PAPI_event)) != PAPI_OK)
00079       ERROR_RETURN(retval);
00080 
00081    /* register overflow and set up threshold */
00082    /* The threshold "THRESHOLD" was set to 100000 */
00083    if ((retval = PAPI_overflow (EventSet, PAPI_event, THRESHOLD, 0,
00084                                handler)) != PAPI_OK)
00085       ERROR_RETURN(retval);
00086 
00087    printf ("Here are the addresses at which overflows occured and overflow vectors \n");
00088   printf ("--------------------------------------------------------------\n");
00089 
00090 
00091   /* Start counting */
00092 
00093    if ( (retval=PAPI_start (EventSet)) != PAPI_OK)
00094       ERROR_RETURN(retval);
00095 
00096    for (i = 0; i < 2000000; i++)
00097    {
00098       tmp = 1.01 + tmp;
00099       tmp++;
00100    }
00101 
00102    /* Stops the counters and reads the counter values into the values array */
00103    if ( (retval=PAPI_stop (EventSet, values[0])) != PAPI_OK)
00104       ERROR_RETURN(retval);
00105 
00106 
00107    printf ("The total no of overflows was %d\n", total);
00108 
00109    /* clear the overflow status */
00110    if ((retval = PAPI_overflow (EventSet, PAPI_event, 0, 0,
00111                                handler)) != PAPI_OK)
00112       ERROR_RETURN(retval);
00113 
00114    /************************************************************************
00115     * PAPI_cleanup_eventset can only be used after the counter has been    *
00116     * stopped then it remove all events in the eventset                    *
00117     ************************************************************************/
00118    if ( (retval=PAPI_cleanup_eventset (EventSet)) != PAPI_OK)
00119       ERROR_RETURN(retval);
00120 
00121    /* Free all memory and data structures, EventSet must be empty. */
00122    if ( (retval=PAPI_destroy_eventset(&EventSet)) != PAPI_OK)
00123       ERROR_RETURN(retval);
00124 
00125    /* free the resources used by PAPI */ 
00126    PAPI_shutdown();
00127 
00128    exit(0);
00129 }

Here is the call graph for this function:


Variable Documentation

int total = 0

Definition at line 15 of file PAPI_overflow.c.


Generated on 17 Nov 2016 for PAPI by  doxygen 1.6.1