|
Packit |
577717 |
/*
|
|
Packit |
577717 |
* File: sprofile.c
|
|
Packit |
577717 |
* Author: Philip Mucci
|
|
Packit |
577717 |
* mucci@cs.utk.edu
|
|
Packit |
577717 |
* Mods: Maynard Johnson
|
|
Packit |
577717 |
* maynardj@us.ibm.com
|
|
Packit |
577717 |
*/
|
|
Packit |
577717 |
|
|
Packit |
577717 |
#include <stdio.h>
|
|
Packit |
577717 |
#include <stdlib.h>
|
|
Packit |
577717 |
|
|
Packit |
577717 |
#include "papi.h"
|
|
Packit |
577717 |
#include "papi_test.h"
|
|
Packit |
577717 |
#include "prof_utils.h"
|
|
Packit |
577717 |
|
|
Packit |
577717 |
#include "do_loops.h"
|
|
Packit |
577717 |
|
|
Packit |
577717 |
/* These architectures use Function Descriptors as Function Pointers */
|
|
Packit |
577717 |
|
|
Packit |
577717 |
#if (defined(linux) && defined(__ia64__)) || (defined(_AIX)) \
|
|
Packit |
577717 |
|| ((defined(__powerpc64__) && (_CALL_ELF != 2)))
|
|
Packit |
577717 |
/* PPC64 Big Endian is ELF version 1 which uses function descriptors */
|
|
Packit |
577717 |
#define DO_READS (unsigned long)(*(void **)do_reads)
|
|
Packit |
577717 |
#define DO_FLOPS (unsigned long)(*(void **)do_flops)
|
|
Packit |
577717 |
#else
|
|
Packit |
577717 |
/* PPC64 Little Endian is ELF version 2 which does not use
|
|
Packit |
577717 |
* function descriptors
|
|
Packit |
577717 |
*/
|
|
Packit |
577717 |
#define DO_READS (unsigned long)(do_reads)
|
|
Packit |
577717 |
#define DO_FLOPS (unsigned long)(do_flops)
|
|
Packit |
577717 |
#endif
|
|
Packit |
577717 |
|
|
Packit |
577717 |
/* This file performs the following test: sprofile */
|
|
Packit |
577717 |
|
|
Packit |
577717 |
|
|
Packit |
577717 |
int
|
|
Packit |
577717 |
main( int argc, char **argv )
|
|
Packit |
577717 |
{
|
|
Packit |
577717 |
int i, num_events, num_tests = 6, mask = 0x1;
|
|
Packit |
577717 |
int EventSet = PAPI_NULL;
|
|
Packit |
577717 |
unsigned short **buf = ( unsigned short ** ) profbuf;
|
|
Packit |
577717 |
unsigned long length, blength;
|
|
Packit |
577717 |
int num_buckets;
|
|
Packit |
577717 |
PAPI_sprofil_t sprof[3];
|
|
Packit |
577717 |
int retval;
|
|
Packit |
577717 |
const PAPI_exe_info_t *prginfo;
|
|
Packit |
577717 |
caddr_t start, end;
|
|
Packit |
577717 |
int quiet;
|
|
Packit |
577717 |
|
|
Packit |
577717 |
/* Set TESTS_QUIET variable */
|
|
Packit |
577717 |
quiet = tests_quiet( argc, argv );
|
|
Packit |
577717 |
|
|
Packit |
577717 |
retval = PAPI_library_init( PAPI_VER_CURRENT );
|
|
Packit |
577717 |
if (retval != PAPI_VER_CURRENT ) {
|
|
Packit |
577717 |
test_fail( __FILE__, __LINE__, "PAPI_library_init", retval );
|
|
Packit |
577717 |
}
|
|
Packit |
577717 |
|
|
Packit |
577717 |
if ( ( prginfo = PAPI_get_executable_info( ) ) == NULL ) {
|
|
Packit |
577717 |
test_fail( __FILE__, __LINE__, "PAPI_get_executable_info", 1 );
|
|
Packit |
577717 |
}
|
|
Packit |
577717 |
|
|
Packit |
577717 |
start = prginfo->address_info.text_start;
|
|
Packit |
577717 |
end = prginfo->address_info.text_end;
|
|
Packit |
577717 |
if ( start > end ) {
|
|
Packit |
577717 |
test_fail( __FILE__, __LINE__, "Profile length < 0!", PAPI_ESYS );
|
|
Packit |
577717 |
}
|
|
Packit |
577717 |
length = ( unsigned long ) ( end - start );
|
|
Packit |
577717 |
if (!quiet) {
|
|
Packit |
577717 |
prof_print_address( "Test case sprofile: POSIX compatible profiling over multiple regions.\n",
|
|
Packit |
577717 |
prginfo );
|
|
Packit |
577717 |
}
|
|
Packit |
577717 |
|
|
Packit |
577717 |
blength = prof_size( length, FULL_SCALE, PAPI_PROFIL_BUCKET_16,
|
|
Packit |
577717 |
&num_buckets );
|
|
Packit |
577717 |
prof_alloc( 3, blength );
|
|
Packit |
577717 |
|
|
Packit |
577717 |
/* First half */
|
|
Packit |
577717 |
sprof[0].pr_base = buf[0];
|
|
Packit |
577717 |
sprof[0].pr_size = ( unsigned int ) blength;
|
|
Packit |
577717 |
sprof[0].pr_off = ( caddr_t ) DO_FLOPS;
|
|
Packit |
577717 |
#if defined(linux) && defined(__ia64__)
|
|
Packit |
577717 |
if ( !quiet )
|
|
Packit |
577717 |
fprintf( stderr, "do_flops is at %p %p\n", &do_flops, sprof[0].pr_off );
|
|
Packit |
577717 |
#endif
|
|
Packit |
577717 |
sprof[0].pr_scale = FULL_SCALE;
|
|
Packit |
577717 |
/* Second half */
|
|
Packit |
577717 |
sprof[1].pr_base = buf[1];
|
|
Packit |
577717 |
sprof[1].pr_size = ( unsigned int ) blength;
|
|
Packit |
577717 |
sprof[1].pr_off = ( caddr_t ) DO_READS;
|
|
Packit |
577717 |
#if defined(linux) && defined(__ia64__)
|
|
Packit |
577717 |
if ( !quiet )
|
|
Packit |
577717 |
fprintf( stderr, "do_reads is at %p %p\n", &do_reads, sprof[1].pr_off );
|
|
Packit |
577717 |
#endif
|
|
Packit |
577717 |
sprof[1].pr_scale = FULL_SCALE;
|
|
Packit |
577717 |
/* Overflow bin */
|
|
Packit |
577717 |
sprof[2].pr_base = buf[2];
|
|
Packit |
577717 |
sprof[2].pr_size = 1;
|
|
Packit |
577717 |
sprof[2].pr_off = 0;
|
|
Packit |
577717 |
sprof[2].pr_scale = 0x2;
|
|
Packit |
577717 |
|
|
Packit |
577717 |
EventSet = add_test_events( &num_events, &mask, 1 );
|
|
Packit |
577717 |
|
|
Packit |
577717 |
values = allocate_test_space( num_tests, num_events );
|
|
Packit |
577717 |
|
|
Packit |
577717 |
retval = PAPI_sprofil( sprof, 3, EventSet, PAPI_TOT_CYC, THRESHOLD,
|
|
Packit |
577717 |
PAPI_PROFIL_POSIX | PAPI_PROFIL_BUCKET_16 );
|
|
Packit |
577717 |
if (retval != PAPI_OK ) {
|
|
Packit |
577717 |
if (retval == PAPI_ENOEVNT) {
|
|
Packit |
577717 |
if (!quiet) printf("Trouble creating events\n");
|
|
Packit |
577717 |
test_skip(__FILE__,__LINE__,"PAPI_sprofil",retval);
|
|
Packit |
577717 |
}
|
|
Packit |
577717 |
test_fail( __FILE__, __LINE__, "PAPI_sprofil", retval );
|
|
Packit |
577717 |
}
|
|
Packit |
577717 |
|
|
Packit |
577717 |
do_stuff( );
|
|
Packit |
577717 |
|
|
Packit |
577717 |
if ( ( retval = PAPI_start( EventSet ) ) != PAPI_OK )
|
|
Packit |
577717 |
test_fail( __FILE__, __LINE__, "PAPI_start", retval );
|
|
Packit |
577717 |
|
|
Packit |
577717 |
do_stuff( );
|
|
Packit |
577717 |
|
|
Packit |
577717 |
if ( ( retval = PAPI_stop( EventSet, values[1] ) ) != PAPI_OK )
|
|
Packit |
577717 |
test_fail( __FILE__, __LINE__, "PAPI_stop", retval );
|
|
Packit |
577717 |
|
|
Packit |
577717 |
/* clear the profile flag before removing the event */
|
|
Packit |
577717 |
if ( ( retval = PAPI_sprofil( sprof, 3, EventSet, PAPI_TOT_CYC, 0,
|
|
Packit |
577717 |
PAPI_PROFIL_POSIX | PAPI_PROFIL_BUCKET_16 ) )
|
|
Packit |
577717 |
!= PAPI_OK )
|
|
Packit |
577717 |
test_fail( __FILE__, __LINE__, "PAPI_sprofil", retval );
|
|
Packit |
577717 |
|
|
Packit |
577717 |
remove_test_events( &EventSet, mask );
|
|
Packit |
577717 |
|
|
Packit |
577717 |
|
|
Packit |
577717 |
|
|
Packit |
577717 |
if ( !quiet ) {
|
|
Packit |
577717 |
printf( "Test case: PAPI_sprofil()\n" );
|
|
Packit |
577717 |
printf( "---------Buffer 1--------\n" );
|
|
Packit |
577717 |
for ( i = 0; i < ( int ) length / 2; i++ ) {
|
|
Packit |
577717 |
if ( buf[0][i] )
|
|
Packit |
577717 |
printf( "%#lx\t%d\n", DO_FLOPS + 2 * ( unsigned long ) i,
|
|
Packit |
577717 |
buf[0][i] );
|
|
Packit |
577717 |
}
|
|
Packit |
577717 |
printf( "---------Buffer 2--------\n" );
|
|
Packit |
577717 |
for ( i = 0; i < ( int ) length / 2; i++ ) {
|
|
Packit |
577717 |
if ( buf[1][i] )
|
|
Packit |
577717 |
printf( "%#lx\t%d\n", DO_READS + 2 * ( unsigned long ) i,
|
|
Packit |
577717 |
buf[1][i] );
|
|
Packit |
577717 |
}
|
|
Packit |
577717 |
printf( "-------------------------\n" );
|
|
Packit |
577717 |
printf( "%u samples fell outside the regions.\n", *buf[2] );
|
|
Packit |
577717 |
}
|
|
Packit |
577717 |
retval = prof_check( 2, PAPI_PROFIL_BUCKET_16, num_buckets );
|
|
Packit |
577717 |
|
|
Packit |
577717 |
for ( i = 0; i < 3; i++ ) {
|
|
Packit |
577717 |
free( profbuf[i] );
|
|
Packit |
577717 |
}
|
|
Packit |
577717 |
if ( retval == 0 ) {
|
|
Packit |
577717 |
test_fail( __FILE__, __LINE__, "No information in buffers", 1 );
|
|
Packit |
577717 |
}
|
|
Packit |
577717 |
|
|
Packit |
577717 |
test_pass( __FILE__ );
|
|
Packit |
577717 |
|
|
Packit |
577717 |
return 0;
|
|
Packit |
577717 |
}
|