PAPI  5.3.2.0
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
PAPI_set_domain.c File Reference
Include dependency graph for PAPI_set_domain.c:

Go to the source code of this file.

Macros

#define ERROR_RETURN(retval)   { fprintf(stderr, "Error %d %s:line %d: \n", retval,__FILE__,__LINE__); exit(retval); }
 

Functions

int poorly_tuned_function ()
 
int main ()
 

Macro Definition Documentation

#define ERROR_RETURN (   retval)    { fprintf(stderr, "Error %d %s:line %d: \n", retval,__FILE__,__LINE__); exit(retval); }

Definition at line 13 of file PAPI_set_domain.c.

Function Documentation

int main ( )

Definition at line 27 of file PAPI_set_domain.c.

28 {
29 
30  int num, retval, EventSet = PAPI_NULL;
31  long long values[2];
33  int fd;
34 
35 
36  /****************************************************************************
37  * This part initializes the library and compares the version number of the *
38  * header file, to the version of the library, if these don't match then it *
39  * is likely that PAPI won't work correctly.If there is an error, retval *
40  * keeps track of the version number. *
41  ****************************************************************************/
42 
44  {
45  printf("Library initialization error! \n");
46  exit(1);
47  }
48 
49  /* Set the domain of this EventSet to counter user mode. The domain
50  will be valid for all the eventset created after this function call
51  unless you call PAPI_set_domain again */
52  if ((retval=PAPI_set_domain(PAPI_DOM_USER)) != PAPI_OK)
53  ERROR_RETURN(retval);
54 
55  if ((retval=PAPI_create_eventset(&EventSet)) != PAPI_OK)
56  ERROR_RETURN(retval);
57 
58  /* Add Total Instructions Executed event to the EventSet */
59  if ( (retval = PAPI_add_event(EventSet, PAPI_TOT_INS)) != PAPI_OK)
60  ERROR_RETURN(retval);
61 
62  /* Add Total Cycles Executed event to the EventSet */
63  if ( (retval = PAPI_add_event(EventSet, PAPI_TOT_CYC)) != PAPI_OK)
64  ERROR_RETURN(retval);
65 
66  /* Start counting */
67  if((retval=PAPI_start(EventSet)) != PAPI_OK)
68  ERROR_RETURN(retval);
69 
71  /* add some system calls */
72  fd = open("/dev/zero", O_RDONLY);
73  if (fd == -1)
74  {
75  perror("open(/dev/zero)");
76  exit(1);
77  }
78  close(fd);
79 
80 
81  /* Stop counting */
82  if((retval=PAPI_stop(EventSet, values)) != PAPI_OK)
83  ERROR_RETURN(retval);
84 
85  printf(" Total instructions: %lld Total Cycles: %lld \n", values[0],
86  values[1]);
87 
88  /* Set the domain of this EventSet to counter user and kernel modes */
89  if ((retval=PAPI_set_domain(PAPI_DOM_ALL)) != PAPI_OK)
90  ERROR_RETURN(retval);
91 
92  EventSet = PAPI_NULL;
93  if ((retval=PAPI_create_eventset(&EventSet)) != PAPI_OK)
94  ERROR_RETURN(retval);
95 
96  /* Add Total Instructions Executed to our EventSet */
97  if ( (retval = PAPI_add_event(EventSet, PAPI_TOT_INS)) != PAPI_OK)
98  ERROR_RETURN(retval);
99 
100  /* Add Total Instructions Executed to our EventSet */
101  if ( (retval = PAPI_add_event(EventSet, PAPI_TOT_CYC)) != PAPI_OK)
102  ERROR_RETURN(retval);
103  /* Start counting */
104  if((retval=PAPI_start(EventSet)) != PAPI_OK)
105  ERROR_RETURN(retval);
106 
108  /* add some system calls */
109  fd = open("/dev/zero", O_RDONLY);
110  if (fd == -1)
111  {
112  perror("open(/dev/zero)");
113  exit(1);
114  }
115  close(fd);
116 
117  /* Stop counting */
118  if((retval=PAPI_stop(EventSet, values)) != PAPI_OK)
119  ERROR_RETURN(retval);
120 
121  printf(" Total instructions: %lld Total Cycles: %lld \n", values[0],
122  values[1]);
123 
124  /* clean up */
125  PAPI_shutdown();
126 
127  exit(0);
128 }
int PAPI_stop(int EventSet, long long *values)
Definition: papi.c:2232
int close(int fd)
Definition: appio.c:175
int PAPI_add_event(int EventSet, int EventCode)
Definition: papi.c:1604
#define PAPI_NULL
Definition: fpapi.h:13
#define PAPI_DOM_ALL
Definition: fpapi.h:25
#define PAPI_TOT_INS
Definition: fpapi.h:185
int fd
Definition: iozone.c:1291
return PAPI_OK
Definition: linux-nvml.c:458
A pointer to the following is passed to PAPI_set/get_opt()
Definition: papi.h:843
#define printf
Definition: papi_test.h:125
#define ERROR_RETURN(retval)
int poorly_tuned_function()
Definition: PAPI_get_opt.c:14
int open(const char *pathname, int flags, mode_t mode)
Definition: appio.c:184
int PAPI_library_init(int version)
Definition: papi.c:495
#define PAPI_TOT_CYC
Definition: fpapi.h:194
void PAPI_shutdown(void)
Definition: papi.c:4357
void int num
Definition: iozone.c:22151
#define PAPI_VER_CURRENT
Definition: fpapi.h:14
int PAPI_create_eventset(int *EventSet)
Definition: papi.c:1406
int EventSet
int PAPI_set_domain(int domain)
Definition: papi.c:5565
#define PAPI_DOM_USER
Definition: fpapi.h:21
int PAPI_start(int EventSet)
Definition: papi.c:2026
static long long values[NUM_EVENTS]
Definition: init_fini.c:10
ssize_t retval
Definition: libasync.c:338
static options_t options
void exit()

Here is the call graph for this function:

int poorly_tuned_function ( )

Definition at line 15 of file PAPI_set_domain.c.

16 {
17  float tmp;
18  int i;
19 
20  for(i=1; i<2000; i++)
21  {
22  tmp=(tmp+100)/i;
23  }
24  return 0;
25 }
int i
Definition: fileop.c:140
long long tmp
Definition: iozone.c:12031