PAPI 7.1.0.0
Loading...
Searching...
No Matches
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

◆ main()

int main ( )

Definition at line 41 of file Papi_add_env_event.c.

41 {
42 int retval,i;
44 int event_code=PAPI_TOT_INS; /* By default monitor total instructions */
45 char errstring[PAPI_MAX_STR_LEN];
47 float a[1000],b[1000],c[1000];
48 long long values;
49
50
51 /* This initializes the library and checks the version number of the
52 * header file, to the version of the library, if these don't match
53 * then it is likely that PAPI won't work correctly.
54 */
56 /* This call loads up what the error means into errstring
57 * if retval == PAPI_ESYS then it might be beneficial
58 * to call perror as well to see what system call failed
59 */
60 PAPI_perror("PAPI_library_init");
61 exit(-1);
62 }
63 /* Create space for the EventSet */
66 exit(-1);
67 }
68
69 /* After this call if the environment variable PAPI_EVENT is set,
70 * event_code may contain something different than total instructions.
71 */
72 if ( (retval=PAPI_add_env_event(&EventSet, &event_code, "PAPI_EVENT"))!=PAPI_OK){
73 PAPI_perror("PAPI_add_env_event");
74 exit(-1);
75 }
76 /* Now lets start counting */
77 if ( (retval = PAPI_start(EventSet)) != PAPI_OK ){
78 PAPI_perror("PAPI_start");
79 exit(-1);
80 }
81
82 /* Some work to take up some time, the PAPI_start/PAPI_stop (and/or
83 * PAPI_read) should surround what you want to monitor.
84 */
85 for ( i=0;i<1000;i++){
86 a[i] = b[i]-c[i];
87 c[i] = a[i]*1.2;
88 }
89
90 if ( (retval = PAPI_stop(EventSet, &values) ) != PAPI_OK ){
91 PAPI_perror("PAPI_stop");
92 exit(-1);
93 }
94
95 if ( (retval=PAPI_event_code_to_name( event_code, event_name))!=PAPI_OK){
96 PAPI_perror("PAPI_event_code_to_name");
97 exit(-1);
98 }
99
100 printf("Ending values for %s: %lld\n", event_name,values);
101 /* Remove PAPI instrumentation, this is necessary on platforms
102 * that need to release shared memory segments and is always
103 * good practice.
104 */
106 exit(0);
107}
int i
int PAPI_add_env_event(int *EventSet, int *Event, char *env_variable)
Create a new empty PAPI EventSet.
Convert a numeric hardware event code to a name.
initialize the PAPI library.
Produces a string on standard error, describing the last library error.
Finish using PAPI and free all related resources.
Start counting hardware events in an event set.
Stop counting hardware events in an event set.
char event_name[2][PAPI_MAX_STR_LEN]
Definition: data_range.c:29
#define PAPI_VER_CURRENT
Definition: f90papi.h:54
#define PAPI_OK
Definition: f90papi.h:73
#define PAPI_NULL
Definition: f90papi.h:78
#define PAPI_MAX_STR_LEN
Definition: f90papi.h:77
#define PAPI_TOT_INS
Definition: f90papi.h:317
static int EventSet
Definition: init_fini.c:8
static long long values[NUM_EVENTS]
Definition: init_fini.c:10
static double a[MATRIX_SIZE][MATRIX_SIZE]
Definition: libmsr_basic.c:38
static double b[MATRIX_SIZE][MATRIX_SIZE]
Definition: libmsr_basic.c:39
static double c[MATRIX_SIZE][MATRIX_SIZE]
Definition: libmsr_basic.c:40
int retval
Definition: zero_fork.c:53
Here is the call graph for this function:

◆ PAPI_add_env_event()

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

Definition at line 111 of file Papi_add_env_event.c.

111 {
112 int real_event=*EventCode;
113 char *eventname;
114 int retval;
115
116 if ( env_variable != NULL ){
117 if ( (eventname=getenv(env_variable)) ) {
118 if ( eventname[0] == 'P' ) { /* Use the PAPI name */
120 if ( retval != PAPI_OK ) real_event = *EventCode;
121 }
122 else{
123 if ( strlen(eventname)>1 && eventname[1]=='x')
124 sscanf(eventname, "%#x", &real_event);
125 else
126 real_event = atoi(eventname);
127 }
128 }
129 }
130 if ( (retval = PAPI_add_event( *EventSet, real_event))!= PAPI_OK ){
131 if ( real_event != *EventCode ) {
132 if ( (retval = PAPI_add_event( *EventSet, *EventCode)) == PAPI_OK
133){
134 real_event = *EventCode;
135 }
136 }
137 }
138 *EventCode = real_event;
139 return retval;
140}
add PAPI preset or native hardware event to an event set
Convert a name to a numeric hardware event code.
char * eventname
Here is the caller graph for this function: