PAPI  5.4.0.0
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
zero_named.c
Go to the documentation of this file.
1 /* This test exercises the PAPI_{query, add, remove}_event APIs for PRESET events.
2  It more or less duplicates the functionality of the classic "zero" test.
3 */
4 
5 #include "papi_test.h"
6 
7 int
8 main( int argc, char **argv )
9 {
10  int retval, num_tests = 1, tmp;
11  int EventSet = PAPI_NULL;
12  int num_events = 2;
13  long long **values;
14  long long elapsed_us, elapsed_cyc, elapsed_virt_us, elapsed_virt_cyc;
15  char *event_names[] = {"PAPI_TOT_CYC","PAPI_TOT_INS"};
16  char add_event_str[PAPI_MAX_STR_LEN];
17  double cycles_error;
18 
19  /* Set TESTS_QUIET variable */
20  tests_quiet( argc, argv );
21 
22  /* Init the PAPI library */
24  if ( retval != PAPI_VER_CURRENT ) {
25  test_fail( __FILE__, __LINE__, "PAPI_library_init", retval );
26  }
27 
28  /* Verify that the named events exist */
29  retval = PAPI_query_named_event(event_names[0]);
30  if ( retval == PAPI_OK)
31  retval = PAPI_query_named_event(event_names[1]);
32  if ( retval != PAPI_OK )
33  test_fail( __FILE__, __LINE__, "PAPI_query_named_event", retval );
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  /* add the events named above */
41  retval = PAPI_add_named_event( EventSet, event_names[0] );
42  if ( retval != PAPI_OK ) {
43  sprintf( add_event_str, "PAPI_add_named_event[%s]", event_names[0] );
44  test_fail( __FILE__, __LINE__, add_event_str, retval );
45  }
46 
47  retval = PAPI_add_named_event( EventSet, event_names[1] );
48  if ( retval != PAPI_OK ) {
49  sprintf( add_event_str, "PAPI_add_named_event[%s]", event_names[1] );
50  test_fail( __FILE__, __LINE__, add_event_str, retval );
51  }
52 
53  values = allocate_test_space( num_tests, num_events );
54 
55  /* Gather before stats */
56  elapsed_us = PAPI_get_real_usec( );
57  elapsed_cyc = PAPI_get_real_cyc( );
58  elapsed_virt_us = PAPI_get_virt_usec( );
59  elapsed_virt_cyc = PAPI_get_virt_cyc( );
60 
61  /* Start PAPI */
62  retval = PAPI_start( EventSet );
63  if ( retval != PAPI_OK ) {
64  test_fail( __FILE__, __LINE__, "PAPI_start", retval );
65  }
66 
67  /* our test code */
69 
70  /* Stop PAPI */
71  retval = PAPI_stop( EventSet, values[0] );
72  if ( retval != PAPI_OK ) {
73  test_fail( __FILE__, __LINE__, "PAPI_stop", retval );
74  }
75 
76  /* Calculate total values */
77  elapsed_virt_us = PAPI_get_virt_usec( ) - elapsed_virt_us;
78  elapsed_virt_cyc = PAPI_get_virt_cyc( ) - elapsed_virt_cyc;
79  elapsed_us = PAPI_get_real_usec( ) - elapsed_us;
80  elapsed_cyc = PAPI_get_real_cyc( ) - elapsed_cyc;
81 
82  /* remove PAPI_TOT_CYC and PAPI_TOT_INS */
83  retval = PAPI_remove_named_event( EventSet, event_names[0] );
84  if ( retval != PAPI_OK ) {
85  sprintf( add_event_str, "PAPI_add_named_event[%s]", event_names[0] );
86  test_fail( __FILE__, __LINE__, add_event_str, retval );
87  }
88 
89  retval = PAPI_remove_named_event( EventSet, event_names[1] );
90  if ( retval != PAPI_OK ) {
91  sprintf( add_event_str, "PAPI_add_named_event[%s]", event_names[1] );
92  test_fail( __FILE__, __LINE__, add_event_str, retval );
93  }
94 
95  if ( !TESTS_QUIET ) {
96  printf( "PAPI_{query, add, remove}_named_event API test.\n" );
97  printf( "-----------------------------------------------\n" );
98  tmp = PAPI_get_opt( PAPI_DEFDOM, NULL );
99  printf( "Default domain is: %d (%s)\n", tmp,
101  tmp = PAPI_get_opt( PAPI_DEFGRN, NULL );
102  printf( "Default granularity is: %d (%s)\n", tmp,
104  printf( "Using %d iterations of c += a*b\n", NUM_FLOPS );
105  printf( "-------------------------------------------------------------------------\n" );
106 
107  printf( "Test type : \t 1\n" );
108 
109  /* cycles is first, other event second */
110  sprintf( add_event_str, "%-12s : \t", event_names[0] );
111  printf( TAB1, add_event_str, values[0][0] );
112  sprintf( add_event_str, "%-12s : \t", event_names[1] );
113  printf( TAB1, add_event_str, values[0][1] );
114 
115  printf( TAB1, "Real usec : \t", elapsed_us );
116  printf( TAB1, "Real cycles : \t", elapsed_cyc );
117  printf( TAB1, "Virt usec : \t", elapsed_virt_us );
118  printf( TAB1, "Virt cycles : \t", elapsed_virt_cyc );
119 
120  printf( "-------------------------------------------------------------------------\n" );
121 
122  printf( "Verification: PAPI_TOT_CYC should be roughly real_cycles\n" );
123  cycles_error=100.0*((double)values[0][0] - (double)elapsed_cyc)/
124  (double)values[0][0];
125  if (cycles_error>10.0) {
126  printf("Error of %.2f%%\n",cycles_error);
127  test_fail( __FILE__, __LINE__, "validation", 0 );
128  }
129 
130  }
131  test_pass( __FILE__, values, num_tests );
132 
133  return 0;
134 }
sprintf(splash[splash_line++],"\tIozone: Performance Test of File I/O\n")
int PAPI_stop(int EventSet, long long *values)
Definition: papi.c:2258
#define NUM_FLOPS
long long PAPI_get_virt_usec(void)
Definition: papi.c:6298
int PAPI_add_named_event(int EventSet, char *EventName)
Definition: papi.c:1835
char * stringify_granularity(int granularity)
Definition: test_utils.c:429
long long PAPI_get_virt_cyc(void)
Definition: papi.c:6226
#define PAPI_NULL
Definition: papi.h:290
#define TAB1
Definition: papi_test.h:112
int EventSet
Definition: data_range.c:25
int num_events
return PAPI_OK
Definition: linux-nvml.c:458
tests_quiet(argc, argv)
#define printf
Definition: papi_test.h:125
static double
Definition: fileop.c:1281
test_pass(__FILE__, NULL, 0)
int int argc
Definition: iozone.c:1609
int TESTS_QUIET
Definition: test_utils.c:11
char ** argv
Definition: iozone.c:1610
test_fail(__FILE__, __LINE__,"PAPI_library_init", retval)
int PAPI_library_init(int version)
Definition: papi.c:497
char * stringify_all_domains(int domains)
Definition: test_utils.c:369
int PAPI_get_opt(int option, PAPI_option_t *ptr)
Definition: papi.c:4082
long long elapsed_cyc
Definition: zero_fork.c:43
#define PAPI_DEFGRN
Definition: papi.h:432
int PAPI_create_eventset(int *EventSet)
Definition: papi.c:1424
int num_tests
Definition: zero_fork.c:46
void do_flops(int n)
Definition: multiplex.c:23
long long PAPI_get_real_usec(void)
Definition: papi.c:6190
int PAPI_query_named_event(char *EventName)
Definition: papi.c:767
#define PAPI_DEFDOM
Definition: papi.h:430
#define PAPI_MAX_STR_LEN
Definition: papi.h:463
long long PAPI_get_real_cyc(void)
Definition: papi.c:6143
int PAPI_start(int EventSet)
Definition: papi.c:2053
static long long values[NUM_EVENTS]
Definition: init_fini.c:10
ssize_t retval
Definition: libasync.c:338
long long tmp
Definition: iozone.c:12031
long long elapsed_us
Definition: zero_fork.c:43
long long ** allocate_test_space(int num_tests, int num_events)
Definition: test_utils.c:107
#define PAPI_VER_CURRENT
Definition: papi.h:223
int PAPI_remove_named_event(int EventSet, char *EventName)
Definition: papi.c:1919
int main(int argc, char **argv)
List all appio events codes and names.