PAPI  5.6.0.0
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
remove_events.c
Go to the documentation of this file.
1 /* This test checks if removing events works properly at the low level
2 
3  by Vince Weaver (vweaver1@eecs.utk.edu)
4 
5  */
6 
7 #include <stdio.h>
8 
9 #include "papi.h"
10 #include "papi_test.h"
11 
12 #include "do_loops.h"
13 
14 int
15 main( int argc, char **argv )
16 {
17  int retval;
18  int EventSet = PAPI_NULL;
19  long long values1[2],values2[2];
20  const char *event_names[] = {"PAPI_TOT_CYC","PAPI_TOT_INS"};
21  char add_event_str[PAPI_MAX_STR_LEN];
22  double instructions_error;
23  long long old_instructions;
24  int quiet;
25 
26  /* Set TESTS_QUIET variable */
27  quiet = tests_quiet( argc, argv );
28 
29  /* Init the PAPI library */
31  if ( retval != PAPI_VER_CURRENT ) {
32  test_fail( __FILE__, __LINE__, "PAPI_library_init", retval );
33  }
34 
35  /* Create an empty event set */
36  retval = PAPI_create_eventset( &EventSet );
37  if ( retval != PAPI_OK ) {
38  test_fail( __FILE__, __LINE__, "PAPI_create_eventset", retval );
39  }
40 
41  /* add the events named above */
42  retval = PAPI_add_named_event( EventSet, event_names[0] );
43  if ( retval != PAPI_OK ) {
44  sprintf( add_event_str, "PAPI_add_named_event[%s]", event_names[0] );
45  if (!quiet) printf("Trouble %s\n",add_event_str);
46  test_skip( __FILE__, __LINE__, add_event_str, retval );
47  }
48 
49  retval = PAPI_add_named_event( EventSet, event_names[1] );
50  if ( retval != PAPI_OK ) {
51  sprintf( add_event_str, "PAPI_add_named_event[%s]", event_names[1] );
52  test_fail( __FILE__, __LINE__, add_event_str, retval );
53  }
54 
55  /* Start PAPI */
56  retval = PAPI_start( EventSet );
57  if ( retval != PAPI_OK ) {
58  test_fail( __FILE__, __LINE__, "PAPI_start", retval );
59  }
60 
61  /* our test code */
63 
64  /* Stop PAPI */
65  retval = PAPI_stop( EventSet, values1 );
66  if ( retval != PAPI_OK ) {
67  test_fail( __FILE__, __LINE__, "PAPI_stop", retval );
68  }
69 
70 
71  old_instructions=values1[1];
72 
73  if ( !quiet ) {
74 
75  printf( "========================\n" );
76 
77  /* cycles is first, other event second */
78  sprintf( add_event_str, "%-12s : \t", event_names[0] );
79  printf( TAB1, add_event_str, values1[0] );
80  sprintf( add_event_str, "%-12s : \t", event_names[1] );
81  printf( TAB1, add_event_str, values1[1] );
82  }
83 
84 
85  /* remove PAPI_TOT_CYC */
86  retval = PAPI_remove_named_event( EventSet, event_names[0] );
87  if ( retval != PAPI_OK ) {
88  sprintf( add_event_str, "PAPI_add_named_event[%s]", event_names[0] );
89  test_fail( __FILE__, __LINE__, add_event_str, retval );
90  }
91 
92 
93  /* Start PAPI */
94  retval = PAPI_start( EventSet );
95  if ( retval != PAPI_OK ) {
96  test_fail( __FILE__, __LINE__, "PAPI_start", retval );
97  }
98 
99  /* our test code */
100  do_flops( NUM_FLOPS );
101 
102  /* Stop PAPI */
103  retval = PAPI_stop( EventSet, values2 );
104  if ( retval != PAPI_OK ) {
105  test_fail( __FILE__, __LINE__, "PAPI_stop", retval );
106  }
107 
108 
109  /* test if after removing the event, the second event */
110  /* still points to the proper native event */
111 
112  /* this only works if IPC != 1 */
113 
114  if ( !quiet ) {
115 
116  printf( "==========================\n" );
117  printf( "After removing PAP_TOT_CYC\n");
118  sprintf( add_event_str, "%-12s : \t", event_names[1] );
119  printf( TAB1, add_event_str, values2[0] );
120 
121  instructions_error=((double)old_instructions - (double)values2[0])/
122  (double)old_instructions;
123  if (instructions_error>10.0) {
124  printf("Error of %.2f%%\n",instructions_error);
125  test_fail( __FILE__, __LINE__, "validation", 0 );
126  }
127 
128  }
129  test_pass( __FILE__ );
130 
131  return 0;
132 }
sprintf(splash[splash_line++],"\tIozone: Performance Test of File I/O\n")
int PAPI_stop(int EventSet, long long *values)
Definition: papi.c:2314
void test_pass(const char *filename)
Definition: test_utils.c:432
#define PAPI_NULL
Definition: papi.h:292
#define TAB1
Definition: papi_test.h:88
int EventSet
return PAPI_OK
Definition: linux-nvml.c:497
#define NUM_FLOPS
Definition: sdsc-mpx.c:24
static double
Definition: fileop.c:1281
int int argc
Definition: iozone.c:1609
Return codes and api definitions.
void test_skip(const char *file, int line, const char *call, int retval)
Definition: test_utils.c:559
int PAPI_add_named_event(int EventSet, const char *EventName)
Definition: papi.c:1876
char ** argv
Definition: iozone.c:1610
int PAPI_library_init(int version)
Definition: papi.c:500
int quiet
Definition: rapl_overflow.c:18
int PAPI_create_eventset(int *EventSet)
Definition: papi.c:1464
void do_flops(int n)
Definition: multiplex.c:23
printf("\tTry: -i 0 -i 1 \n\n")
int tests_quiet(int argc, char **argv)
Definition: test_utils.c:376
void test_fail(const char *file, int line, const char *call, int retval)
Definition: test_utils.c:468
int PAPI_remove_named_event(int EventSet, const char *EventName)
Definition: papi.c:1961
#define PAPI_MAX_STR_LEN
Definition: papi.h:465
int PAPI_start(int EventSet)
Definition: papi.c:2096
ssize_t retval
Definition: libasync.c:338
#define PAPI_VER_CURRENT
Definition: papi.h:225
int main(int argc, char **argv)
List all appio events codes and names.