PAPI  5.6.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 27 of file appio_values_by_name.c.

Function Documentation

int main ( int  argc,
char **  argv 
)

Definition at line 29 of file appio_values_by_name.c.

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