PAPI  5.6.0.0
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
earprofile.c
Go to the documentation of this file.
1 /*
2 * File: profile.c
3 * Author: Philip Mucci
4 * mucci@cs.utk.edu
5 * Mods: Dan Terpstra
6 * terpstra@cs.utk.edu
7 */
8 
9 /* This file performs the following test: profiling and program info option call
10 
11  - This tests the SVR4 profiling interface of PAPI. These are counted
12  in the default counting domain and default granularity, depending on
13  the platform. Usually this is the user domain (PAPI_DOM_USER) and
14  thread context (PAPI_GRN_THR).
15 
16  The Eventset contains:
17  + PAPI_FP_INS (to profile)
18  + PAPI_TOT_CYC
19 
20  - Set up profile
21  - Start eventset 1
22  - Do both (flops and reads)
23  - Stop eventset 1
24 */
25 
26 #include <stdio.h>
27 #include <stdlib.h>
28 #include <string.h>
29 
30 #include "papi.h"
31 #include "papi_test.h"
32 #include "prof_utils.h"
33 
34 #include "do_loops.h"
35 
36 #undef THRESHOLD
37 #define THRESHOLD 1000
38 
39 static void
41 {
42  int retval;
43 
44  if ( ( retval = PAPI_start( EventSet ) ) != PAPI_OK )
45  test_fail( __FILE__, __LINE__, "PAPI_start", retval );
46 
47  do_l1misses( 10000 );
48 
49  if ( ( retval = PAPI_stop( EventSet, values[0] ) ) != PAPI_OK )
50  test_fail( __FILE__, __LINE__, "PAPI_stop", retval );
51 
52  printf( "Test type : \tNo profiling\n" );
53  printf( TAB1, event_name, ( values[0] )[0] );
54  printf( TAB1, "PAPI_TOT_CYC:", ( values[0] )[1] );
55 }
56 
57 static int
58 do_profile( caddr_t start, unsigned long plength, unsigned scale, int thresh,
59  int bucket )
60 {
61  int i, retval;
62  unsigned long blength;
63  int num_buckets;
64  const char *profstr[2] = { "PAPI_PROFIL_POSIX", "PAPI_PROFIL_INST_EAR" };
65  int profflags[2] =
67  int num_profs;
68 
69  do_stuff( );
70 
71  num_profs = sizeof ( profflags ) / sizeof ( int );
72  ear_no_profile( );
73  blength = prof_size( plength, scale, bucket, &num_buckets );
74  prof_alloc( num_profs, blength );
75 
76  for ( i = 0; i < num_profs; i++ ) {
77  if ( !TESTS_QUIET )
78  printf( "Test type : \t%s\n", profstr[i] );
79 
80  if ( ( retval = PAPI_profil( profbuf[i], blength, start, scale,
81  EventSet, PAPI_event, thresh,
82  profflags[i] | bucket ) ) != PAPI_OK ) {
83  test_fail( __FILE__, __LINE__, "PAPI_profil", retval );
84  }
85  if ( ( retval = PAPI_start( EventSet ) ) != PAPI_OK )
86  test_fail( __FILE__, __LINE__, "PAPI_start", retval );
87 
88  do_stuff( );
89 
90  if ( ( retval = PAPI_stop( EventSet, values[1] ) ) != PAPI_OK )
91  test_fail( __FILE__, __LINE__, "PAPI_stop", retval );
92 
93  if ( !TESTS_QUIET ) {
94  printf( TAB1, event_name, ( values[1] )[0] );
95  printf( TAB1, "PAPI_TOT_CYC:", ( values[1] )[1] );
96  }
97  if ( ( retval = PAPI_profil( profbuf[i], blength, start, scale,
98  EventSet, PAPI_event, 0,
99  profflags[i] ) ) != PAPI_OK )
100  test_fail( __FILE__, __LINE__, "PAPI_profil", retval );
101  }
102 
103  prof_head( blength, bucket, num_buckets,
104  "address\t\t\tPOSIX\tINST_DEAR\n" );
105  prof_out( start, num_profs, bucket, num_buckets, scale );
106 
107  retval = prof_check( num_profs, bucket, num_buckets );
108 
109  for ( i = 0; i < num_profs; i++ ) {
110  free( profbuf[i] );
111  }
112 
113  return retval;
114 }
115 
116 
117 int
118 main( int argc, char **argv )
119 {
120  int num_events, num_tests = 6;
121  long length;
122  int retval, retval2;
123  const PAPI_hw_info_t *hw_info;
124  const PAPI_exe_info_t *prginfo;
125  caddr_t start, end;
126  int quiet;
127 
128  /* Set TESTS_QUIET variable */
129  quiet = tests_quiet( argc, argv );
130 
132  if (retval != PAPI_VER_CURRENT ) {
133  test_fail( __FILE__, __LINE__, "PAPI_library_init", retval );
134  }
135 
136  if ( ( prginfo = PAPI_get_executable_info( ) ) == NULL ) {
137  test_fail( __FILE__, __LINE__, "PAPI_get_executable_info", 1 );
138  }
139 
140  if ( ( hw_info = PAPI_get_hardware_info( ) ) == NULL ) {
141  test_fail( __FILE__, __LINE__, "PAPI_get_hardware_info", 0 );
142  }
143 
144  if ( ( strncasecmp( hw_info->model_string, "Itanium",
145  strlen( "Itanium" ) ) != 0 ) &&
146  ( strncasecmp( hw_info->model_string, "32",
147  strlen( "32" ) ) != 0 ) ) {
148  if (!quiet) printf("Itanium only for now.\n");
149  test_skip( __FILE__, __LINE__, "Test unsupported", PAPI_ENOIMPL );
150  }
151 
152 // if ( quiet ) {
153 // test_skip( __FILE__, __LINE__,
154 // "Test deprecated in quiet mode for PAPI 3.6", 0 );
155 // }
156 
157  sprintf( event_name, "DATA_EAR_CACHE_LAT4" );
158  if ( ( retval =
160  test_fail( __FILE__, __LINE__, "PAPI_event_name_to_code", retval );
161 
162  if ( ( retval = PAPI_create_eventset( &EventSet ) ) != PAPI_OK )
163  test_fail( __FILE__, __LINE__, "PAPI_create_eventset", retval );
164 
165  if ( ( retval = PAPI_add_event( EventSet, PAPI_event ) ) != PAPI_OK )
166  test_fail( __FILE__, __LINE__, "PAPI_add_event", retval );
167 
168  if ( ( retval = PAPI_add_event( EventSet, PAPI_TOT_CYC ) ) != PAPI_OK )
169  test_fail( __FILE__, __LINE__, "PAPI_add_event", retval );
170 
171  num_events = 2;
172  values = allocate_test_space( num_tests, num_events );
173 
174  /* use these lines to profile entire code address space */
175  start = prginfo->address_info.text_start;
176  end = prginfo->address_info.text_end;
177  length = end - start;
178  if ( length < 0 )
179  test_fail( __FILE__, __LINE__, "Profile length < 0!", length );
180 
182  ( "Test earprofile: POSIX compatible event address register profiling.\n",
183  prginfo );
184  prof_print_prof_info( start, end, THRESHOLD, event_name );
185  retval =
186  do_profile( start, length, FULL_SCALE, THRESHOLD,
188 
189  retval2 = PAPI_remove_event( EventSet, PAPI_event );
190  if ( retval2 == PAPI_OK )
192  if ( retval2 != PAPI_OK )
193  test_fail( __FILE__, __LINE__, "Can't remove events", retval2 );
194 
195  if ( retval )
196  test_pass( __FILE__ );
197  else
198  test_fail( __FILE__, __LINE__, "No information in buffers", 1 );
199 
200  return 1;
201 
202 }
char event_name[2][PAPI_MAX_STR_LEN]
Definition: data_range.c:29
sprintf(splash[splash_line++],"\tIozone: Performance Test of File I/O\n")
int PAPI_stop(int EventSet, long long *values)
Definition: papi.c:2314
unsigned long long length
Definition: iozone.c:17106
int PAPI_event[2]
Definition: data_range.c:30
void test_pass(const char *filename)
Definition: test_utils.c:432
int PAPI_add_event(int EventSet, int EventCode)
Definition: papi.c:1663
Hardware info structure.
Definition: papi.h:780
caddr_t text_end
Definition: papi.h:698
start
Definition: iozone.c:22736
int PAPI_remove_event(int EventSet, int EventCode)
Definition: papi.c:1758
#define PAPI_PROFIL_BUCKET_16
Definition: papi.h:400
static int num_events
void do_stuff(void)
Definition: do_loops.c:256
#define TAB1
Definition: papi_test.h:88
int EventSet
get the executable&#39;s info
Definition: papi.h:707
return PAPI_OK
Definition: linux-nvml.c:497
int PAPI_event_name_to_code(const char *in, int *out)
Definition: papi.c:1004
void do_l1misses(int n)
Definition: do_loops.c:220
int int argc
Definition: iozone.c:1609
Return codes and api definitions.
void test_skip(const char *file, int line, const char *call, int retval)
Definition: test_utils.c:559
char ** argv
Definition: iozone.c:1610
unsigned long prof_size(unsigned long plength, unsigned scale, int bucket, int *num_buckets)
Definition: prof_utils.c:310
int PAPI_library_init(int version)
Definition: papi.c:500
int PAPI_profil(void *buf, unsigned bufsiz, caddr_t offset, unsigned scale, int EventSet, int EventCode, int threshold, int flags)
Definition: papi.c:5438
int i
Definition: fileop.c:140
void prof_out(caddr_t start, int n, int bucket, int num_buckets, unsigned int scale)
Definition: prof_utils.c:202
#define FULL_SCALE
Definition: prof_utils.h:20
int quiet
Definition: rapl_overflow.c:18
#define PAPI_TOT_CYC
const PAPI_exe_info_t * PAPI_get_executable_info(void)
Definition: papi.c:6114
free(dummyfile[xx])
caddr_t text_start
Definition: papi.h:697
PAPI_address_map_t address_info
Definition: papi.h:709
static void ear_no_profile(void)
Definition: earprofile.c:40
void * profbuf[5]
Definition: prof_utils.c:33
#define PAPI_PROFIL_INST_EAR
Definition: papi.h:405
int PAPI_create_eventset(int *EventSet)
Definition: papi.c:1464
int num_tests
Definition: zero_fork.c:53
#define PAPI_ENOIMPL
Definition: papi.h:272
void prof_head(unsigned long blength, int bucket, int num_buckets, const char *header)
Definition: prof_utils.c:183
static int do_profile(caddr_t start, unsigned long plength, unsigned scale, int thresh, int bucket)
Definition: earprofile.c:58
#define PAPI_PROFIL_POSIX
Definition: papi.h:396
printf("\tTry: -i 0 -i 1 \n\n")
int TESTS_QUIET
Definition: test_utils.c:18
int tests_quiet(int argc, char **argv)
Definition: test_utils.c:376
void test_fail(const char *file, int line, const char *call, int retval)
Definition: test_utils.c:468
void prof_print_address(const char *title, const PAPI_exe_info_t *prginfo)
Definition: prof_utils.c:69
void prof_print_prof_info(caddr_t start, caddr_t end, int threshold, char *event_name)
Definition: prof_utils.c:93
int prof_check(int n, int bucket, int num_buckets)
Definition: prof_utils.c:272
char model_string[PAPI_MAX_STR_LEN]
Definition: papi.h:790
int PAPI_start(int EventSet)
Definition: papi.c:2096
#define THRESHOLD
Definition: earprofile.c:37
const PAPI_hw_info_t * PAPI_get_hardware_info(void)
Definition: papi.c:6185
static long long values[NUM_EVENTS]
Definition: init_fini.c:10
ssize_t retval
Definition: libasync.c:338
long long ** allocate_test_space(int num_tests, int num_events)
Definition: test_utils.c:46
#define PAPI_VER_CURRENT
Definition: papi.h:225
static const PAPI_hw_info_t * hw_info
Definition: byte_profile.c:28
int main(int argc, char **argv)
List all appio events codes and names.
void prof_alloc(int num, unsigned long blength)
Definition: prof_utils.c:140