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

Go to the source code of this file.

Macros

#define NUM_EVENTS   8
 

Functions

int main (int argc, char **argv)
 

Macro Definition Documentation

#define NUM_EVENTS   8

Definition at line 22 of file appio_test_fread_fwrite.c.

Function Documentation

int main ( int  argc,
char **  argv 
)

Definition at line 24 of file appio_test_fread_fwrite.c.

24  {
25  int Events[NUM_EVENTS];
26  const char* names[NUM_EVENTS] = {"READ_CALLS", "READ_BYTES","READ_USEC","READ_ERR", "READ_EOF", "WRITE_CALLS","WRITE_BYTES","WRITE_USEC"};
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  if (!TESTS_QUIET) printf("This program will read %s and write it to /dev/null\n", infile);
40  FILE* fdin=fopen(infile, "r");
41  if (fdin == NULL) perror("Could not open file for reading: \n");
42  FILE* fout=fopen("/dev/null", "w");
43  if (fout == NULL) perror("Could not open file for writing: \n");
44  int bytes = 0;
45  char buf[1024];
46 
47  int retval;
48  int e;
49  for (e=0; e<NUM_EVENTS; e++) {
50  retval = PAPI_event_name_to_code((char*)names[e], &Events[e]);
51  if (retval != PAPI_OK) {
52  fprintf(stderr, "Error getting code for %s\n", names[e]);
53  exit(2);
54  }
55  }
56 
57  /* Start counting events */
58  if (PAPI_start_counters(Events, NUM_EVENTS) != PAPI_OK) {
59  fprintf(stderr, "Error in PAPI_start_counters\n");
60  exit(1);
61  }
62 
63 //if (PAPI_read_counters(values, NUM_EVENTS) != PAPI_OK)
64 // handle_error(1);
65 //printf("After reading the counters: %lld\n",values[0]);
66 
67  while ((bytes = fread(buf, 1, 1024, fdin)) > 0) {
68  fwrite(buf, 1, bytes, fout);
69  }
70 
71  fclose(fdin);
72  fclose(fout);
73 
74  /* Stop counting events */
75  if (PAPI_stop_counters(values, NUM_EVENTS) != PAPI_OK) {
76  fprintf(stderr, "Error in PAPI_stop_counters\n");
77  }
78 
79  if (!TESTS_QUIET) {
80  printf("----\n");
81  for (e=0; e<NUM_EVENTS; e++)
82  printf("%s: %lld\n", names[e], values[e]);
83  }
84  test_pass( __FILE__, NULL, 0 );
85  return 0;
86 }
size_t fwrite(const void *ptr, size_t size, size_t nmemb, FILE *stream)
Definition: appio.c:387
static int Events[NUM_EVENTS]
Definition: init_fini.c:8
size_t fread(void *ptr, size_t size, size_t nmemb, FILE *stream)
Definition: appio.c:275
return PAPI_OK
Definition: linux-nvml.c:458
tests_quiet(argc, argv)
fclose(thread_wqfd)
#define printf
Definition: papi_test.h:125
test_pass(__FILE__, NULL, 0)
int int argc
Definition: iozone.c:1609
int TESTS_QUIET
Definition: test_utils.c:11
char ** argv
Definition: iozone.c:1610
int PAPI_library_init(int version)
Definition: papi.c:495
char buf[200]
Definition: iozone.c:19609
int PAPI_stop_counters(long long *values, int array_len)
Definition: papi_hl.c:803
#define PAPI_VER_CURRENT
Definition: fpapi.h:14
char version[]
Definition: fileop.c:134
int PAPI_event_name_to_code(char *in, int *out)
Definition: papi.c:1008
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
const char * names[NUM_EVENTS]
void exit()
#define NUM_EVENTS

Here is the call graph for this function: