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

Go to the source code of this file.

Macros

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

Functions

int code_to_monitor ()
 
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 12 of file PAPI_profil.c.

#define FLOPS   1000000

Definition at line 10 of file PAPI_profil.c.

#define THRESHOLD   100000

Definition at line 11 of file PAPI_profil.c.

Function Documentation

int code_to_monitor ( )

Definition at line 14 of file PAPI_profil.c.

15 {
16  int i;
17  double tmp=1.1;
18 
19  for(i=0; i < FLOPS; i++)
20  {
21  tmp=i+tmp;
22  tmp++;
23  }
24  i = (int) tmp;
25  return i;
26 }
int i
Definition: fileop.c:140
int
Definition: iozone.c:18528
long long tmp
Definition: iozone.c:12031
#define FLOPS
Definition: PAPI_profil.c:10

Here is the caller graph for this function:

int main ( )

Definition at line 28 of file PAPI_profil.c.

29 {
30 
31  unsigned long length;
32  caddr_t start, end;
33  PAPI_sprofil_t * prof;
34  int EventSet = PAPI_NULL;
35  /*must be initialized to PAPI_NULL before calling PAPI_create_event*/
36  int PAPI_event,i,tmp = 0;
38  /*These are going to be used as buffers */
39  unsigned short *profbuf;
40  long long values[2];
41  const PAPI_exe_info_t *prginfo = NULL;
42 
43 
44  int retval;
45 
46 
47  /****************************************************************************
48  * This part initializes the library and compares the version number of the *
49  * header file, to the version of the library, if these don't match then it *
50  * is likely that PAPI won't work correctly.If there is an error, retval *
51  * keeps track of the version number. *
52  ****************************************************************************/
53 
55  {
56  printf("Library initialization error! \n");
57  exit(1);
58  }
59 
60 
61  if ((prginfo = PAPI_get_executable_info()) == NULL)
62  {
63  fprintf(stderr, "Error in get executable information \n");
64  exit(1);
65  }
66 
67  start = prginfo->address_info.text_start;
68  end = prginfo->address_info.text_end;
69  length = (end - start);
70 
71  /* for PAPI_PROFIL_BUCKET_16 and scale = 65536,
72  profile buffer length == program address length.
73  Larger bucket sizes would increase the buffer length.
74  Smaller scale factors would decrease it.
75  Handle with care...
76  */
77  profbuf = (unsigned short *)malloc(length);
78  if (profbuf == NULL)
79  {
80  fprintf(stderr, "Not enough memory \n");
81  exit(1);
82  }
83  memset(profbuf,0x00,length);
84 
85  /* Creating the eventset */
86  if ( (retval = PAPI_create_eventset(&EventSet)) != PAPI_OK)
87  ERROR_RETURN(retval);
88 
89  PAPI_event = PAPI_TOT_INS;
90  /* Add Total Instructions Executed to our EventSet */
91  if ( (retval = PAPI_add_event(EventSet, PAPI_event)) != PAPI_OK)
92  ERROR_RETURN(retval);
93 
94  /* Add Total Cycles Executed to our EventSet */
95  if ( (retval = PAPI_add_event(EventSet, PAPI_TOT_CYC)) != PAPI_OK)
96  ERROR_RETURN(retval);
97 
98  /* enable the collection of profiling information */
99  if ((retval = PAPI_profil(profbuf, length, start, 65536, EventSet,
101  ERROR_RETURN(retval);
102 
103  /* let's rock and roll */
104  if ((retval=PAPI_start(EventSet)) != PAPI_OK)
105  ERROR_RETURN(retval);
106 
107  code_to_monitor();
108 
109  if ((retval=PAPI_stop(EventSet, values)) != PAPI_OK)
110  ERROR_RETURN(retval);
111 
112  /* disable the collection of profiling information by setting threshold
113  to 0
114  */
115  if ((retval = PAPI_profil(profbuf, length, start, 65536, EventSet,
116  PAPI_event, 0, PAPI_PROFIL_POSIX)) != PAPI_OK)
117  ERROR_RETURN(retval);
118 
119  printf("-----------------------------------------------------------\n");
120  printf("Text start: %p, Text end: %p, \n",
121  prginfo->address_info.text_start,prginfo->address_info.text_end);
122  printf("Data start: %p, Data end: %p\n",
123  prginfo->address_info.data_start,prginfo->address_info.data_end);
124  printf("BSS start : %p, BSS end: %p\n",
125  prginfo->address_info.bss_start,prginfo->address_info.bss_end);
126 
127  printf("------------------------------------------\n");
128 
129  printf("Test type : \tPAPI_PROFIL_POSIX\n");
130  printf("------------------------------------------\n\n\n");
131  printf("PAPI_profil() hash table.\n");
132  printf("address\t\tflat \n");
133  for (i = 0; i < (int) length/2; i++)
134  {
135  if (profbuf[i])
136  printf("%#lx\t%d \n",
137  (unsigned long) start + (unsigned long) (2 * i), profbuf[i]);
138  }
139 
140  printf("-----------------------------------------\n");
141 
142  retval = 0;
143  for (i = 0; i < (int) length/2; i++)
144  retval = retval || (profbuf[i]);
145  if (retval)
146  printf("Test succeeds! \n");
147  else
148  printf( "No information in buffers\n");
149  /* clean up */
150  PAPI_shutdown();
151 
152  exit(0);
153 }
char event_name[2][PAPI_MAX_STR_LEN]
Definition: data_range.c:23
memset(eventId, 0, size)
int PAPI_stop(int EventSet, long long *values)
Definition: papi.c:2232
unsigned long long length
Definition: iozone.c:17106
int PAPI_event[2]
Definition: data_range.c:24
int PAPI_add_event(int EventSet, int EventCode)
Definition: papi.c:1604
#define PAPI_NULL
Definition: fpapi.h:13
caddr_t text_end
Definition: papi.h:693
#define PAPI_MAX_STR_LEN
Definition: fpapi.h:43
start
Definition: iozone.c:22736
#define THRESHOLD
Definition: PAPI_profil.c:11
#define PAPI_TOT_INS
Definition: fpapi.h:185
get the executable&#39;s info
Definition: papi.h:702
return PAPI_OK
Definition: linux-nvml.c:458
caddr_t bss_start
Definition: papi.h:696
#define PAPI_PROFIL_POSIX
Definition: fpapi.h:75
#define printf
Definition: papi_test.h:125
int code_to_monitor()
Definition: PAPI_profil.c:14
int PAPI_library_init(int version)
Definition: papi.c:495
int PAPI_profil(void *buf, unsigned bufsiz, caddr_t offset, unsigned scale, int EventSet, int EventCode, int threshold, int flags)
Definition: papi.c:5316
int i
Definition: fileop.c:140
#define PAPI_TOT_CYC
Definition: fpapi.h:194
void PAPI_shutdown(void)
Definition: papi.c:4357
const PAPI_exe_info_t * PAPI_get_executable_info(void)
Definition: papi.c:5988
caddr_t text_start
Definition: papi.h:692
PAPI_address_map_t address_info
Definition: papi.h:704
#define PAPI_PROFIL_BUCKET_16
Definition: fpapi.h:79
void * profbuf[5]
Definition: prof_utils.c:28
#define PAPI_VER_CURRENT
Definition: fpapi.h:14
int PAPI_create_eventset(int *EventSet)
Definition: papi.c:1406
#define ERROR_RETURN(retval)
Definition: PAPI_profil.c:12
caddr_t data_start
Definition: papi.h:694
int EventSet
int
Definition: iozone.c:18528
caddr_t bss_end
Definition: papi.h:697
caddr_t data_end
Definition: papi.h:695
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
long long tmp
Definition: iozone.c:12031
void exit()

Here is the call graph for this function: