PAPI  5.4.0.0
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
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_test.h"
20 
21 #define NUM_EVENTS 1
22 
23 int main(int argc, char** argv) {
24  int Events[NUM_EVENTS];
25  const char* names[NUM_EVENTS] = {"SELECT_USEC"};
26  long long values[NUM_EVENTS];
27 
28  /* Set TESTS_QUIET variable */
29  tests_quiet( argc, argv );
30 
32  if (version != PAPI_VER_CURRENT) {
33  fprintf(stderr, "PAPI_library_init version mismatch\n");
34  exit(1);
35  }
36 
37  if (!TESTS_QUIET) printf("This program will read from stdin and echo it to stdout\n");
38  int retval;
39  int e;
40  for (e=0; e<NUM_EVENTS; e++) {
41  retval = PAPI_event_name_to_code((char*)names[e], &Events[e]);
42  if (retval != PAPI_OK) {
43  fprintf(stderr, "Error getting code for %s\n", names[e]);
44  exit(2);
45  }
46  }
47 
48  /* Start counting events */
49  if (PAPI_start_counters(Events, NUM_EVENTS) != PAPI_OK) {
50  fprintf(stderr, "Error in PAPI_start_counters\n");
51  exit(1);
52  }
53 
54  int bytes = 0;
55  char buf[1024];
56 
57 
58 //if (PAPI_read_counters(values, NUM_EVENTS) != PAPI_OK)
59 // handle_error(1);
60 //printf("After reading the counters: %lld\n",values[0]);
61 
62  int fdready;
63  fd_set readfds;
64  FD_SET(0,&readfds);
65 
66  while (select(1,&readfds,NULL,NULL,NULL)) {
67  bytes = read(0, buf, 1024);
68  if (bytes > 0) write(1, buf, bytes);
69  if (bytes == 0) break;
70  }
71 
72 
73  /* Stop counting events */
74  if (PAPI_stop_counters(values, NUM_EVENTS) != PAPI_OK) {
75  fprintf(stderr, "Error in PAPI_stop_counters\n");
76  }
77 
78  if (!TESTS_QUIET) {
79  printf("----\n");
80  for (e=0; e<NUM_EVENTS; e++)
81  printf("%s: %lld\n", names[e], values[e]);
82  }
83  test_pass( __FILE__, NULL, 0 );
84  return 0;
85 }
ssize_t read(int fd, void *buf, size_t count)
Definition: appio.c:225
static int Events[NUM_EVENTS]
Definition: init_fini.c:8
return PAPI_OK
Definition: linux-nvml.c:458
tests_quiet(argc, argv)
#define printf
Definition: papi_test.h:125
test_pass(__FILE__, NULL, 0)
int int argc
Definition: iozone.c:1609
Return codes and api definitions.
#define NUM_EVENTS
int TESTS_QUIET
Definition: test_utils.c:11
char ** argv
Definition: iozone.c:1610
int PAPI_library_init(int version)
Definition: papi.c:497
char buf[200]
Definition: iozone.c:19609
ssize_t write(int fd, const void *buf, size_t count)
Definition: appio.c:298
int PAPI_stop_counters(long long *values, int array_len)
Definition: papi_hl.c:803
int select(int nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds, struct timeval *timeout)
Definition: appio.c:199
char version[]
Definition: fileop.c:134
int PAPI_event_name_to_code(char *in, int *out)
Definition: papi.c:1010
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
#define PAPI_VER_CURRENT
Definition: papi.h:223
int main(int argc, char **argv)
List all appio events codes and names.
const char * names[NUM_EVENTS]
void exit()