PAPI  5.3.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  long long value;
25  int code;
26  char event_names[MAX_EVENTS][PAPI_MAX_STR_LEN];
27  int event_codes[MAX_EVENTS];
28  long long event_values[MAX_EVENTS];
29  int total_events=0; /* events added so far */
30  int r;
31  const PAPI_component_info_t *cmpinfo = NULL;
32 
33  /* Set TESTS_QUIET variable */
34  tests_quiet( argc, argv );
35 
36  /* PAPI Initialization */
38  if ( retval != PAPI_VER_CURRENT ) {
39  test_fail(__FILE__, __LINE__,"PAPI_library_init failed\n",retval);
40  }
41 
42  if (!TESTS_QUIET) {
43  printf("Trying all appio events\n");
44  }
45 
46  numcmp = PAPI_num_components();
47 
48  for(cid=0; cid<numcmp; cid++) {
49 
50  if ( (cmpinfo = PAPI_get_component_info(cid)) == NULL) {
51  test_fail(__FILE__, __LINE__,"PAPI_get_component_info failed\n",-1);
52  }
53 
54  if (!TESTS_QUIET) {
55  printf("Component %d - %d events - %s\n", cid,
56  cmpinfo->num_native_events, cmpinfo->name);
57  }
58 
59  if ( strstr(cmpinfo->name, "appio") == NULL) {
60  continue;
61  }
62 
63  code = PAPI_NATIVE_MASK;
64 
65  r = PAPI_enum_cmp_event( &code, PAPI_ENUM_FIRST, cid );
66  /* Create and populate the EventSet */
67  EventSet = PAPI_NULL;
68 
69  retval = PAPI_create_eventset( &EventSet );
70  if (retval != PAPI_OK) {
71  test_fail(__FILE__, __LINE__, "PAPI_create_eventset()", retval);
72  }
73 
74  while ( r == PAPI_OK ) {
75 
76  retval = PAPI_event_code_to_name( code, event_names[total_events] );
77  if ( retval != PAPI_OK ) {
78  test_fail( __FILE__, __LINE__, "PAPI_event_code_to_name", retval );
79  }
80 
81  if (!TESTS_QUIET) {
82  printf("Added event %s (code=%#x)\n", event_names[total_events], code);
83  }
84  event_codes[total_events++] = code;
85  r = PAPI_enum_cmp_event( &code, PAPI_ENUM_EVENTS, cid );
86  }
87 
88  }
89 
90  int fdin,fdout;
91  const char* infile = "/etc/group";
92  printf("This program will read %s and write it to /dev/null\n", infile);
93  int bytes = 0;
94  char buf[1024];
95 
96  retval = PAPI_add_events( EventSet, event_codes, total_events);
97  if (retval != PAPI_OK) {
98  test_fail(__FILE__, __LINE__, "PAPI_add_events()", retval);
99  }
100 
101  retval = PAPI_start( EventSet );
102  if (retval != PAPI_OK) {
103  test_fail(__FILE__, __LINE__, "PAPI_start()", retval);
104  }
105 
106  fdin=open(infile, O_RDONLY);
107  if (fdin < 0) perror("Could not open file for reading: \n");
108  fdout = open("/dev/null", O_WRONLY);
109  if (fdout < 0) perror("Could not open /dev/null for writing: \n");
110 
111  while ((bytes = read(fdin, buf, 1024)) > 0) {
112  write(fdout, buf, bytes);
113  }
114 
115  retval = PAPI_stop( EventSet, event_values );
116  if (retval != PAPI_OK) {
117  test_fail(__FILE__, __LINE__, "PAPI_stop()", retval);
118  }
119  close(fdin);
120  close(fdout);
121 
122  int i;
123  if (!TESTS_QUIET) {
124  for ( i=0; i<total_events; i++ ) {
125  printf("%#x %-24s = %lld\n",
126  event_codes[i], event_names[i], event_values[i]);
127  }
128  }
129 
130  retval = PAPI_cleanup_eventset( EventSet );
131  if (retval != PAPI_OK) {
132  test_fail(__FILE__, __LINE__, "PAPI_cleanup_eventset()", retval);
133  }
134 
135  retval = PAPI_destroy_eventset( &EventSet );
136  if (retval != PAPI_OK) {
137  test_fail(__FILE__, __LINE__, "PAPI_destroy_eventset()", retval);
138  }
139 
140  if (total_events==0) {
141  test_skip(__FILE__,__LINE__,"No appio events found", 0);
142  }
143 
144  test_pass( __FILE__, NULL, 0 );
145 
146  retval = PAPI_cleanup_eventset( EventSet );
147  if (retval != PAPI_OK) {
148  test_fail(__FILE__, __LINE__, "PAPI_cleanup_eventset()", retval);
149  }
150 
151  retval = PAPI_destroy_eventset( &EventSet );
152  if (retval != PAPI_OK) {
153  test_fail(__FILE__, __LINE__, "PAPI_destroy_eventset()", retval);
154  }
155  return 0;
156 }
157 
158 // vim:set ai ts=4 sw=4 sts=4 et:
char name[PAPI_MAX_STR_LEN]
Definition: papi.h:625
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:2225
#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:803
#define PAPI_NULL
Definition: fpapi.h:13
#define PAPI_MAX_STR_LEN
Definition: fpapi.h:43
void test_skip(char *file, int line, char *call, int retval)
Definition: test_utils.c:614
int PAPI_num_components(void)
Definition: papi.c:4272
return PAPI_OK
Definition: linux-nvml.c:458
tests_quiet(argc, argv)
#define printf
Definition: papi_test.h:125
void double value
Definition: iozone.c:18781
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:5707
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:495
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
#define PAPI_VER_CURRENT
Definition: fpapi.h:14
int PAPI_enum_cmp_event(int *EventCode, int modifier, int cidx)
Definition: papi.c:1305
int PAPI_cleanup_eventset(int EventSet)
Definition: papi.c:2795
int PAPI_create_eventset(int *EventSet)
Definition: papi.c:1399
int PAPI_event_code_to_name(int EventCode, char *out)
Definition: papi.c:920
int EventSet
#define MAX_EVENTS
Prints the value of every appio event (by code)
int PAPI_destroy_eventset(int *EventSet)
Definition: papi.c:1937
int PAPI_start(int EventSet)
Definition: papi.c:2019
ssize_t retval
Definition: libasync.c:338
int main(int argc, char **argv)
List all appio events codes and names.