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

Go to the source code of this file.

Macros

#define NUM_EVENTS   12
 

Functions

int main (int argc, char **argv)
 

Macro Definition Documentation

#define NUM_EVENTS   12

Definition at line 22 of file appio_test_read_write.c.

Function Documentation

int main ( int  argc,
char **  argv 
)

Definition at line 24 of file appio_test_read_write.c.

24  {
25  int Events[NUM_EVENTS];
26  const char* names[NUM_EVENTS] = {"OPEN_CALLS", "OPEN_FDS", "READ_CALLS", "READ_BYTES", "READ_USEC", "READ_ERR", "READ_INTERRUPTED", "READ_WOULD_BLOCK", "WRITE_CALLS","WRITE_BYTES","WRITE_USEC","WRITE_WOULD_BLOCK"};
27  long long values[NUM_EVENTS];
28 
29  char *infile = "/etc/group";
30 
31  /* Set TESTS_QUIET variable */
32  tests_quiet( argc, argv );
33 
35  if (version != PAPI_VER_CURRENT) {
36  fprintf(stderr, "PAPI_library_init version mismatch\n");
37  exit(1);
38  }
39 
40  int fdin;
41  if (!TESTS_QUIET) printf("This program will read %s and write it to /dev/null\n", infile);
42  int retval;
43  int e;
44  for (e=0; e<NUM_EVENTS; e++) {
45  retval = PAPI_event_name_to_code((char*)names[e], &Events[e]);
46  if (retval != PAPI_OK) {
47  fprintf(stderr, "Error getting code for %s\n", names[e]);
48  exit(2);
49  }
50  }
51 
52  /* Start counting events */
53  if (PAPI_start_counters(Events, NUM_EVENTS) != PAPI_OK) {
54  fprintf(stderr, "Error in PAPI_start_counters\n");
55  exit(1);
56  }
57 
58  fdin=open(infile, O_RDONLY);
59  if (fdin < 0) perror("Could not open file for reading: \n");
60  int fdout;
61  fdout=open("/dev/null", O_WRONLY);
62  if (fdout < 0) perror("Could not open file for writing: \n");
63  int bytes = 0;
64  char buf[1024];
65 
66 
67 //if (PAPI_read_counters(values, NUM_EVENTS) != PAPI_OK)
68 // handle_error(1);
69 //printf("After reading the counters: %lld\n",values[0]);
70 
71  while ((bytes = read(fdin, buf, 1024)) > 0) {
72  write(fdout, buf, bytes);
73  }
74 
75  /* Closing the descriptors before doing the PAPI_stop
76  means, OPEN_FDS will be reported as zero, which is
77  right, since at the time of PAPI_stop, the descriptors
78  we opened have been closed */
79  close (fdin);
80  close (fdout);
81 
82  /* Stop counting events */
83  if (PAPI_stop_counters(values, NUM_EVENTS) != PAPI_OK) {
84  fprintf(stderr, "Error in PAPI_stop_counters\n");
85  }
86 
87  if (!TESTS_QUIET) {
88  printf("----\n");
89  for (e=0; e<NUM_EVENTS; e++)
90  printf("%s: %lld\n", names[e], values[e]);
91  }
92  test_pass( __FILE__ );
93  return 0;
94 }
ssize_t read(int fd, void *buf, size_t count)
Definition: appio.c:225
int close(int fd)
Definition: appio.c:175
void test_pass(const char *filename)
Definition: test_utils.c:432
static int Events[NUM_EVENTS]
Definition: init_fini.c:8
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
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
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
char version[]
Definition: fileop.c:134
#define NUM_EVENTS
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
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:225
const char * names[NUM_EVENTS]
void exit()

Here is the call graph for this function: