Error Handling
From PAPIDocs
Jump to: navigation, search

PAPI ERROR HANDLING

ERROR CODES

All of the functions contained in the PAPI library return standardized error codes in which the values that are greater than or equal to zero indicate success and those that are less than zero indicate failure, as shown in the table below:

VALUE SYMBOL DEFINITION
0 PAPI_OK No error
-1 PAPI_EINVAL Invalid argument
-2 PAPI_ENOMEM Insufficient memory
-3 PAPI_ESYS A system or C library call failed, please check errno
-4 PAPI_ESBSTR Substrate returned an error, usually the result of an unimplemented feature
-5 PAPI_ECLOST Access to the counters was lost or interrupted
-6 PAPI_EBUG Internal error, please send mail to the developers
-7 PAPI_ENOEVNT Hardware event does not exist
-8 PAPI_ECNFLCT Hardware event exists, but cannot be counted due to counter resource limitations
-9 PAPI_ENOTRUN No events or event sets are currently not counting
-10 PAPI_EISRUN Event Set is currently running
-11 PAPI_ENOEVST No such event set available
-12 PAPI_ENOTPRESET Event is not a valid preset
-13 PAPI_ENOCNTR Hardware does not support performance counters
-14 PAPI_EMISC ‘Unknown error’ code
-15 PAPI_EPERM You lack the necessary permissions



CONVERTING ERROR CODES TO ERROR MESSAGES

Error codes can be converted to error messages by calling the following low-level functions:

C:

 
PAPI_perror(''code, destination, length'')
PAPI_strerror(''code'')

 

Fortan:

 
PAPIF_perror(''code'', ''destination'', check)

 


ARGUMENTS
 
''code'' -- the error code to interpret 
''*''''destination'' -- "the error message in quotes"  
''length'' -- either 0 or strlen(destination) 

 

PAPI_perror fills the string, destination', with the error message corresponding to the error code (code). The function copies length worth of the error description string corresponding to code into destination. The resulting string is always null terminated. If length is 0, then the string is printed to stderr.

PAPI_strerror returns a pointer to the error message corresponding to the error code (code). If the call fails, the function returns a NULL pointer. Otherwise, a non-NULL pointer is returned. Note that this function is not implemented in Fortran.

In the following code example, PAPI_perror is used to convert error codes to error messages:

 
#include <papi.h>
#include <stdio.h>

main()
{
int EventSet = PAPI_NULL;
int native = 0x0;
char error_str[PAPI_MAX_STR_LEN];
        
/* Initialize the PAPI library */
retval = PAPI_library_init(PAPI_VER_CURRENT);
 
if (retval != PAPI_VER_CURRENT && retval > 0) {
  fprintf(stderr,"PAPI library version mismatch!\n");
  exit(1);
}

if ((retval = PAPI_create_eventset(&EventSet)) != PAPI_OK) {
     fprintf(stderr, "PAPI error %d: %s\n",retval, 		PAPI_strerror(retval));
     exit(1);
}     

/* Add Total Instructions Executed to our EventSet */
if ((retval = PAPI_add_event(&EventSet, PAPI_TOT_INS)) != PAPI_OK) {
     PAPI_perror(retval,error_str,PAPI_MAX_STR_LEN);
     fprintf(stderr,"PAPI_error %d: %s\n",retval,error_str);
     exit(1);
}

/* Add POWER4 native event */
retval = PAPI_event_name_to_code(“PM_LD_MISS_L1”, &native);
if ((retval = PAPI_add_event(&EventSet, native)) != PAPI_OK) {
     /* Dump error string directly to stderr. */
      PAPI_perror(retval,NULL,NULL);
     exit(1);
}

/* Start counting */
if ((retval = PAPI_start(EventSet)) != PAPI_OK)
  handle_error(retval);
}
 



OUTPUT:
 
Invalid argument
 


Notice that the above output was generated from the last call to'PAPI_perror'.

On success, PAPI_perror returns PAPI_OK and on error, a non-zero error code is returned.