PAPI  5.6.0.0
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
appio_values_by_code.c File Reference
Include dependency graph for appio_values_by_code.c:

Go to the source code of this file.

Macros

#define MAX_EVENTS   48
 Prints the value of every appio event (by code) More...
 

Functions

int main (int argc, char **argv)
 

Macro Definition Documentation

#define MAX_EVENTS   48
Author
Tushar Mohan (adapted from code in linux-net) test case for the appio component

Definition at line 23 of file appio_values_by_code.c.

Function Documentation

int main ( int  argc,
char **  argv 
)

Definition at line 25 of file appio_values_by_code.c.

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

Here is the call graph for this function: