PAPI  5.4.0.0
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
appio_test_seek.c
Go to the documentation of this file.
1 /*
2  * Test case for appio
3  * Author: Tushar Mohan
4  * tusharmohan@gmail.com
5  *
6  * Description: This test case does a strided read of /etc/group
7  * and writes the output to stdout.
8  */
9 #include <papi.h>
10 #include <errno.h>
11 #include <stdio.h>
12 #include <stdlib.h>
13 #include <sys/types.h>
14 #include <sys/stat.h>
15 #include <fcntl.h>
16 #include <unistd.h>
17 
18 #include "papi_test.h"
19 
20 #define NUM_EVENTS 7
21 
22 int main(int argc, char** argv) {
23  int Events[NUM_EVENTS];
24  const char* names[NUM_EVENTS] = {"READ_CALLS", "READ_BYTES", "READ_BLOCK_SIZE", "READ_USEC", "SEEK_CALLS", "SEEK_USEC", "SEEK_ABS_STRIDE_SIZE"};
25  long long values[NUM_EVENTS];
26 
27  char *infile = "/etc/group";
28 
29  /* Set TESTS_QUIET variable */
30  tests_quiet( argc, argv );
31 
33  if (version != PAPI_VER_CURRENT) {
34  fprintf(stderr, "PAPI_library_init version mismatch\n");
35  exit(1);
36  }
37 
38  int fdin;
39  if (!TESTS_QUIET) printf("This program will do a strided read %s and write it to stdout\n", infile);
40  int retval;
41  int e;
42  for (e=0; e<NUM_EVENTS; e++) {
43  retval = PAPI_event_name_to_code((char*)names[e], &Events[e]);
44  if (retval != PAPI_OK) {
45  fprintf(stderr, "Error getting code for %s\n", names[e]);
46  exit(2);
47  }
48  }
49 
50  /* Start counting events */
51  if (PAPI_start_counters(Events, NUM_EVENTS) != PAPI_OK) {
52  fprintf(stderr, "Error in PAPI_start_counters\n");
53  exit(1);
54  }
55 
56  fdin=open(infile, O_RDONLY);
57  if (fdin < 0) perror("Could not open file for reading: \n");
58  int bytes = 0;
59  char buf[1024];
60 
61 
62 //if (PAPI_read_counters(values, NUM_EVENTS) != PAPI_OK)
63 // handle_error(1);
64 //printf("After reading the counters: %lld\n",values[0]);
65 
66  while ((bytes = read(fdin, buf, 32)) > 0) {
67  write(1, buf, bytes);
68  lseek(fdin, 16, SEEK_CUR);
69  }
70 
71  /* Closing the descriptors before doing the PAPI_stop
72  means, OPEN_FDS will be reported as zero, which is
73  right, since at the time of PAPI_stop, the descriptors
74  we opened have been closed */
75  close (fdin);
76 
77  /* Stop counting events */
78  if (PAPI_stop_counters(values, NUM_EVENTS) != PAPI_OK) {
79  fprintf(stderr, "Error in PAPI_stop_counters\n");
80  }
81 
82  if (!TESTS_QUIET) {
83  printf("----\n");
84  for (e=0; e<NUM_EVENTS; e++)
85  printf("%s: %lld\n", names[e], values[e]);
86  }
87  test_pass( __FILE__, NULL, 0 );
88  return 0;
89 }
ssize_t read(int fd, void *buf, size_t count)
Definition: appio.c:225
int close(int fd)
Definition: appio.c:175
static int Events[NUM_EVENTS]
Definition: init_fini.c:8
off_t lseek(int fd, off_t offset, int whence)
Definition: appio.c:210
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
Return codes and api definitions.
int TESTS_QUIET
Definition: test_utils.c:11
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:497
char buf[200]
Definition: iozone.c:19609
ssize_t write(int fd, const void *buf, size_t count)
Definition: appio.c:298
int PAPI_stop_counters(long long *values, int array_len)
Definition: papi_hl.c:803
#define NUM_EVENTS
char version[]
Definition: fileop.c:134
int PAPI_event_name_to_code(char *in, int *out)
Definition: papi.c:1010
int PAPI_start_counters(int *events, int array_len)
Definition: papi_hl.c:593
static long long values[NUM_EVENTS]
Definition: init_fini.c:10
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.
const char * names[NUM_EVENTS]
void exit()