PAPI  5.3.0.0
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
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.

41  {
42  int retval,i;
43  int EventSet=PAPI_NULL;
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 */
64  if ( (retval=PAPI_create_eventset( &EventSet ))!=PAPI_OK){
65  PAPI_perror(retval, errstring, PAPI_MAX_STR_LEN);
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  */
105  PAPI_shutdown();
106  exit(0);
107 }
char event_name[2][PAPI_MAX_STR_LEN]
Definition: data_range.c:23
int PAPI_stop(int EventSet, long long *values)
Definition: papi.c:2225
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
int PAPI_add_env_event(int *EventSet, int *Event, char *env_variable)
#define printf
Definition: papi_test.h:125
double c
Definition: multiplex.c:22
static double a[MATRIX_SIZE][MATRIX_SIZE]
Definition: rapl_basic.c:37
int PAPI_library_init(int version)
Definition: papi.c:495
int i
Definition: fileop.c:140
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 PAPI_event_code_to_name(int EventCode, char *out)
Definition: papi.c:920
int EventSet
static double b[MATRIX_SIZE][MATRIX_SIZE]
Definition: rapl_basic.c:38
int PAPI_start(int EventSet)
Definition: papi.c:2019
static long long values[NUM_EVENTS]
Definition: init_fini.c:10
ssize_t retval
Definition: libasync.c:338
void exit()

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.

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 */
119  retval=PAPI_event_name_to_code(eventname, &real_event );
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 }
int atoi()
char * getenv()
int PAPI_add_event(int EventSet, int EventCode)
Definition: papi.c:1597
return PAPI_OK
Definition: linux-nvml.c:458
int PAPI_event_name_to_code(char *in, int *out)
Definition: papi.c:1003
int EventSet
sscanf(mnc->m_child_port,"%d",&mc.m_child_port)
ssize_t retval
Definition: libasync.c:338

Here is the call graph for this function:

Here is the caller graph for this function: