PAPI  5.3.0.0
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
profile.c
Go to the documentation of this file.
1 /*
2 * File: profile.c
3 * CVS: $Id$
4 * Author: Philip Mucci
5 * mucci@cs.utk.edu
6 * Mods: Dan Terpstra
7 * terpstra@cs.utk.edu
8 * Mods: Maynard Johnson
9 * maynardj@us.ibm.com
10 * Mods: <your name here>
11 * <your email address>
12 */
13 
14 /* This file performs the following test: profiling and program info option call
15 
16  - This tests the SVR4 profiling interface of PAPI. These are counted
17  in the default counting domain and default granularity, depending on
18  the platform. Usually this is the user domain (PAPI_DOM_USER) and
19  thread context (PAPI_GRN_THR).
20 
21  The Eventset contains:
22  + PAPI_FP_INS (to profile)
23  + PAPI_TOT_CYC
24 
25  - Set up profile
26  - Start eventset 1
27  - Do both (flops and reads)
28  - Stop eventset 1
29 */
30 
31 #include "papi_test.h"
32 #include "prof_utils.h"
33 #define PROFILE_ALL
34 
35 static int do_profile( caddr_t start, unsigned long plength, unsigned scale,
36  int thresh, int bucket );
37 
38 int
39 main( int argc, char **argv )
40 {
41  int num_tests = 6;
42  long length;
43  int mask;
44  int retval;
45  int mythreshold = THRESHOLD;
46  const PAPI_exe_info_t *prginfo;
47  caddr_t start, end;
48 
49  prof_init( argc, argv, &prginfo );
50  mask = prof_events( num_tests );
51 
52 #ifdef PROFILE_ALL
53 /* use these lines to profile entire code address space */
54  start = prginfo->address_info.text_start;
55  end = prginfo->address_info.text_end;
56 #else
57 /* use these lines to profile only do_flops address space */
58  start = ( caddr_t ) do_flops;
59  end = ( caddr_t ) fdo_flops;
60 /* Itanium and ppc64 processors return function descriptors instead of function addresses.
61  You must dereference the descriptor to get the address.
62 */
63 #if defined(ITANIUM1) || defined(ITANIUM2) || defined(__powerpc64__)
64  start = ( caddr_t ) ( ( ( struct fdesc * ) start )->ip );
65  end = ( caddr_t ) ( ( ( struct fdesc * ) end )->ip );
66 #endif
67 #endif
68 
69 #if defined(linux)
70  {
71  char *tmp = getenv( "THRESHOLD" );
72  if ( tmp )
73  mythreshold = atoi( tmp );
74  }
75 #endif
76 
77  length = end - start;
78  if ( length < 0 )
79  test_fail( __FILE__, __LINE__, "Profile length < 0!", ( int ) length );
80 
82  ( "Test case profile: POSIX compatible profiling with hardware counters.\n",
83  prginfo );
84  prof_print_prof_info( start, end, mythreshold, event_name );
85  retval =
86  do_profile( start, ( unsigned long ) length, FULL_SCALE, mythreshold,
88  if ( retval == PAPI_OK )
89  retval =
90  do_profile( start, ( unsigned long ) length, FULL_SCALE,
91  mythreshold, PAPI_PROFIL_BUCKET_32 );
92  if ( retval == PAPI_OK )
93  retval =
94  do_profile( start, ( unsigned long ) length, FULL_SCALE,
95  mythreshold, PAPI_PROFIL_BUCKET_64 );
96 
97  remove_test_events( &EventSet, mask );
98  test_pass( __FILE__, values, num_tests );
99  exit( 1 );
100 }
101 
102 static int
103 do_profile( caddr_t start, unsigned long plength, unsigned scale, int thresh,
104  int bucket )
105 {
106  int i, retval;
107  unsigned long blength;
108  int num_buckets;
109 
110  char *profstr[5] = { "PAPI_PROFIL_POSIX",
111  "PAPI_PROFIL_RANDOM",
112  "PAPI_PROFIL_WEIGHTED",
113  "PAPI_PROFIL_COMPRESS",
114  "PAPI_PROFIL_<all>"
115  };
116 
117  int profflags[5] = { PAPI_PROFIL_POSIX,
123  };
124 
125  do_no_profile( );
126  blength = prof_size( plength, scale, bucket, &num_buckets );
127  prof_alloc( 5, blength );
128 
129  for ( i = 0; i < 5; i++ ) {
130  if ( !TESTS_QUIET )
131  printf( "Test type : \t%s\n", profstr[i] );
132 
133 #ifndef SWPROFILE
134  if ( ( retval =
135  PAPI_profil( profbuf[i], ( unsigned int ) blength, start, scale,
136  EventSet, PAPI_event, thresh,
137  profflags[i] | bucket ) ) != PAPI_OK ) {
138  if (retval==PAPI_ENOSUPP) {
139  char warning[BUFSIZ];
140 
141  sprintf(warning,"PAPI_profil %s not supported",
142  profstr[i]);
143  test_warn( __FILE__, __LINE__, warning, 1 );
144  }
145  else {
146  test_fail( __FILE__, __LINE__, "PAPI_profil", retval );
147  }
148  }
149 #else
150  if ( ( retval =
151  PAPI_profil( profbuf[i], ( unsigned int ) blength, start, scale,
152  EventSet, PAPI_event, thresh,
153  profflags[i] | bucket | PAPI_PROFIL_FORCE_SW ) ) !=
154  PAPI_OK ) {
155  test_fail( __FILE__, __LINE__, "PAPI_profil", retval );
156  }
157 #endif
158 
159  if ( retval != PAPI_OK )
160  break;
161 
162  if ( ( retval = PAPI_start( EventSet ) ) != PAPI_OK )
163  test_fail( __FILE__, __LINE__, "PAPI_start", retval );
164 
165  do_flops( getenv( "NUM_FLOPS" ) ? atoi( getenv( "NUM_FLOPS" ) ) :
166  NUM_FLOPS );
167 
168  if ( ( retval = PAPI_stop( EventSet, values[1] ) ) != PAPI_OK )
169  test_fail( __FILE__, __LINE__, "PAPI_stop", retval );
170 
171  if ( !TESTS_QUIET ) {
172  printf( TAB1, event_name, ( values[1] )[0] );
173  printf( TAB1, "PAPI_TOT_CYC", ( values[1] )[1] );
174  }
175  if ( ( retval =
176  PAPI_profil( profbuf[i], ( unsigned int ) blength, start, scale,
177  EventSet, PAPI_event, 0,
178  profflags[i] ) ) != PAPI_OK )
179  test_fail( __FILE__, __LINE__, "PAPI_profil", retval );
180  }
181 
182  if ( retval == PAPI_OK ) {
183  prof_head( blength, bucket, num_buckets,
184  "address\t\t\tflat\trandom\tweight\tcomprs\tall\n" );
185  prof_out( start, 5, bucket, num_buckets, scale );
186  retval = prof_check( 5, bucket, num_buckets );
187  }
188 
189  for ( i = 0; i < 5; i++ ) {
190  free( profbuf[i] );
191  }
192 
193  return ( retval );
194 }
char event_name[2][PAPI_MAX_STR_LEN]
Definition: data_range.c:23
#define PAPI_PROFIL_WEIGHTED
Definition: fpapi.h:77
sprintf(splash[splash_line++],"\tIozone: Performance Test of File I/O\n")
int atoi()
int PAPI_stop(int EventSet, long long *values)
Definition: papi.c:2225
#define NUM_FLOPS
unsigned long long length
Definition: iozone.c:17106
int PAPI_event[2]
Definition: data_range.c:24
void prof_print_address(char *title, const PAPI_exe_info_t *prginfo)
Definition: prof_utils.c:82
char * getenv()
void prof_head(unsigned long blength, int bucket, int num_buckets, char *header)
Definition: prof_utils.c:194
struct in_addr * ip
Definition: iozone.c:20416
caddr_t text_end
Definition: papi.h:693
start
Definition: iozone.c:22736
#define TAB1
Definition: papi_test.h:112
get the executable&#39;s info
Definition: papi.h:702
#define PAPI_PROFIL_RANDOM
Definition: fpapi.h:76
return PAPI_OK
Definition: linux-nvml.c:458
#define PAPI_PROFIL_COMPRESS
Definition: fpapi.h:78
#define PAPI_PROFIL_POSIX
Definition: fpapi.h:75
#define printf
Definition: papi_test.h:125
test_pass(__FILE__, NULL, 0)
int int argc
Definition: iozone.c:1609
static int do_profile(caddr_t start, unsigned long plength, unsigned scale, int thresh, int bucket)
Definition: profile.c:103
int TESTS_QUIET
Definition: test_utils.c:11
char ** argv
Definition: iozone.c:1610
void do_no_profile(void)
Definition: prof_utils.c:126
unsigned long prof_size(unsigned long plength, unsigned scale, int bucket, int *num_buckets)
Definition: prof_utils.c:321
test_fail(__FILE__, __LINE__,"PAPI_library_init", retval)
int PAPI_profil(void *buf, unsigned bufsiz, caddr_t offset, unsigned scale, int EventSet, int EventCode, int threshold, int flags)
Definition: papi.c:5303
int i
Definition: fileop.c:140
void test_warn(char *file, int line, char *call, int retval)
Definition: test_utils.c:578
#define PAPI_ENOSUPP
Definition: fpapi.h:123
void prof_out(caddr_t start, int n, int bucket, int num_buckets, unsigned int scale)
Definition: prof_utils.c:213
#define FULL_SCALE
Definition: prof_utils.h:23
free(dummyfile[xx])
caddr_t text_start
Definition: papi.h:692
PAPI_address_map_t address_info
Definition: papi.h:704
#define PAPI_PROFIL_BUCKET_64
Definition: fpapi.h:81
#define PAPI_PROFIL_BUCKET_16
Definition: fpapi.h:79
void * profbuf[5]
Definition: prof_utils.c:28
int num_tests
Definition: zero_fork.c:46
void do_flops(int n)
Definition: multiplex.c:23
int EventSet
void prof_init(int argc, char **argv, const PAPI_exe_info_t **prginfo)
Definition: prof_utils.c:39
void prof_print_prof_info(caddr_t start, caddr_t end, int threshold, char *event_name)
Definition: prof_utils.c:106
int prof_check(int n, int bucket, int num_buckets)
Definition: prof_utils.c:283
#define PAPI_PROFIL_FORCE_SW
Definition: papi.h:401
int prof_events(int num_tests)
Definition: prof_utils.c:59
#define PAPI_PROFIL_BUCKET_32
Definition: fpapi.h:80
long long mythreshold
int PAPI_start(int EventSet)
Definition: papi.c:2019
#define THRESHOLD
Definition: earprofile.c:31
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 fdo_flops(int *n)
Definition: do_loops.c:83
int main(int argc, char **argv)
List all appio events codes and names.
void exit()
int remove_test_events(int *EventSet, int mask)
Definition: test_utils.c:277
void prof_alloc(int num, unsigned long blength)
Definition: prof_utils.c:151