PAPI 7.1.0.0
Loading...
Searching...
No Matches
appio_test_select.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 reads from standard linux /etc/group
7 * and writes the output to stdout.
8 * Statistics are printed at the end of the run.,
9 */
10#include <papi.h>
11#include <errno.h>
12#include <stdio.h>
13#include <stdlib.h>
14#include <sys/types.h>
15#include <sys/stat.h>
16#include <fcntl.h>
17#include <unistd.h>
18
19#include "papi.h"
20#include "papi_test.h"
21
22#define NUM_EVENTS 1
23
24int main(int argc, char** argv) {
25 int EventSet = PAPI_NULL;
26 const char* names[NUM_EVENTS] = {"SELECT_USEC"};
27 long long values[NUM_EVENTS];
28
29 /* Set TESTS_QUIET variable */
30 tests_quiet( argc, argv );
31
34 fprintf(stderr, "PAPI_library_init version mismatch\n");
35 exit(1);
36 }
37
38 /* Create the Event Set */
40 fprintf(stderr, "Error creating event set\n");
41 exit(2);
42 }
43
44 if (!TESTS_QUIET) printf("This program will read from stdin and echo it to stdout\n");
45 int retval;
46 int e;
47 int event_code;
48 for (e=0; e<NUM_EVENTS; e++) {
49 retval = PAPI_event_name_to_code((char*)names[e], &event_code);
50 if (retval != PAPI_OK) {
51 fprintf(stderr, "Error getting code for %s\n", names[e]);
52 exit(2);
53 }
54 retval = PAPI_add_event(EventSet, event_code);
55 if (retval != PAPI_OK) {
56 fprintf(stderr, "Error adding %s to event set\n", names[e]);
57 exit(2);
58 }
59 }
60
61 /* Start counting events */
62 if (PAPI_start(EventSet) != PAPI_OK) {
63 fprintf(stderr, "Error in PAPI_start\n");
64 exit(1);
65 }
66
67 int bytes = 0;
68 char buf[1024];
69
70
71//if (PAPI_read(EventSet, values) != PAPI_OK)
72// handle_error(1);
73//printf("After reading the counters: %lld\n",values[0]);
74
75 int fdready;
76 fd_set readfds;
77 FD_SET(0,&readfds);
78
79 while (select(1,&readfds,NULL,NULL,NULL)) {
80 bytes = read(0, buf, 1024);
81 if (bytes > 0) write(1, buf, bytes);
82 if (bytes == 0) break;
83 }
84
85
86 /* Stop counting events */
88 fprintf(stderr, "Error in PAPI_stop\n");
89 }
90
91 if (!TESTS_QUIET) {
92 printf("----\n");
93 for (e=0; e<NUM_EVENTS; e++)
94 printf("%s: %lld\n", names[e], values[e]);
95 }
96 test_pass( __FILE__ );
97 return 0;
98}
ssize_t write(int fd, const void *buf, size_t count)
Definition: appio.c:302
int select(int nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds, struct timeval *timeout)
Definition: appio.c:203
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