|
PAPI
5.0.1.0
|
00001 /* This file performs the following test: 00002 00003 - make an event set with PAPI_TOT_INS and PAPI_TOT_CYC. 00004 - enable per node counting 00005 - enable full domain counting 00006 - sleeps for 5 seconds 00007 - print the results 00008 */ 00009 00010 #include <stdlib.h> 00011 #include <stdio.h> 00012 #include <unistd.h> 00013 #include <errno.h> 00014 #include <sys/types.h> 00015 #include <memory.h> 00016 #include <malloc.h> 00017 #include "papi_test.h" 00018 00019 int 00020 main( ) 00021 { 00022 int ncpu, nctr, i, actual_domain; 00023 int retval; 00024 int EventSet = PAPI_NULL; 00025 long long *values; 00026 long long elapsed_us, elapsed_cyc; 00027 PAPI_option_t options; 00028 00029 retval = PAPI_library_init( PAPI_VER_CURRENT ); 00030 if ( retval != PAPI_VER_CURRENT ) { 00031 fprintf( stderr, "Library mismatch: code %d, library %d\n", retval, 00032 PAPI_VER_CURRENT ); 00033 exit( 1 ); 00034 } 00035 00036 if ( PAPI_create_eventset( &EventSet ) != PAPI_OK ) 00037 exit( 1 ); 00038 00039 /* Set the domain as high as it will go. */ 00040 00041 options.domain.eventset = EventSet; 00042 options.domain.domain = PAPI_DOM_ALL; 00043 retval = PAPI_set_opt( PAPI_DOMAIN, &options ); 00044 if ( retval != PAPI_OK ) 00045 exit( 1 ); 00046 actual_domain = options.domain.domain; 00047 00048 /* This should only happen to an empty eventset */ 00049 00050 options.granularity.eventset = EventSet; 00051 options.granularity.granularity = PAPI_GRN_SYS_CPU; 00052 retval = PAPI_set_opt( PAPI_GRANUL, &options ); 00053 if ( retval != PAPI_OK ) 00054 exit( 1 ); 00055 00056 /* Malloc the output array */ 00057 00058 ncpu = PAPI_get_opt( PAPI_MAX_CPUS, NULL ); 00059 nctr = PAPI_get_opt( PAPI_MAX_HWCTRS, NULL ); 00060 values = ( long long * ) malloc( ncpu * nctr * sizeof ( long long ) ); 00061 memset( values, 0x0, ( ncpu * nctr * sizeof ( long long ) ) ); 00062 00063 /* Add the counters */ 00064 00065 if ( PAPI_add_event( EventSet, PAPI_TOT_CYC ) != PAPI_OK ) 00066 exit( 1 ); 00067 00068 if ( PAPI_add_event( EventSet, PAPI_TOT_INS ) != PAPI_OK ) 00069 exit( 1 ); 00070 00071 elapsed_us = PAPI_get_real_usec( ); 00072 00073 elapsed_cyc = PAPI_get_real_cyc( ); 00074 00075 retval = PAPI_start( EventSet ); 00076 if ( retval != PAPI_OK ) 00077 exit( 1 ); 00078 00079 sleep( 5 ); 00080 00081 retval = PAPI_stop( EventSet, values ); 00082 if ( retval != PAPI_OK ) 00083 exit( 1 ); 00084 00085 elapsed_us = PAPI_get_real_usec( ) - elapsed_us; 00086 00087 elapsed_cyc = PAPI_get_real_cyc( ) - elapsed_cyc; 00088 00089 printf( "Test case: per node\n" ); 00090 printf( "-------------------\n\n" ); 00091 00092 printf( "This machine has %d cpus, each with %d counters.\n", ncpu, nctr ); 00093 printf( "Test case asked for: PAPI_DOM_ALL\n" ); 00094 printf( "Test case got: " ); 00095 if ( actual_domain & PAPI_DOM_USER ) 00096 printf( "PAPI_DOM_USER " ); 00097 if ( actual_domain & PAPI_DOM_KERNEL ) 00098 printf( "PAPI_DOM_KERNEL " ); 00099 if ( actual_domain & PAPI_DOM_OTHER ) 00100 printf( "PAPI_DOM_OTHER " ); 00101 printf( "\n" ); 00102 00103 for ( i = 0; i < ncpu; i++ ) { 00104 printf( "CPU %d\n", i ); 00105 printf( "PAPI_TOT_CYC: \t%lld\n", values[0 + i * nctr] ); 00106 printf( "PAPI_TOT_INS: \t%lld\n", values[1 + i * nctr] ); 00107 } 00108 00109 printf 00110 ( "\n-------------------------------------------------------------------------\n" ); 00111 00112 printf( "Real usec : \t%lld\n", elapsed_us ); 00113 printf( "Real cycles : \t%lld\n", elapsed_cyc ); 00114 00115 printf 00116 ( "-------------------------------------------------------------------------\n" ); 00117 00118 free( values ); 00119 00120 PAPI_shutdown( ); 00121 00122 exit( 0 ); 00123 }