PAPI 7.1.0.0
Loading...
Searching...
No Matches
ctests/sprofile.c
Go to the documentation of this file.
1/*
2* File: sprofile.c
3* Author: Philip Mucci
4* mucci@cs.utk.edu
5* Mods: Maynard Johnson
6* maynardj@us.ibm.com
7*/
8
9#include <stdio.h>
10#include <stdlib.h>
11
12#include "papi.h"
13#include "papi_test.h"
14#include "prof_utils.h"
15
16#include "do_loops.h"
17
18/* These architectures use Function Descriptors as Function Pointers */
19
20#if (defined(linux) && defined(__ia64__)) || (defined(_AIX)) \
21 || ((defined(__powerpc64__) && (_CALL_ELF != 2)))
22/* PPC64 Big Endian is ELF version 1 which uses function descriptors */
23#define DO_READS (unsigned long)(*(void **)do_reads)
24#define DO_FLOPS (unsigned long)(*(void **)do_flops)
25#else
26/* PPC64 Little Endian is ELF version 2 which does not use
27 * function descriptors
28 */
29#define DO_READS (unsigned long)(do_reads)
30#define DO_FLOPS (unsigned long)(do_flops)
31#endif
32
33/* This file performs the following test: sprofile */
34
35
36int
37main( int argc, char **argv )
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 vptr_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 = ( vptr_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 = ( vptr_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
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}
int i
Get the executable's address space info.
initialize the PAPI library.
Generate PC histogram data from multiple code regions where hardware counter overflow occurs.
Start counting hardware events in an event set.
Stop counting hardware events in an event set.
#define DO_FLOPS
#define DO_READS
volatile int buf[CACHE_FLUSH_BUFFER_SIZE_INTS]
Definition: do_loops.c:12
void do_reads(int n)
Definition: do_loops.c:19
void do_stuff(void)
Definition: do_loops.c:256
#define THRESHOLD
Definition: earprofile.c:37
#define PAPI_VER_CURRENT
Definition: f90papi.h:54
#define PAPI_OK
Definition: f90papi.h:73
#define PAPI_NULL
Definition: f90papi.h:78
#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_ENOEVNT
Definition: f90papi.h:139
#define PAPI_ESYS
Definition: f90papi.h:136
static int EventSet
Definition: init_fini.c:8
static long long values[NUM_EVENTS]
Definition: init_fini.c:10
static struct timeval start
static int num_events
void do_flops(int n)
Definition: multiplex.c:23
Return codes and api definitions.
void * vptr_t
Definition: papi.h:576
FILE * stderr
int tests_quiet(int argc, char **argv)
Definition: test_utils.c:376
int add_test_events(int *number, int *mask, int allow_derived)
Definition: test_utils.c:152
void PAPI_NORETURN test_fail(const char *file, int line, const char *call, int retval)
Definition: test_utils.c:491
long long ** allocate_test_space(int num_tests, int num_events)
Definition: test_utils.c:46
void PAPI_NORETURN test_pass(const char *filename)
Definition: test_utils.c:432
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
unsigned long prof_size(unsigned long plength, unsigned scale, int bucket, int *num_buckets)
Definition: prof_utils.c:310
void prof_alloc(int num, unsigned long blength)
Definition: prof_utils.c:140
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
#define FULL_SCALE
Definition: prof_utils.h:20
unsigned int length
int quiet
Definition: rapl_overflow.c:19
int
Definition: sde_internal.h:89
long long int long long
Definition: sde_internal.h:85
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
vptr_t pr_off
Definition: papi.h:582
unsigned pr_size
Definition: papi.h:581
void * pr_base
Definition: papi.h:580
unsigned pr_scale
Definition: papi.h:583
int num_tests
Definition: zero_fork.c:53
int retval
Definition: zero_fork.c:53