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

Go to the source code of this file.

Macros

#define NUM_EVENTS   11
 Prints the values of several (but not all) appio events specified by names. More...
 

Functions

int main (int argc, char **argv)
 

Macro Definition Documentation

#define NUM_EVENTS   11
Author
Tushar Mohan

test case for the appio component (adapted from test in linux-net component)

Definition at line 25 of file appio_values_by_name.c.

Function Documentation

int main ( int  argc,
char **  argv 
)

Definition at line 27 of file appio_values_by_name.c.

28 {
29  int i, retval;
30  int EventSet = PAPI_NULL;
31  char *event_name[NUM_EVENTS] = {
32  "READ_BYTES",
33  "READ_CALLS",
34  "READ_USEC",
35  "READ_EOF",
36  "READ_SHORT",
37  "READ_ERR",
38  "WRITE_BYTES",
39  "WRITE_CALLS",
40  "WRITE_USEC",
41  "WRITE_ERR",
42  "WRITE_SHORT"
43  };
44  int event_code[NUM_EVENTS] = { 0, 0, 0, 0, 0, 0, 0, 0, 0};
45  long long event_value[NUM_EVENTS];
46  int total_events=0;
47 
48  /* Set TESTS_QUIET variable */
49  tests_quiet( argc, argv );
50 
51  /* PAPI Initialization */
53  if ( retval != PAPI_VER_CURRENT ) {
54  test_fail(__FILE__, __LINE__,"PAPI_library_init failed\n",retval);
55  }
56 
57  if (!TESTS_QUIET) {
58  printf("Appio events by name\n");
59  }
60 
61  /* Map names to codes */
62  for ( i=0; i<NUM_EVENTS; i++ ) {
63  retval = PAPI_event_name_to_code( event_name[i], &event_code[i]);
64  if ( retval != PAPI_OK ) {
65  test_fail( __FILE__, __LINE__, "PAPI_event_name_to_code", retval );
66  }
67 
68  total_events++;
69  }
70 
71  int fdin,fdout;
72  const char* infile = "/etc/group";
73  if (!TESTS_QUIET) printf("This program will read %s and write it to /dev/null\n", infile);
74  int bytes = 0;
75  char buf[1024];
76 
77  /* Create and populate the EventSet */
78  EventSet = PAPI_NULL;
79 
80  retval = PAPI_create_eventset( &EventSet );
81  if (retval != PAPI_OK) {
82  test_fail(__FILE__, __LINE__, "PAPI_create_eventset()", retval);
83  }
84 
85  retval = PAPI_add_events( EventSet, event_code, NUM_EVENTS);
86  if (retval != PAPI_OK) {
87  test_fail(__FILE__, __LINE__, "PAPI_add_events()", retval);
88  }
89 
90  retval = PAPI_start( EventSet );
91  if (retval != PAPI_OK) {
92  test_fail(__FILE__, __LINE__, "PAPI_start()", retval);
93  }
94 
95  fdin=open(infile, O_RDONLY);
96  if (fdin < 0) perror("Could not open file for reading: \n");
97  fdout=open("/dev/null", O_WRONLY);
98  if (fdout < 0) perror("Could not open /dev/null for writing: \n");
99 
100  while ((bytes = read(fdin, buf, 1024)) > 0) {
101  write(fdout, buf, bytes);
102  }
103  close(fdin);
104  close(fdout);
105 
106  retval = PAPI_stop( EventSet, event_value );
107  if (retval != PAPI_OK) {
108  test_fail(__FILE__, __LINE__, "PAPI_start()", retval);
109  }
110 
111  if (!TESTS_QUIET) {
112  for ( i=0; i<NUM_EVENTS; i++ ) {
113  printf("%#x %-24s = %lld\n",
114  event_code[i], event_name[i], event_value[i]);
115  }
116  }
117 
118  retval = PAPI_cleanup_eventset( EventSet );
119  if (retval != PAPI_OK) {
120  test_fail(__FILE__, __LINE__, "PAPI_cleanup_eventset()", retval);
121  }
122 
123  retval = PAPI_destroy_eventset( &EventSet );
124  if (retval != PAPI_OK) {
125  test_fail(__FILE__, __LINE__, "PAPI_destroy_eventset()", retval);
126  }
127 
128  if (total_events==0) {
129  test_skip(__FILE__,__LINE__,"No appio events found", 0);
130  }
131 
132  test_pass( __FILE__, NULL, 0 );
133 
134  return 0;
135 }
char event_name[2][PAPI_MAX_STR_LEN]
Definition: data_range.c:23
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
int close(int fd)
Definition: appio.c:175
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
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
#define NUM_EVENTS
Prints the values of several (but not all) appio events specified by names.
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_cleanup_eventset(int EventSet)
Definition: papi.c:2834
int PAPI_create_eventset(int *EventSet)
Definition: papi.c:1424
int PAPI_event_name_to_code(char *in, int *out)
Definition: papi.c:1010
int PAPI_destroy_eventset(int *EventSet)
Definition: papi.c:1971
int PAPI_start(int EventSet)
Definition: papi.c:2053
ssize_t retval
Definition: libasync.c:338
#define PAPI_VER_CURRENT
Definition: papi.h:223

Here is the call graph for this function: