PAPI 7.1.0.0
Loading...
Searching...
No Matches
profile.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* Mods: Maynard Johnson
8* maynardj@us.ibm.com
9*/
10
11/* This file performs the following test:
12 profiling and program info option call
13
14 - This tests the SVR4 profiling interface of PAPI. These are counted
15 in the default counting domain and default granularity, depending on
16 the platform. Usually this is the user domain (PAPI_DOM_USER) and
17 thread context (PAPI_GRN_THR).
18
19 The Eventset contains:
20 + PAPI_FP_INS (to profile)
21 + PAPI_TOT_CYC
22
23 - Set up profile
24 - Start eventset 1
25 - Do both (flops and reads)
26 - Stop eventset 1
27*/
28
29#include <stdio.h>
30#include <stdlib.h>
31
32#include "papi.h"
33#include "papi_test.h"
34#include "prof_utils.h"
35
36#include "do_loops.h"
37
38#define PROFILE_ALL
39
40static int
41do_profile( vptr_t start, unsigned long plength, unsigned scale, int thresh,
42 int bucket )
43{
44 int i, retval;
45 unsigned long blength;
46 int num_buckets;
47
48 const char *profstr[5] = { "PAPI_PROFIL_POSIX",
49 "PAPI_PROFIL_RANDOM",
50 "PAPI_PROFIL_WEIGHTED",
51 "PAPI_PROFIL_COMPRESS",
52 "PAPI_PROFIL_<all>"
53 };
54
55 int profflags[5] = { PAPI_PROFIL_POSIX,
61 };
62
64 blength = prof_size( plength, scale, bucket, &num_buckets );
65 prof_alloc( 5, blength );
66
67 for ( i = 0; i < 5; i++ ) {
68 if ( !TESTS_QUIET ) {
69 printf( "Test type : \t%s\n", profstr[i] );
70 }
71
72#ifndef SWPROFILE
73 if ( ( retval =
74 PAPI_profil( profbuf[i], ( unsigned int ) blength, start, scale,
75 EventSet, PAPI_event, thresh,
76 profflags[i] | bucket ) ) != PAPI_OK ) {
77 if (retval==PAPI_ENOSUPP) {
78 char warning[BUFSIZ];
79
80 sprintf(warning,"PAPI_profil %s not supported",
81 profstr[i]);
82 test_warn( __FILE__, __LINE__, warning, 1 );
83 }
84 else {
85 test_fail( __FILE__, __LINE__, "PAPI_profil", retval );
86 }
87 }
88#else
89 if ( ( retval =
90 PAPI_profil( profbuf[i], ( unsigned int ) blength, start, scale,
91 EventSet, PAPI_event, thresh,
92 profflags[i] | bucket | PAPI_PROFIL_FORCE_SW ) ) !=
93 PAPI_OK ) {
94 test_fail( __FILE__, __LINE__, "PAPI_profil", retval );
95 }
96#endif
97
98 if ( retval != PAPI_OK )
99 break;
100
101 if ( ( retval = PAPI_start( EventSet ) ) != PAPI_OK )
102 test_fail( __FILE__, __LINE__, "PAPI_start", retval );
103
104 do_flops( getenv( "NUM_FLOPS" ) ? atoi( getenv( "NUM_FLOPS" ) ) :
105 NUM_FLOPS );
106
107 if ( ( retval = PAPI_stop( EventSet, values[1] ) ) != PAPI_OK )
108 test_fail( __FILE__, __LINE__, "PAPI_stop", retval );
109
110 if ( !TESTS_QUIET ) {
111 printf( TAB1, event_name, ( values[1] )[0] );
112 printf( TAB1, "PAPI_TOT_CYC", ( values[1] )[1] );
113 }
114 retval = PAPI_profil( profbuf[i], ( unsigned int ) blength, start, scale,
116 profflags[i] );
117 if (retval != PAPI_OK ) {
118 test_fail( __FILE__, __LINE__, "PAPI_profil", retval );
119 }
120 }
121
122 if ( retval == PAPI_OK ) {
123 if (!TESTS_QUIET) prof_head( blength, bucket, num_buckets,
124 "address\t\t\tflat\trandom\tweight\tcomprs\tall\n" );
125 if (!TESTS_QUIET) prof_out( start, 5, bucket, num_buckets, scale );
126 retval = prof_check( 5, bucket, num_buckets );
127 }
128
129 for ( i = 0; i < 5; i++ ) {
130 free( profbuf[i] );
131 }
132
133 return retval;
134}
135
136
137int
138main( int argc, char **argv )
139{
140 int num_tests = 6;
141 long length;
142 int mask;
143 int retval;
145 const PAPI_exe_info_t *prginfo;
146 vptr_t start, end;
147 int quiet;
148
149 /* Set TESTS_QUIET variable */
150 quiet = tests_quiet( argc, argv );
151
153 if (retval != PAPI_VER_CURRENT ) {
154 test_fail( __FILE__, __LINE__, "PAPI_library_init", retval );
155 }
156
157 if ( ( prginfo = PAPI_get_executable_info( ) ) == NULL ) {
158 test_fail( __FILE__, __LINE__, "PAPI_get_executable_info", 1 );
159 }
160
162 if (retval!=PAPI_OK) {
163 if (!quiet) printf("No events found\n");
164 test_skip(__FILE__, __LINE__,"No events found",1);
165 }
166
167 mask = prof_events( num_tests );
168
169#ifdef PROFILE_ALL
170/* use these lines to profile entire code address space */
171 start = prginfo->address_info.text_start;
172 end = prginfo->address_info.text_end;
173#else
174/* use these lines to profile only do_flops address space */
175 start = ( vptr_t ) do_flops;
176 end = ( vptr_t ) fdo_flops;
177/* Itanium and ppc64 processors return function descriptors instead of function addresses.
178 You must dereference the descriptor to get the address.
179*/
180#if defined(ITANIUM1) || defined(ITANIUM2) || defined(__powerpc64__)
181 start = ( vptr_t ) ( ( ( struct fdesc * ) start )->ip );
182 end = ( vptr_t ) ( ( ( struct fdesc * ) end )->ip );
183#endif
184#endif
185
186#if defined(linux)
187 {
188 char *tmp = getenv( "THRESHOLD" );
189 if ( tmp )
190 mythreshold = atoi( tmp );
191 }
192#endif
193
194 length = end - start;
195 if ( length < 0 ) {
196 test_fail( __FILE__, __LINE__, "Profile length < 0!", ( int ) length );
197 }
198
199 if (!quiet) {
200 prof_print_address( "Test case profile: "
201 "POSIX compatible profiling with hardware counters.\n",
202 prginfo );
204 }
205
206 retval = do_profile( start, ( unsigned long ) length, FULL_SCALE,
208 if ( retval == PAPI_OK ) {
209 retval = do_profile( start, ( unsigned long ) length,
212 }
213 if ( retval == PAPI_OK ) {
214 retval = do_profile( start, ( unsigned long ) length,
217 }
218
220
221 test_pass( __FILE__ );
222
223 return 0;
224}
225
double tmp
int i
Get the executable's address space info.
initialize the PAPI library.
Generate a histogram of hardware counter overflows vs. PC addresses.
Query if PAPI event exists.
Start counting hardware events in an event set.
Stop counting hardware events in an event set.
static long long mythreshold
int PAPI_event[2]
Definition: data_range.c:30
char event_name[2][PAPI_MAX_STR_LEN]
Definition: data_range.c:29
void fdo_flops(int *n)
Definition: do_loops.c:90
#define THRESHOLD
Definition: earprofile.c:37
#define PAPI_VER_CURRENT
Definition: f90papi.h:54
#define PAPI_PROFIL_BUCKET_32
Definition: f90papi.h:248
#define PAPI_OK
Definition: f90papi.h:73
#define PAPI_PROFIL_WEIGHTED
Definition: f90papi.h:167
#define PAPI_PROFIL_POSIX
Definition: f90papi.h:44
#define PAPI_PROFIL_BUCKET_16
Definition: f90papi.h:144
#define PAPI_TOT_CYC
Definition: f90papi.h:308
#define PAPI_ENOSUPP
Definition: f90papi.h:244
#define PAPI_PROFIL_FORCE_SW
Definition: f90papi.h:257
#define PAPI_PROFIL_BUCKET_64
Definition: f90papi.h:198
#define PAPI_PROFIL_COMPRESS
Definition: f90papi.h:53
#define PAPI_PROFIL_RANDOM
Definition: f90papi.h:143
static int EventSet
Definition: init_fini.c:8
static long long values[NUM_EVENTS]
Definition: init_fini.c:10
static struct timeval start
void do_flops(int n)
Definition: multiplex.c:23
int TESTS_QUIET
Definition: test_utils.c:18
Return codes and api definitions.
void * vptr_t
Definition: papi.h:576
int tests_quiet(int argc, char **argv)
Definition: test_utils.c:376
#define TAB1
Definition: papi_test.h:98
void PAPI_NORETURN test_fail(const char *file, int line, const char *call, int retval)
Definition: test_utils.c:491
void PAPI_NORETURN test_pass(const char *filename)
Definition: test_utils.c:432
void test_warn(const char *file, int line, const char *call, int retval)
Definition: test_utils.c:547
void PAPI_NORETURN test_skip(const char *file, int line, const char *call, int retval)
Definition: test_utils.c:584
int remove_test_events(int *EventSet, int mask)
Definition: test_utils.c:201
int main()
Definition: pernode.c:20
int prof_check(int n, int bucket, int num_buckets)
Definition: prof_utils.c:272
void prof_head(unsigned long blength, int bucket, int num_buckets, const char *header)
Definition: prof_utils.c:183
void prof_print_prof_info(vptr_t start, vptr_t end, int threshold, char *event_name)
Definition: prof_utils.c:93
unsigned long prof_size(unsigned long plength, unsigned scale, int bucket, int *num_buckets)
Definition: prof_utils.c:310
int prof_events(int num_tests)
Definition: prof_utils.c:42
void prof_alloc(int num, unsigned long blength)
Definition: prof_utils.c:140
void prof_out(vptr_t start, int n, int bucket, int num_buckets, unsigned int scale)
Definition: prof_utils.c:202
void prof_print_address(const char *title, const PAPI_exe_info_t *prginfo)
Definition: prof_utils.c:69
void * profbuf[5]
Definition: prof_utils.c:33
void do_no_profile(int quiet)
Definition: prof_utils.c:113
#define FULL_SCALE
Definition: prof_utils.h:20
static int do_profile(vptr_t start, unsigned long plength, unsigned scale, int thresh, int bucket)
Definition: profile.c:41
unsigned int length
int quiet
Definition: rapl_overflow.c:19
#define NUM_FLOPS
Definition: sdsc-mpx.c:24
vptr_t text_start
Definition: papi.h:686
vptr_t text_end
Definition: papi.h:687
get the executable's info
Definition: papi.h:696
PAPI_address_map_t address_info
Definition: papi.h:698
int num_tests
Definition: zero_fork.c:53
int retval
Definition: zero_fork.c:53