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

◆ NUM_EVENTS

#define NUM_EVENTS   12

Definition at line 22 of file appio_test_read_write.c.

Function Documentation

◆ main()

int main ( int  argc,
char **  argv 
)

Definition at line 24 of file appio_test_read_write.c.

24 {
25 int EventSet = PAPI_NULL;
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
36 fprintf(stderr, "PAPI_library_init version mismatch\n");
37 exit(1);
38 }
39
40 /* Create the Event Set */
42 fprintf(stderr, "Error creating event set\n");
43 exit(2);
44 }
45
46 int fdin;
47 if (!TESTS_QUIET) printf("This program will read %s and write it to /dev/null\n", infile);
48 int retval;
49 int e;
50 int event_code;
51 for (e=0; e<NUM_EVENTS; e++) {
52 retval = PAPI_event_name_to_code((char*)names[e], &event_code);
53 if (retval != PAPI_OK) {
54 fprintf(stderr, "Error getting code for %s\n", names[e]);
55 exit(2);
56 }
57 retval = PAPI_add_event(EventSet, event_code);
58 if (retval != PAPI_OK) {
59 fprintf(stderr, "Error adding %s to event set\n", names[e]);
60 exit(2);
61 }
62 }
63
64 /* Start counting events */
65 if (PAPI_start(EventSet) != PAPI_OK) {
66 fprintf(stderr, "Error in PAPI_start\n");
67 exit(1);
68 }
69
70 fdin=open(infile, O_RDONLY);
71 if (fdin < 0) perror("Could not open file for reading: \n");
72 int fdout;
73 fdout=open("/dev/null", O_WRONLY);
74 if (fdout < 0) perror("Could not open file for writing: \n");
75 int bytes = 0;
76 char buf[1024];
77
78
79//if (PAPI_read(EventSet, values) != PAPI_OK)
80// handle_error(1);
81//printf("After reading the counters: %lld\n",values[0]);
82
83 while ((bytes = read(fdin, buf, 1024)) > 0) {
84 write(fdout, buf, bytes);
85 }
86
87 /* Closing the descriptors before doing the PAPI_stop
88 means, OPEN_FDS will be reported as zero, which is
89 right, since at the time of PAPI_stop, the descriptors
90 we opened have been closed */
91 close (fdin);
92 close (fdout);
93
94 /* Stop counting events */
96 fprintf(stderr, "Error in PAPI_stop\n");
97 }
98
99 if (!TESTS_QUIET) {
100 printf("----\n");
101 for (e=0; e<NUM_EVENTS; e++)
102 printf("%s: %lld\n", names[e], values[e]);
103 }
104 test_pass( __FILE__ );
105 return 0;
106}
int open(const char *pathname, int flags, mode_t mode)
Definition: appio.c:188
int close(int fd)
Definition: appio.c:179
ssize_t write(int fd, const void *buf, size_t count)
Definition: appio.c:302
ssize_t read(int fd, void *buf, size_t count)
Definition: appio.c:229
const char * names[NUM_EVENTS]
#define 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 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: