PAPI  5.7.0.0
ctests/sprofile.c File Reference
Include dependency graph for ctests/sprofile.c:

Go to the source code of this file.

Macros

#define DO_READS   (unsigned long)(do_reads)
 
#define DO_FLOPS   (unsigned long)(do_flops)
 

Functions

int main (int argc, char **argv)
 

Macro Definition Documentation

◆ DO_FLOPS

#define DO_FLOPS   (unsigned long)(do_flops)

Definition at line 30 of file ctests/sprofile.c.

◆ DO_READS

#define DO_READS   (unsigned long)(do_reads)

Definition at line 29 of file ctests/sprofile.c.

Function Documentation

◆ main()

int main ( int  argc,
char **  argv 
)

Definition at line 37 of file ctests/sprofile.c.

38 {
39  int i, num_events, num_tests = 6, mask = 0x1;
40  int EventSet = PAPI_NULL;
41  unsigned short **buf = ( unsigned short ** ) profbuf;
42  unsigned long length, blength;
43  int num_buckets;
44  PAPI_sprofil_t sprof[3];
45  int retval;
46  const PAPI_exe_info_t *prginfo;
47  caddr_t start, end;
48  int quiet;
49 
50  /* Set TESTS_QUIET variable */
51  quiet = tests_quiet( argc, argv );
52 
54  if (retval != PAPI_VER_CURRENT ) {
55  test_fail( __FILE__, __LINE__, "PAPI_library_init", retval );
56  }
57 
58  if ( ( prginfo = PAPI_get_executable_info( ) ) == NULL ) {
59  test_fail( __FILE__, __LINE__, "PAPI_get_executable_info", 1 );
60  }
61 
62  start = prginfo->address_info.text_start;
63  end = prginfo->address_info.text_end;
64  if ( start > end ) {
65  test_fail( __FILE__, __LINE__, "Profile length < 0!", PAPI_ESYS );
66  }
67  length = ( unsigned long ) ( end - start );
68  if (!quiet) {
69  prof_print_address( "Test case sprofile: POSIX compatible profiling over multiple regions.\n",
70  prginfo );
71  }
72 
74  &num_buckets );
75  prof_alloc( 3, blength );
76 
77  /* First half */
78  sprof[0].pr_base = buf[0];
79  sprof[0].pr_size = ( unsigned int ) blength;
80  sprof[0].pr_off = ( caddr_t ) DO_FLOPS;
81 #if defined(linux) && defined(__ia64__)
82  if ( !quiet )
83  fprintf( stderr, "do_flops is at %p %p\n", &do_flops, sprof[0].pr_off );
84 #endif
85  sprof[0].pr_scale = FULL_SCALE;
86  /* Second half */
87  sprof[1].pr_base = buf[1];
88  sprof[1].pr_size = ( unsigned int ) blength;
89  sprof[1].pr_off = ( caddr_t ) DO_READS;
90 #if defined(linux) && defined(__ia64__)
91  if ( !quiet )
92  fprintf( stderr, "do_reads is at %p %p\n", &do_reads, sprof[1].pr_off );
93 #endif
94  sprof[1].pr_scale = FULL_SCALE;
95  /* Overflow bin */
96  sprof[2].pr_base = buf[2];
97  sprof[2].pr_size = 1;
98  sprof[2].pr_off = 0;
99  sprof[2].pr_scale = 0x2;
100 
101  EventSet = add_test_events( &num_events, &mask, 1 );
102 
104 
107  if (retval != PAPI_OK ) {
108  if (retval == PAPI_ENOEVNT) {
109  if (!quiet) printf("Trouble creating events\n");
110  test_skip(__FILE__,__LINE__,"PAPI_sprofil",retval);
111  }
112  test_fail( __FILE__, __LINE__, "PAPI_sprofil", retval );
113  }
114 
115  do_stuff( );
116 
117  if ( ( retval = PAPI_start( EventSet ) ) != PAPI_OK )
118  test_fail( __FILE__, __LINE__, "PAPI_start", retval );
119 
120  do_stuff( );
121 
122  if ( ( retval = PAPI_stop( EventSet, values[1] ) ) != PAPI_OK )
123  test_fail( __FILE__, __LINE__, "PAPI_stop", retval );
124 
125  /* clear the profile flag before removing the event */
126  if ( ( retval = PAPI_sprofil( sprof, 3, EventSet, PAPI_TOT_CYC, 0,
128  != PAPI_OK )
129  test_fail( __FILE__, __LINE__, "PAPI_sprofil", retval );
130 
131  remove_test_events( &EventSet, mask );
132 
133 
134 
135  if ( !quiet ) {
136  printf( "Test case: PAPI_sprofil()\n" );
137  printf( "---------Buffer 1--------\n" );
138  for ( i = 0; i < ( int ) length / 2; i++ ) {
139  if ( buf[0][i] )
140  printf( "%#lx\t%d\n", DO_FLOPS + 2 * ( unsigned long ) i,
141  buf[0][i] );
142  }
143  printf( "---------Buffer 2--------\n" );
144  for ( i = 0; i < ( int ) length / 2; i++ ) {
145  if ( buf[1][i] )
146  printf( "%#lx\t%d\n", DO_READS + 2 * ( unsigned long ) i,
147  buf[1][i] );
148  }
149  printf( "-------------------------\n" );
150  printf( "%u samples fell outside the regions.\n", *buf[2] );
151  }
152  retval = prof_check( 2, PAPI_PROFIL_BUCKET_16, num_buckets );
153 
154  for ( i = 0; i < 3; i++ ) {
155  free( profbuf[i] );
156  }
157  if ( retval == 0 ) {
158  test_fail( __FILE__, __LINE__, "No information in buffers", 1 );
159  }
160 
161  test_pass( __FILE__ );
162 
163  return 0;
164 }
#define PAPI_OK
Definition: fpapi.h:105
int PAPI_stop(int EventSet, long long *values)
Definition: papi.c:2314
void test_pass(const char *filename)
Definition: test_utils.c:432
void do_reads(int n)
Definition: do_loops.c:19
caddr_t text_end
Definition: papi.h:699
#define PAPI_PROFIL_BUCKET_16
Definition: fpapi.h:79
#define DO_FLOPS
static int num_events
void do_stuff(void)
Definition: do_loops.c:256
caddr_t pr_off
Definition: papi.h:585
#define PAPI_VER_CURRENT
Definition: fpapi.h:14
int EventSet
get the executable's info
Definition: papi.h:708
#define PAPI_PROFIL_POSIX
Definition: fpapi.h:75
int retval
Definition: zero_fork.c:53
static struct timeval start
int PAPI_sprofil(PAPI_sprofil_t *prof, int profcnt, int EventSet, int EventCode, int threshold, int flags)
Definition: papi.c:5044
unsigned pr_scale
Definition: papi.h:586
void test_skip(const char *file, int line, const char *call, int retval)
Definition: test_utils.c:561
#define PAPI_ESYS
Definition: fpapi.h:108
unsigned pr_size
Definition: papi.h:584
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
#define FULL_SCALE
Definition: prof_utils.h:20
int quiet
Definition: rapl_overflow.c:18
const PAPI_exe_info_t * PAPI_get_executable_info(void)
Definition: papi.c:6114
caddr_t text_start
Definition: papi.h:698
PAPI_address_map_t address_info
Definition: papi.h:710
void * profbuf[5]
Definition: prof_utils.c:33
unsigned int length
#define PAPI_NULL
Definition: fpapi.h:13
void * pr_base
Definition: papi.h:583
#define DO_READS
int num_tests
Definition: zero_fork.c:53
void do_flops(int n)
Definition: multiplex.c:23
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
#define PAPI_ENOEVNT
Definition: fpapi.h:112
int prof_check(int n, int bucket, int num_buckets)
Definition: prof_utils.c:272
char * caddr_t
int PAPI_start(int EventSet)
Definition: papi.c:2096
#define THRESHOLD
Definition: earprofile.c:37
#define PAPI_TOT_CYC
Definition: fpapi.h:195
static long long values[NUM_EVENTS]
Definition: init_fini.c:10
long long ** allocate_test_space(int num_tests, int num_events)
Definition: test_utils.c:46
volatile int buf[CACHE_FLUSH_BUFFER_SIZE_INTS]
Definition: do_loops.c:12
int remove_test_events(int *EventSet, int mask)
Definition: test_utils.c:201
void prof_alloc(int num, unsigned long blength)
Definition: prof_utils.c:140
int add_test_events(int *number, int *mask, int allow_derived)
Definition: test_utils.c:152
int i
Definition: fileop.c:140
Here is the call graph for this function: