PAPI  5.6.0.0
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
all_events.c
Go to the documentation of this file.
1 /* This file tries to add,start,stop, and remove all pre-defined events.
2  * It is meant not to test the accuracy of the mapping but to make sure
3  * that all events in the component will at least start (Helps to
4  * catch typos).
5  *
6  * Author: Kevin London
7  * london@cs.utk.edu
8  */
9 
10 #include <stdio.h>
11 #include <stdlib.h>
12 
13 #include "papi.h"
14 #include "papi_test.h"
15 
16 int
17 main( int argc, char **argv )
18 {
19  int retval, i;
20  int EventSet = PAPI_NULL, count = 0, err_count = 0;
21  long long values;
22  PAPI_event_info_t info;
23  int quiet=0;
24  char error_message[BUFSIZ];
25 
26  /* Set TESTS_QUIET variable */
27  quiet=tests_quiet( argc, argv );
28 
29  if (!quiet) {
30  printf("\nTrying all pre-defined events:\n");
31  }
32 
33  /* Initialize PAPI */
35  if ( retval != PAPI_VER_CURRENT ) {
36  test_fail( __FILE__, __LINE__, "PAPI_library_init", retval );
37  }
38 
39  /* Create an EventSet */
40  retval = PAPI_create_eventset( &EventSet );
41  if ( retval != PAPI_OK ) {
42  test_fail( __FILE__, __LINE__, "PAPI_create_eventset", retval );
43  }
44 
45  /* Add all preset events */
46  for ( i = 0; i < PAPI_MAX_PRESET_EVENTS; i++ ) {
47 
48  if ( PAPI_get_event_info( PAPI_PRESET_MASK | i, &info ) != PAPI_OK )
49  continue;
50 
51  if ( !( info.count ) )
52  continue;
53 
54  if (!quiet) printf( "Adding %-14s", info.symbol );
55 
56  retval = PAPI_add_event( EventSet, ( int ) info.event_code );
57  if ( retval != PAPI_OK ) {
58  if (!quiet) {
59  printf("Error adding event %s\n",info.symbol);
60  if (retval==PAPI_ECNFLCT) {
61  printf("Probably NMI watchdog related\n");
62  }
63  }
64  if (retval==PAPI_ECNFLCT) {
65  sprintf(error_message,"Problem adding %s (probably NMI Watchdog related)",info.symbol);
66  }
67  else {
68  sprintf(error_message,"Problem adding %s",info.symbol);
69  }
70  test_warn( __FILE__, __LINE__, error_message, retval );
71  err_count++;
72  } else {
73  retval = PAPI_start( EventSet );
74  if ( retval != PAPI_OK ) {
75  PAPI_perror( "PAPI_start" );
76  err_count++;
77  } else {
78  retval = PAPI_stop( EventSet, &values );
79  if ( retval != PAPI_OK ) {
80  PAPI_perror( "PAPI_stop" );
81  err_count++;
82  } else {
83  if (!quiet) printf( "successful\n" );
84  count++;
85  }
86  }
87  retval = PAPI_remove_event( EventSet, ( int ) info.event_code );
88  if ( retval != PAPI_OK )
89  test_fail( __FILE__, __LINE__, "PAPI_remove_event", retval );
90  }
91  }
92  retval = PAPI_destroy_eventset( &EventSet );
93  if ( retval != PAPI_OK )
94  test_fail( __FILE__, __LINE__, "PAPI_destroy_eventset", retval );
95 
96  if (!quiet) {
97  printf( "Successfully added, started and stopped %d events.\n", count );
98  }
99 
100  if ( err_count ) {
101  if (!quiet) printf( "Failed to add, start or stop %d events.\n", err_count );
102  }
103 
104  if (count<=0) {
105  test_fail( __FILE__, __LINE__, "No events added", 1 );
106  }
107 
108  test_pass( __FILE__ );
109 
110  return 0;
111 
112 }
sprintf(splash[splash_line++],"\tIozone: Performance Test of File I/O\n")
unsigned int count
Definition: papi.h:987
int PAPI_stop(int EventSet, long long *values)
Definition: papi.c:2314
void test_pass(const char *filename)
Definition: test_utils.c:432
int PAPI_add_event(int EventSet, int EventCode)
Definition: papi.c:1663
int PAPI_remove_event(int EventSet, int EventCode)
Definition: papi.c:1758
#define PAPI_NULL
Definition: papi.h:292
#define PAPI_MAX_PRESET_EVENTS
char symbol[PAPI_HUGE_STR_LEN]
Definition: papi.h:966
int EventSet
return PAPI_OK
Definition: linux-nvml.c:497
int count
Definition: iozone.c:22422
#define PAPI_PRESET_MASK
void test_warn(const char *file, int line, const char *call, int retval)
Definition: test_utils.c:522
int int argc
Definition: iozone.c:1609
Return codes and api definitions.
int PAPI_get_event_info(int EventCode, PAPI_event_info_t *info)
Definition: papi.c:835
char ** argv
Definition: iozone.c:1610
int PAPI_library_init(int version)
Definition: papi.c:500
int i
Definition: fileop.c:140
int quiet
Definition: rapl_overflow.c:18
#define PAPI_ECNFLCT
Definition: papi.h:261
int PAPI_create_eventset(int *EventSet)
Definition: papi.c:1464
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_destroy_eventset(int *EventSet)
Definition: papi.c:2014
int PAPI_start(int EventSet)
Definition: papi.c:2096
void PAPI_perror(const char *msg)
Definition: papi.c:4653
unsigned int event_code
Definition: papi.h:964
static long long values[NUM_EVENTS]
Definition: init_fini.c:10
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.