PAPI  5.3.0.0
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
PAPI_perror.c
Go to the documentation of this file.
1 /*****************************************************************************
2  * PAPI_perror converts PAPI error codes to strings,it fills the string *
3  * destination with the error message corresponding to the error code. *
4  * The function copies length worth of the error description string *
5  * corresponding to code into destination. The resulting string is always *
6  * null terminated. If length is 0, then the string is printed on stderr. *
7  * PAPI_strerror does similar but it just returns the corresponding *
8  * error string from the code. *
9  *****************************************************************************/
10 
11 #include <stdio.h>
12 #include <stdlib.h>
13 #include "papi.h" /* This needs to be included every time you use PAPI */
14 
15 
16 int main()
17 {
18 
19  int retval;
20  int EventSet = PAPI_NULL;
21  char error_str[PAPI_MAX_STR_LEN];
22 
23  /****************************************************************************
24  * This part initializes the library and compares the version number of the *
25  * header file, to the version of the library, if these don't match then it *
26  * is likely that PAPI won't work correctly.If there is an error, retval *
27  * keeps track of the version number. *
28  ****************************************************************************/
29 
31  {
32  exit(1);
33  }
34 
35  if ((retval = PAPI_create_eventset(&EventSet)) != PAPI_OK)
36  {
37  fprintf(stderr, "PAPI error %d: %s\n",retval,PAPI_strerror(retval));
38  exit(1);
39  }
40 
41  /* Add Total Instructions Executed to our EventSet */
42 
43  if ((retval = PAPI_add_event(EventSet, PAPI_TOT_INS)) != PAPI_OK)
44  {
45  PAPI_perror( "PAPI_add_event" );
46  exit(1);
47  }
48 
49  /* Start counting */
50 
51  if ((retval = PAPI_start(EventSet)) != PAPI_OK)
52  {
53  PAPI_perror( "PAPI_start" );
54  exit(1);
55  }
56 
57  /* We are trying to start the counter which has already been started,
58  and this will give an error which will be passed to PAPI_perror via
59  retval and the function will then display the error string on the
60  screen.
61  */
62 
63  if ((retval = PAPI_start(EventSet)) != PAPI_OK)
64  {
65  PAPI_perror( "PAPI_start" );
66  }
67 
68  /* The function PAPI_strerror returns the corresponding error string
69  from the error code */
70  if ((retval = PAPI_start(EventSet)) != PAPI_OK)
71  {
72  printf("%s\n",PAPI_strerror(retval));
73  }
74 
75  /* finish using PAPI and free all related resources
76  (this is optional, you don't have to use it
77  */
78  PAPI_shutdown ();
79 
80  exit(0);
81 }
int PAPI_add_event(int EventSet, int EventCode)
Definition: papi.c:1597
void PAPI_perror(char *msg)
Definition: papi.c:4520
#define PAPI_NULL
Definition: fpapi.h:13
#define PAPI_MAX_STR_LEN
Definition: fpapi.h:43
#define PAPI_TOT_INS
Definition: fpapi.h:185
return PAPI_OK
Definition: linux-nvml.c:458
#define printf
Definition: papi_test.h:125
Return codes and api definitions.
int PAPI_library_init(int version)
Definition: papi.c:495
void PAPI_shutdown(void)
Definition: papi.c:4344
#define PAPI_VER_CURRENT
Definition: fpapi.h:14
int PAPI_create_eventset(int *EventSet)
Definition: papi.c:1399
int EventSet
char * PAPI_strerror(int errorCode)
Definition: papi.c:4470
int PAPI_start(int EventSet)
Definition: papi.c:2019
ssize_t retval
Definition: libasync.c:338
int main(int argc, char **argv)
List all appio events codes and names.
void exit()