PAPI  5.4.0.0
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
appio_values_by_code.c
Go to the documentation of this file.
1 /****************************/
2 /* THIS IS OPEN SOURCE CODE */
3 /****************************/
4 
14 #include <stdio.h>
15 #include <stdlib.h>
16 #include "papi_test.h"
17 
18 #define MAX_EVENTS 48
19 
20 int main (int argc, char **argv)
21 {
22  int retval,cid,numcmp;
23  int EventSet = PAPI_NULL;
24  int code;
25  char event_names[MAX_EVENTS][PAPI_MAX_STR_LEN];
26  int event_codes[MAX_EVENTS];
27  long long event_values[MAX_EVENTS];
28  int total_events=0; /* events added so far */
29  int r;
30  const PAPI_component_info_t *cmpinfo = NULL;
31 
32  /* Set TESTS_QUIET variable */
33  tests_quiet( argc, argv );
34 
35  /* PAPI Initialization */
37  if ( retval != PAPI_VER_CURRENT ) {
38  test_fail(__FILE__, __LINE__,"PAPI_library_init failed\n",retval);
39  }
40 
41  if (!TESTS_QUIET) {
42  printf("Trying all appio events\n");
43  }
44 
45  numcmp = PAPI_num_components();
46 
47  for(cid=0; cid<numcmp; cid++) {
48 
49  if ( (cmpinfo = PAPI_get_component_info(cid)) == NULL) {
50  test_fail(__FILE__, __LINE__,"PAPI_get_component_info failed\n",-1);
51  }
52 
53  if (!TESTS_QUIET) {
54  printf("Component %d - %d events - %s\n", cid,
55  cmpinfo->num_native_events, cmpinfo->name);
56  }
57 
58  if ( strstr(cmpinfo->name, "appio") == NULL) {
59  continue;
60  }
61 
62  code = PAPI_NATIVE_MASK;
63 
64  r = PAPI_enum_cmp_event( &code, PAPI_ENUM_FIRST, cid );
65  /* Create and populate the EventSet */
66  EventSet = PAPI_NULL;
67 
68  retval = PAPI_create_eventset( &EventSet );
69  if (retval != PAPI_OK) {
70  test_fail(__FILE__, __LINE__, "PAPI_create_eventset()", retval);
71  }
72 
73  while ( r == PAPI_OK ) {
74 
75  retval = PAPI_event_code_to_name( code, event_names[total_events] );
76  if ( retval != PAPI_OK ) {
77  test_fail( __FILE__, __LINE__, "PAPI_event_code_to_name", retval );
78  }
79 
80  if (!TESTS_QUIET) {
81  printf("Added event %s (code=%#x)\n", event_names[total_events], code);
82  }
83  event_codes[total_events++] = code;
84  r = PAPI_enum_cmp_event( &code, PAPI_ENUM_EVENTS, cid );
85  }
86 
87  }
88 
89  int fdin,fdout;
90  const char* infile = "/etc/group";
91  printf("This program will read %s and write it to /dev/null\n", infile);
92  int bytes = 0;
93  char buf[1024];
94 
95  retval = PAPI_add_events( EventSet, event_codes, total_events);
96  if (retval != PAPI_OK) {
97  test_fail(__FILE__, __LINE__, "PAPI_add_events()", retval);
98  }
99 
100  retval = PAPI_start( EventSet );
101  if (retval != PAPI_OK) {
102  test_fail(__FILE__, __LINE__, "PAPI_start()", retval);
103  }
104 
105  fdin=open(infile, O_RDONLY);
106  if (fdin < 0) perror("Could not open file for reading: \n");
107  fdout = open("/dev/null", O_WRONLY);
108  if (fdout < 0) perror("Could not open /dev/null for writing: \n");
109 
110  while ((bytes = read(fdin, buf, 1024)) > 0) {
111  write(fdout, buf, bytes);
112  }
113 
114  retval = PAPI_stop( EventSet, event_values );
115  if (retval != PAPI_OK) {
116  test_fail(__FILE__, __LINE__, "PAPI_stop()", retval);
117  }
118  close(fdin);
119  close(fdout);
120 
121  int i;
122  if (!TESTS_QUIET) {
123  for ( i=0; i<total_events; i++ ) {
124  printf("%#x %-24s = %lld\n",
125  event_codes[i], event_names[i], event_values[i]);
126  }
127  }
128 
129  retval = PAPI_cleanup_eventset( EventSet );
130  if (retval != PAPI_OK) {
131  test_fail(__FILE__, __LINE__, "PAPI_cleanup_eventset()", retval);
132  }
133 
134  retval = PAPI_destroy_eventset( &EventSet );
135  if (retval != PAPI_OK) {
136  test_fail(__FILE__, __LINE__, "PAPI_destroy_eventset()", retval);
137  }
138 
139  if (total_events==0) {
140  test_skip(__FILE__,__LINE__,"No appio events found", 0);
141  }
142 
143  test_pass( __FILE__, NULL, 0 );
144 
145  retval = PAPI_cleanup_eventset( EventSet );
146  if (retval != PAPI_OK) {
147  test_fail(__FILE__, __LINE__, "PAPI_cleanup_eventset()", retval);
148  }
149 
150  retval = PAPI_destroy_eventset( &EventSet );
151  if (retval != PAPI_OK) {
152  test_fail(__FILE__, __LINE__, "PAPI_destroy_eventset()", retval);
153  }
154  return 0;
155 }
156 
157 // vim:set ai ts=4 sw=4 sts=4 et:
char name[PAPI_MAX_STR_LEN]
Definition: papi.h:626
ssize_t read(int fd, void *buf, size_t count)
Definition: appio.c:225
int PAPI_stop(int EventSet, long long *values)
Definition: papi.c:2258
#define PAPI_NATIVE_MASK
int close(int fd)
Definition: appio.c:175
const PAPI_component_info_t * PAPI_get_component_info(int cidx)
Definition: papi.c:807
void test_skip(char *file, int line, char *call, int retval)
Definition: test_utils.c:614
#define PAPI_NULL
Definition: papi.h:290
int EventSet
Definition: data_range.c:25
int PAPI_num_components(void)
Definition: papi.c:4326
return PAPI_OK
Definition: linux-nvml.c:458
tests_quiet(argc, argv)
#define printf
Definition: papi_test.h:125
test_pass(__FILE__, NULL, 0)
int int argc
Definition: iozone.c:1609
int PAPI_add_events(int EventSet, int *Events, int number)
Definition: papi.c:5769
int TESTS_QUIET
Definition: test_utils.c:11
char ** argv
Definition: iozone.c:1610
test_fail(__FILE__, __LINE__,"PAPI_library_init", retval)
int open(const char *pathname, int flags, mode_t mode)
Definition: appio.c:184
int PAPI_library_init(int version)
Definition: papi.c:497
int i
Definition: fileop.c:140
char buf[200]
Definition: iozone.c:19609
ssize_t write(int fd, const void *buf, size_t count)
Definition: appio.c:298
int PAPI_enum_cmp_event(int *EventCode, int modifier, int cidx)
Definition: papi.c:1324
int PAPI_cleanup_eventset(int EventSet)
Definition: papi.c:2834
int PAPI_create_eventset(int *EventSet)
Definition: papi.c:1424
int PAPI_event_code_to_name(int EventCode, char *out)
Definition: papi.c:926
#define MAX_EVENTS
Prints the value of every appio event (by code)
int PAPI_destroy_eventset(int *EventSet)
Definition: papi.c:1971
#define PAPI_MAX_STR_LEN
Definition: papi.h:463
int PAPI_start(int EventSet)
Definition: papi.c:2053
ssize_t retval
Definition: libasync.c:338
#define PAPI_VER_CURRENT
Definition: papi.h:223
int main(int argc, char **argv)
List all appio events codes and names.