PAPI 7.1.0.0
Loading...
Searching...
No Matches
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

◆ NUM_EVENTS

#define NUM_EVENTS   8

Definition at line 24 of file appio_test_fread_fwrite.c.

Function Documentation

◆ main()

int main ( int  argc,
char **  argv 
)

Definition at line 26 of file appio_test_fread_fwrite.c.

26 {
27 int EventSet = PAPI_NULL;
28 const char* names[NUM_EVENTS] = {"READ_CALLS", "READ_BYTES","READ_USEC","READ_ERR", "READ_EOF", "WRITE_CALLS","WRITE_BYTES","WRITE_USEC"};
29 long long values[NUM_EVENTS];
30
31 char *infile = "/etc/group";
32
33 /* Set TESTS_QUIET variable */
34 tests_quiet( argc, argv );
35
38 fprintf(stderr, "PAPI_library_init version mismatch\n");
39 exit(1);
40 }
41
42 /* Create the Event Set */
44 fprintf(stderr, "Error creating event set\n");
45 exit(2);
46 }
47
48 if (!TESTS_QUIET) printf("This program will read %s and write it to /dev/null\n", infile);
49 FILE* fdin=fopen(infile, "r");
50 if (fdin == NULL) perror("Could not open file for reading: \n");
51 FILE* fout=fopen("/dev/null", "w");
52 if (fout == NULL) perror("Could not open file for writing: \n");
53 int bytes = 0;
54 char buf[1024];
55
56 int retval;
57 int e;
58 int event_code;
59 for (e=0; e<NUM_EVENTS; e++) {
60 retval = PAPI_event_name_to_code((char*)names[e], &event_code);
61 if (retval != PAPI_OK) {
62 fprintf(stderr, "Error getting code for %s\n", names[e]);
63 exit(2);
64 }
65 retval = PAPI_add_event(EventSet, event_code);
66 if (retval != PAPI_OK) {
67 fprintf(stderr, "Error adding %s to event set\n", names[e]);
68 exit(2);
69 }
70 }
71
72 /* Start counting events */
73 if (PAPI_start(EventSet) != PAPI_OK) {
74 fprintf(stderr, "Error in PAPI_start\n");
75 exit(1);
76 }
77
78//if (PAPI_read(EventSet, values) != PAPI_OK)
79// handle_error(1);
80//printf("After reading the counters: %lld\n",values[0]);
81
82 while ((bytes = fread(buf, 1, 1024, fdin)) > 0) {
83 fwrite(buf, 1, bytes, fout);
84 }
85
86 fclose(fdin);
87 fclose(fout);
88
89 /* Stop counting events */
91 fprintf(stderr, "Error in PAPI_stop\n");
92 }
93
94 if (!TESTS_QUIET) {
95 printf("----\n");
96 for (e=0; e<NUM_EVENTS; e++)
97 printf("%s: %lld\n", names[e], values[e]);
98 }
99 test_pass( __FILE__ );
100 return 0;
101}
size_t fread(void *ptr, size_t size, size_t nmemb, FILE *stream)
Definition: appio.c:279
size_t fwrite(const void *ptr, size_t size, size_t nmemb, FILE *stream)
Definition: appio.c:391
#define NUM_EVENTS
const char * names[NUM_EVENTS]
add PAPI preset or native hardware event to an event set
Create a new empty PAPI EventSet.
Convert a name to a numeric hardware event code.
initialize the PAPI library.
Start counting hardware events in an event set.
Stop counting hardware events in an event set.
volatile int buf[CACHE_FLUSH_BUFFER_SIZE_INTS]
Definition: do_loops.c:12
#define PAPI_VER_CURRENT
Definition: f90papi.h:54
#define PAPI_OK
Definition: f90papi.h:73
#define PAPI_NULL
Definition: f90papi.h:78
static int EventSet
Definition: init_fini.c:8
static long long values[NUM_EVENTS]
Definition: init_fini.c:10
uint8_t version
int TESTS_QUIET
Definition: test_utils.c:18
FILE * stderr
int fclose(FILE *__stream)
int tests_quiet(int argc, char **argv)
Definition: test_utils.c:376
void PAPI_NORETURN test_pass(const char *filename)
Definition: test_utils.c:432
int retval
Definition: zero_fork.c:53
Here is the call graph for this function: