PAPI  5.0.1.0
earprofile.c
Go to the documentation of this file.
00001 /* 
00002 * File:    profile.c
00003 * Author:  Philip Mucci
00004 *          mucci@cs.utk.edu
00005 * Mods:    Dan Terpstra
00006 *          terpstra@cs.utk.edu
00007 * Mods:    <your name here>
00008 *          <your email address>
00009 */
00010 
00011 /* This file performs the following test: profiling and program info option call
00012 
00013    - This tests the SVR4 profiling interface of PAPI. These are counted 
00014    in the default counting domain and default granularity, depending on 
00015    the platform. Usually this is the user domain (PAPI_DOM_USER) and 
00016    thread context (PAPI_GRN_THR).
00017 
00018      The Eventset contains:
00019      + PAPI_FP_INS (to profile)
00020      + PAPI_TOT_CYC
00021 
00022    - Set up profile
00023    - Start eventset 1
00024    - Do both (flops and reads)
00025    - Stop eventset 1
00026 */
00027 
00028 #include "papi_test.h"
00029 #include "prof_utils.h"
00030 #undef THRESHOLD
00031 #define THRESHOLD 1000
00032 
00033 static void
00034 ear_no_profile( void )
00035 {
00036     int retval;
00037 
00038     if ( ( retval = PAPI_start( EventSet ) ) != PAPI_OK )
00039         test_fail( __FILE__, __LINE__, "PAPI_start", retval );
00040 
00041     do_l1misses( 10000 );
00042 
00043     if ( ( retval = PAPI_stop( EventSet, values[0] ) ) != PAPI_OK )
00044         test_fail( __FILE__, __LINE__, "PAPI_stop", retval );
00045 
00046     printf( "Test type   : \tNo profiling\n" );
00047     printf( TAB1, event_name, ( values[0] )[0] );
00048     printf( TAB1, "PAPI_TOT_CYC:", ( values[0] )[1] );
00049 }
00050 
00051 static int
00052 do_profile( caddr_t start, unsigned long plength, unsigned scale, int thresh,
00053             int bucket )
00054 {
00055     int i, retval;
00056     unsigned long blength;
00057     int num_buckets;
00058     char *profstr[2] = { "PAPI_PROFIL_POSIX", "PAPI_PROFIL_INST_EAR" };
00059     int profflags[2] =
00060         { PAPI_PROFIL_POSIX, PAPI_PROFIL_POSIX | PAPI_PROFIL_INST_EAR };
00061     int num_profs;
00062 
00063     do_stuff(  );
00064 
00065     num_profs = sizeof ( profflags ) / sizeof ( int );
00066     ear_no_profile(  );
00067     blength = prof_size( plength, scale, bucket, &num_buckets );
00068     prof_alloc( num_profs, blength );
00069 
00070     for ( i = 0; i < num_profs; i++ ) {
00071         if ( !TESTS_QUIET )
00072             printf( "Test type   : \t%s\n", profstr[i] );
00073 
00074         if ( ( retval = PAPI_profil( profbuf[i], blength, start, scale,
00075                                      EventSet, PAPI_event, thresh,
00076                                      profflags[i] | bucket ) ) != PAPI_OK ) {
00077             test_fail( __FILE__, __LINE__, "PAPI_profil", retval );
00078         }
00079         if ( ( retval = PAPI_start( EventSet ) ) != PAPI_OK )
00080             test_fail( __FILE__, __LINE__, "PAPI_start", retval );
00081 
00082         do_stuff(  );
00083 
00084         if ( ( retval = PAPI_stop( EventSet, values[1] ) ) != PAPI_OK )
00085             test_fail( __FILE__, __LINE__, "PAPI_stop", retval );
00086 
00087         if ( !TESTS_QUIET ) {
00088             printf( TAB1, event_name, ( values[1] )[0] );
00089             printf( TAB1, "PAPI_TOT_CYC:", ( values[1] )[1] );
00090         }
00091         if ( ( retval = PAPI_profil( profbuf[i], blength, start, scale,
00092                                      EventSet, PAPI_event, 0,
00093                                      profflags[i] ) ) != PAPI_OK )
00094             test_fail( __FILE__, __LINE__, "PAPI_profil", retval );
00095     }
00096 
00097     prof_head( blength, bucket, num_buckets,
00098                "address\t\t\tPOSIX\tINST_DEAR\n" );
00099     prof_out( start, num_profs, bucket, num_buckets, scale );
00100 
00101     retval = prof_check( num_profs, bucket, num_buckets );
00102 
00103     for ( i = 0; i < num_profs; i++ ) {
00104         free( profbuf[i] );
00105     }
00106 
00107     return ( retval );
00108 }
00109 
00110 
00111 int
00112 main( int argc, char **argv )
00113 {
00114     int num_events, num_tests = 6;
00115     long length;
00116     int retval, retval2;
00117     PAPI_hw_info_t *hw_info;
00118     PAPI_exe_info_t *prginfo;
00119     caddr_t start, end;
00120 
00121     prof_init( argc, argv, &prginfo );
00122 
00123     if ( ( hw_info = PAPI_get_hardware_info(  ) ) == NULL ) {
00124        test_fail( __FILE__, __LINE__, "PAPI_get_hardware_info", 0 );
00125     }
00126 
00127     if ( ( strncasecmp( hw_info->model_string, "Itanium", strlen( "Itanium" ) )
00128            != 0 ) &&
00129          ( strncasecmp( hw_info->model_string, "32", strlen( "32" ) ) != 0 ) )
00130         test_skip( __FILE__, __LINE__, "Test unsupported", PAPI_ENOIMPL );
00131 
00132     if ( TESTS_QUIET ) {
00133        test_skip( __FILE__, __LINE__,
00134              "Test deprecated in quiet mode for PAPI 3.6", 0 );
00135 
00136     }
00137 
00138     sprintf( event_name, "DATA_EAR_CACHE_LAT4" );
00139     if ( ( retval =
00140            PAPI_event_name_to_code( event_name, &PAPI_event ) ) != PAPI_OK )
00141         test_fail( __FILE__, __LINE__, "PAPI_event_name_to_code", retval );
00142 
00143     if ( ( retval = PAPI_create_eventset( &EventSet ) ) != PAPI_OK )
00144         test_fail( __FILE__, __LINE__, "PAPI_create_eventset", retval );
00145 
00146     if ( ( retval = PAPI_add_event( EventSet, PAPI_event ) ) != PAPI_OK )
00147         test_fail( __FILE__, __LINE__, "PAPI_add_event", retval );
00148 
00149     if ( ( retval = PAPI_add_event( EventSet, PAPI_TOT_CYC ) ) != PAPI_OK )
00150         test_fail( __FILE__, __LINE__, "PAPI_add_event", retval );
00151 
00152     num_events = 2;
00153     values = allocate_test_space( num_tests, num_events );
00154 
00155 /* use these lines to profile entire code address space */
00156     start = prginfo->address_info.text_start;
00157     end = prginfo->address_info.text_end;
00158     length = end - start;
00159     if ( length < 0 )
00160         test_fail( __FILE__, __LINE__, "Profile length < 0!", length );
00161 
00162     prof_print_address
00163         ( "Test earprofile: POSIX compatible event address register profiling.\n",
00164           prginfo );
00165     prof_print_prof_info( start, end, THRESHOLD, event_name );
00166     retval =
00167         do_profile( start, length, FULL_SCALE, THRESHOLD,
00168                     PAPI_PROFIL_BUCKET_16 );
00169 
00170     retval2 = PAPI_remove_event( EventSet, PAPI_event );
00171     if ( retval2 == PAPI_OK )
00172         retval2 = PAPI_remove_event( EventSet, PAPI_TOT_CYC );
00173     if ( retval2 != PAPI_OK )
00174         test_fail( __FILE__, __LINE__, "Can't remove events", retval2 );
00175 
00176     if ( retval )
00177         test_pass( __FILE__, values, num_tests );
00178     else
00179         test_fail( __FILE__, __LINE__, "No information in buffers", 1 );
00180     exit( 1 );
00181 }
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Defines