PAPI  5.0.1.0
sprofile.c
Go to the documentation of this file.
00001 /* 
00002 * File:    sprofile.c
00003 * Author:  Philip Mucci
00004 *          mucci@cs.utk.edu
00005 * Mods:    Maynard Johnson
00006 *          maynardj@us.ibm.com
00007 * Mods:    <your name here>
00008 *          <your email address>
00009 */
00010 
00011 /* These architectures use Function Descriptors as Function Pointers */
00012 
00013 #if (defined(linux) && defined(__ia64__)) || (defined(_AIX)) ||(defined(__powerpc64__))
00014 #define DO_READS (unsigned long)(*(void **)do_reads)
00015 #define DO_FLOPS (unsigned long)(*(void **)do_flops)
00016 #else
00017 #define DO_READS (unsigned long)(do_reads)
00018 #define DO_FLOPS (unsigned long)(do_flops)
00019 #endif
00020 
00021 /* This file performs the following test: sprofile */
00022 
00023 #include "papi_test.h"
00024 #include "prof_utils.h"
00025 
00026 int
00027 main( int argc, char **argv )
00028 {
00029     int i, num_events, num_tests = 6, mask = 0x1;
00030     int EventSet = PAPI_NULL;
00031     unsigned short **buf = ( unsigned short ** ) profbuf;
00032     unsigned long length, blength;
00033     int num_buckets;
00034     PAPI_sprofil_t sprof[3];
00035     int retval;
00036     const PAPI_exe_info_t *prginfo;
00037     caddr_t start, end;
00038 
00039     prof_init( argc, argv, &prginfo );
00040 
00041     start = prginfo->address_info.text_start;
00042     end = prginfo->address_info.text_end;
00043     if ( start > end ) {
00044        test_fail( __FILE__, __LINE__, "Profile length < 0!", PAPI_ESYS );
00045     }
00046     length = ( unsigned long ) ( end - start );
00047     prof_print_address
00048         ( "Test case sprofile: POSIX compatible profiling over multiple regions.\n",
00049           prginfo );
00050     blength =
00051         prof_size( length, FULL_SCALE, PAPI_PROFIL_BUCKET_16, &num_buckets );
00052     prof_alloc( 3, blength );
00053 
00054     /* First half */
00055     sprof[0].pr_base = buf[0];
00056     sprof[0].pr_size = ( unsigned int ) blength;
00057     sprof[0].pr_off = ( caddr_t ) DO_FLOPS;
00058 #if defined(linux) && defined(__ia64__)
00059     if ( !TESTS_QUIET )
00060         fprintf( stderr, "do_flops is at %p %p\n", &do_flops, sprof[0].pr_off );
00061 #endif
00062     sprof[0].pr_scale = FULL_SCALE;
00063     /* Second half */
00064     sprof[1].pr_base = buf[1];
00065     sprof[1].pr_size = ( unsigned int ) blength;
00066     sprof[1].pr_off = ( caddr_t ) DO_READS;
00067 #if defined(linux) && defined(__ia64__)
00068     if ( !TESTS_QUIET )
00069         fprintf( stderr, "do_reads is at %p %p\n", &do_reads, sprof[1].pr_off );
00070 #endif
00071     sprof[1].pr_scale = FULL_SCALE;
00072     /* Overflow bin */
00073     sprof[2].pr_base = buf[2];
00074     sprof[2].pr_size = 1;
00075     sprof[2].pr_off = 0;
00076     sprof[2].pr_scale = 0x2;
00077 
00078     EventSet = add_test_events( &num_events, &mask, 1 );
00079 
00080     values = allocate_test_space( num_tests, num_events );
00081 
00082     if ( ( retval = PAPI_sprofil( sprof, 3, EventSet, PAPI_TOT_CYC, THRESHOLD,
00083                                   PAPI_PROFIL_POSIX | PAPI_PROFIL_BUCKET_16 ) )
00084          != PAPI_OK )
00085         test_fail( __FILE__, __LINE__, "PAPI_sprofil", retval );
00086 
00087     do_stuff(  );
00088 
00089     if ( ( retval = PAPI_start( EventSet ) ) != PAPI_OK )
00090         test_fail( __FILE__, __LINE__, "PAPI_start", retval );
00091 
00092     do_stuff(  );
00093 
00094     if ( ( retval = PAPI_stop( EventSet, values[1] ) ) != PAPI_OK )
00095         test_fail( __FILE__, __LINE__, "PAPI_stop", retval );
00096 
00097     /* clear the profile flag before removing the event */
00098     if ( ( retval = PAPI_sprofil( sprof, 3, EventSet, PAPI_TOT_CYC, 0,
00099                                   PAPI_PROFIL_POSIX | PAPI_PROFIL_BUCKET_16 ) )
00100          != PAPI_OK )
00101         test_fail( __FILE__, __LINE__, "PAPI_sprofil", retval );
00102 
00103     remove_test_events( &EventSet, mask );
00104 
00105 
00106 
00107     if ( !TESTS_QUIET ) {
00108         printf( "Test case: PAPI_sprofil()\n" );
00109         printf( "---------Buffer 1--------\n" );
00110         for ( i = 0; i < ( int ) length / 2; i++ ) {
00111             if ( buf[0][i] )
00112                 printf( "0x%lx\t%d\n", DO_FLOPS + 2 * ( unsigned long ) i,
00113                         buf[0][i] );
00114         }
00115         printf( "---------Buffer 2--------\n" );
00116         for ( i = 0; i < ( int ) length / 2; i++ ) {
00117             if ( buf[1][i] )
00118                 printf( "0x%lx\t%d\n", DO_READS + 2 * ( unsigned long ) i,
00119                         buf[1][i] );
00120         }
00121         printf( "-------------------------\n" );
00122         printf( "%u samples fell outside the regions.\n", *buf[2] );
00123     }
00124     retval = prof_check( 2, PAPI_PROFIL_BUCKET_16, num_buckets );
00125 
00126     for ( i = 0; i < 3; i++ ) {
00127         free( profbuf[i] );
00128     }
00129     if ( retval == 0 )
00130         test_fail( __FILE__, __LINE__, "No information in buffers", 1 );
00131 
00132     test_pass( __FILE__, values, num_tests );
00133 
00134     exit( 1 );
00135 }
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Defines