remove_events.c File Reference

Include dependency graph for remove_events.c:

Go to the source code of this file.

Functions

int main (int argc, char **argv)

Function Documentation

int main ( int  argc,
char **  argv 
)

Definition at line 10 of file remove_events.c.

00011 {
00012     int retval;
00013     int EventSet = PAPI_NULL;
00014     long long values1[2],values2[2];
00015     char *event_names[] = {"PAPI_TOT_CYC","PAPI_TOT_INS"};
00016     char add_event_str[PAPI_MAX_STR_LEN];
00017     double instructions_error;
00018     long long old_instructions;
00019 
00020     /* Set TESTS_QUIET variable */
00021     tests_quiet( argc, argv );  
00022 
00023     /* Init the PAPI library */
00024     retval = PAPI_library_init( PAPI_VER_CURRENT );
00025     if ( retval != PAPI_VER_CURRENT ) {
00026        test_fail( __FILE__, __LINE__, "PAPI_library_init", retval );
00027     }
00028         
00029     /* Create an empty event set */
00030     retval = PAPI_create_eventset( &EventSet );
00031     if ( retval != PAPI_OK ) {
00032        test_fail( __FILE__, __LINE__, "PAPI_create_eventset", retval );
00033     }   
00034 
00035     /* add the events named above */
00036     retval = PAPI_add_named_event( EventSet, event_names[0] );
00037     if ( retval != PAPI_OK ) {
00038         sprintf( add_event_str, "PAPI_add_named_event[%s]", event_names[0] );
00039         test_fail( __FILE__, __LINE__, add_event_str, retval );
00040     }
00041     
00042     retval = PAPI_add_named_event( EventSet, event_names[1] );
00043     if ( retval != PAPI_OK ) {
00044         sprintf( add_event_str, "PAPI_add_named_event[%s]", event_names[1] );
00045         test_fail( __FILE__, __LINE__, add_event_str, retval );
00046     }
00047 
00048     /* Start PAPI */
00049     retval = PAPI_start( EventSet );
00050     if ( retval != PAPI_OK ) {
00051        test_fail( __FILE__, __LINE__, "PAPI_start", retval );
00052     }
00053 
00054     /* our test code */
00055     do_flops( NUM_FLOPS );
00056 
00057     /* Stop PAPI */
00058     retval = PAPI_stop( EventSet, values1 );
00059     if ( retval != PAPI_OK ) {
00060        test_fail( __FILE__, __LINE__, "PAPI_stop", retval );
00061     }
00062 
00063 
00064     old_instructions=values1[1];
00065     
00066     if ( !TESTS_QUIET ) {
00067 
00068        printf( "========================\n" );
00069 
00070        /* cycles is first, other event second */
00071        sprintf( add_event_str, "%-12s : \t", event_names[0] );
00072        printf( TAB1, add_event_str, values1[0] );
00073        sprintf( add_event_str, "%-12s : \t", event_names[1] );
00074            printf( TAB1, add_event_str, values1[1] );
00075     }
00076 
00077 
00078     /* remove PAPI_TOT_CYC */
00079     retval = PAPI_remove_named_event( EventSet, event_names[0] );
00080     if ( retval != PAPI_OK ) {
00081         sprintf( add_event_str, "PAPI_add_named_event[%s]", event_names[0] );
00082         test_fail( __FILE__, __LINE__, add_event_str, retval );
00083     }
00084     
00085 
00086     /* Start PAPI */
00087     retval = PAPI_start( EventSet );
00088     if ( retval != PAPI_OK ) {
00089        test_fail( __FILE__, __LINE__, "PAPI_start", retval );
00090     }
00091 
00092     /* our test code */
00093     do_flops( NUM_FLOPS );
00094 
00095     /* Stop PAPI */
00096     retval = PAPI_stop( EventSet, values2 );
00097     if ( retval != PAPI_OK ) {
00098        test_fail( __FILE__, __LINE__, "PAPI_stop", retval );
00099     }
00100 
00101 
00102     /* test if after removing the event, the second event */
00103     /* still points to the proper native event            */
00104 
00105     /* this only works if IPC != 1 */
00106 
00107     if ( !TESTS_QUIET ) {
00108 
00109        printf( "==========================\n" );
00110        printf( "After removing PAP_TOT_CYC\n");
00111        sprintf( add_event_str, "%-12s : \t", event_names[1] );
00112            printf( TAB1, add_event_str, values2[0] );
00113 
00114        instructions_error=((double)old_instructions - (double)values2[0])/
00115          (double)old_instructions;
00116        if (instructions_error>10.0) {
00117          printf("Error of %.2f%%\n",instructions_error);
00118          test_fail( __FILE__, __LINE__, "validation", 0 );
00119        }
00120 
00121     }
00122     test_pass( __FILE__, NULL, 0 );
00123     
00124     return 0;
00125 }

Here is the call graph for this function:


Generated on 26 Jan 2016 for PAPI by  doxygen 1.6.1