Papi_add_env_event.c File Reference

Include dependency graph for Papi_add_env_event.c:

Go to the source code of this file.

Functions

int PAPI_add_env_event (int *EventSet, int *Event, char *env_variable)
int main ()

Function Documentation

int main (  ) 

Definition at line 41 of file Papi_add_env_event.c.

00041           {
00042   int retval,i;
00043   int EventSet=PAPI_NULL;
00044   int event_code=PAPI_TOT_INS; /* By default monitor total instructions */
00045   char errstring[PAPI_MAX_STR_LEN];
00046   char event_name[PAPI_MAX_STR_LEN];
00047   float a[1000],b[1000],c[1000];
00048   long long values;
00049 
00050 
00051   /* This initializes the library and checks the version number of the
00052    * header file, to the version of the library, if these don't match
00053    * then it is likely that PAPI won't work correctly.  
00054    */
00055   if ((retval = PAPI_library_init(PAPI_VER_CURRENT)) != PAPI_VER_CURRENT ){
00056     /* This call loads up what the error means into errstring 
00057      * if retval == PAPI_ESYS then it might be beneficial
00058      * to call perror as well to see what system call failed
00059      */
00060     PAPI_perror("PAPI_library_init");
00061     exit(-1);
00062   }
00063   /* Create space for the EventSet */
00064   if ( (retval=PAPI_create_eventset( &EventSet ))!=PAPI_OK){
00065     PAPI_perror(retval, errstring, PAPI_MAX_STR_LEN);
00066         exit(-1);
00067   }
00068 
00069   /*  After this call if the environment variable PAPI_EVENT is set,
00070    *  event_code may contain something different than total instructions.
00071    */
00072   if ( (retval=PAPI_add_env_event(&EventSet, &event_code, "PAPI_EVENT"))!=PAPI_OK){
00073         PAPI_perror("PAPI_add_env_event");
00074         exit(-1);
00075   }
00076   /* Now lets start counting */
00077   if ( (retval = PAPI_start(EventSet)) != PAPI_OK ){
00078         PAPI_perror("PAPI_start");
00079         exit(-1);
00080   }
00081 
00082   /* Some work to take up some time, the PAPI_start/PAPI_stop (and/or
00083    * PAPI_read) should surround what you want to monitor.
00084    */
00085   for ( i=0;i<1000;i++){
00086         a[i] = b[i]-c[i];
00087         c[i] = a[i]*1.2;
00088   }
00089 
00090   if ( (retval = PAPI_stop(EventSet, &values) ) != PAPI_OK ){
00091         PAPI_perror("PAPI_stop");
00092         exit(-1);
00093   }
00094 
00095   if ( (retval=PAPI_event_code_to_name( event_code, event_name))!=PAPI_OK){
00096         PAPI_perror("PAPI_event_code_to_name");   
00097         exit(-1);
00098   }
00099 
00100   printf("Ending values for %s: %lld\n", event_name,values);
00101   /* Remove PAPI instrumentation, this is necessary on platforms
00102    * that need to release shared memory segments and is always
00103    * good practice.
00104    */
00105   PAPI_shutdown();
00106   exit(0);
00107 }

Here is the call graph for this function:

int PAPI_add_env_event ( int *  EventSet,
int *  Event,
char *  env_variable 
)

Definition at line 111 of file Papi_add_env_event.c.

00111                                                                          {
00112   int real_event=*EventCode;
00113   char *eventname;
00114   int retval;
00115  
00116   if ( env_variable != NULL ){
00117     if ( (eventname=getenv(env_variable)) ) {
00118         if ( eventname[0] == 'P' ) {  /* Use the PAPI name */
00119            retval=PAPI_event_name_to_code(eventname, &real_event );
00120            if ( retval != PAPI_OK ) real_event = *EventCode;
00121         }
00122         else{
00123            if ( strlen(eventname)>1 && eventname[1]=='x')
00124                 sscanf(eventname, "%#x", &real_event);
00125            else
00126                real_event = atoi(eventname);
00127         }
00128     }
00129   }
00130   if ( (retval = PAPI_add_event( *EventSet, real_event))!= PAPI_OK ){
00131         if ( real_event != *EventCode ) {
00132                 if ( (retval = PAPI_add_event( *EventSet, *EventCode)) == PAPI_OK
00133 ){
00134                         real_event = *EventCode;
00135                 }
00136         }
00137   }
00138   *EventCode = real_event;
00139   return retval;
00140 }

Here is the call graph for this function:

Here is the caller graph for this function:


Generated on 8 Sep 2016 for PAPI by  doxygen 1.6.1