PAPI 7.1.0.0
Loading...
Searching...
No Matches
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.h"
19#include "papi_test.h"
20
21#define NUM_EVENTS 7
22
23int main(int argc, char** argv) {
24 int EventSet = PAPI_NULL;
25 const char* names[NUM_EVENTS] = {"READ_CALLS", "READ_BYTES", "READ_BLOCK_SIZE", "READ_USEC", "SEEK_CALLS", "SEEK_USEC", "SEEK_ABS_STRIDE_SIZE"};
26 long long values[NUM_EVENTS];
27
28 char *infile = "/etc/group";
29
30 /* Set TESTS_QUIET variable */
31 tests_quiet( argc, argv );
32
35 fprintf(stderr, "PAPI_library_init version mismatch\n");
36 exit(1);
37 }
38
39 /* Create the Event Set */
41 fprintf(stderr, "Error creating event set\n");
42 exit(2);
43 }
44
45 int fdin;
46 if (!TESTS_QUIET) printf("This program will do a strided read %s and write it to stdout\n", infile);
47 int retval;
48 int e;
49 int event_code;
50 for (e=0; e<NUM_EVENTS; e++) {
51 retval = PAPI_event_name_to_code((char*)names[e], &event_code);
52 if (retval != PAPI_OK) {
53 fprintf(stderr, "Error getting code for %s\n", names[e]);
54 exit(2);
55 }
56 retval = PAPI_add_event(EventSet, event_code);
57 if (retval != PAPI_OK) {
58 fprintf(stderr, "Error adding %s to event set\n", names[e]);
59 exit(2);
60 }
61 }
62
63 /* Start counting events */
64 if (PAPI_start(EventSet) != PAPI_OK) {
65 fprintf(stderr, "Error in PAPI_start\n");
66 exit(1);
67 }
68
69 fdin=open(infile, O_RDONLY);
70 if (fdin < 0) perror("Could not open file for reading: \n");
71 int bytes = 0;
72 char buf[1024];
73
74
75//if (PAPI_read(EventSet, values) != PAPI_OK)
76// handle_error(1);
77//printf("After reading the counters: %lld\n",values[0]);
78
79 while ((bytes = read(fdin, buf, 32)) > 0) {
80 write(1, buf, bytes);
81 lseek(fdin, 16, SEEK_CUR);
82 }
83
84 /* Closing the descriptors before doing the PAPI_stop
85 means, OPEN_FDS will be reported as zero, which is
86 right, since at the time of PAPI_stop, the descriptors
87 we opened have been closed */
88 close (fdin);
89
90 /* Stop counting events */
92 fprintf(stderr, "Error in PAPI_stop\n");
93 }
94
95 if (!TESTS_QUIET) {
96 printf("----\n");
97 for (e=0; e<NUM_EVENTS; e++)
98 printf("%s: %lld\n", names[e], values[e]);
99 }
100 test_pass( __FILE__ );
101 return 0;
102}
int open(const char *pathname, int flags, mode_t mode)
Definition: appio.c:188
off_t lseek(int fd, off_t offset, int whence)
Definition: appio.c:214
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
Return codes and api definitions.
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 main()
Definition: pernode.c:20
int retval
Definition: zero_fork.c:53