PAPI  5.4.0.0
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
appio_test_socket.c File Reference
Include dependency graph for appio_test_socket.c:

Go to the source code of this file.

Macros

#define PORT   3490
 
#define NUM_EVENTS   15
 

Functions

 main (int argc, char *argv[])
 

Macro Definition Documentation

#define NUM_EVENTS   15

Definition at line 14 of file appio_test_socket.c.

#define PORT   3490

Definition at line 13 of file appio_test_socket.c.

Function Documentation

main ( int  argc,
char *  argv[] 
)

Definition at line 16 of file appio_test_socket.c.

16  {
17  int Events[NUM_EVENTS];
18  const char* names[NUM_EVENTS] = {"READ_CALLS", "READ_BYTES", "READ_USEC", "READ_WOULD_BLOCK", "SOCK_READ_CALLS", "SOCK_READ_BYTES", "SOCK_READ_USEC", "SOCK_READ_WOULD_BLOCK", "WRITE_BYTES", "WRITE_CALLS", "WRITE_WOULD_BLOCK", "WRITE_USEC", "SOCK_WRITE_BYTES", "SOCK_WRITE_CALLS", "SOCK_WRITE_USEC"};
19  long long values[NUM_EVENTS];
20 
21  /* Set TESTS_QUIET variable */
22  tests_quiet( argc, argv );
23 
25  if (version != PAPI_VER_CURRENT) {
26  fprintf(stderr, "PAPI_library_init version mismatch\n");
27  exit(1);
28  }
29 
30  if (!TESTS_QUIET)
31  printf("This program will listen on port 3490, and write data received to standard output AND socket\n"
32  "In the output ensure that the following identities hold:\n"
33  "READ_* == SOCK_READ_*\n"
34  "WRITE_{CALLS,BYTES} = 2 * SOCK_WRITE_{CALLS,BYTES}\n"
35  "SOCK_READ_BYTES == SOCK_WRITE_BYTES\n");
36  int retval;
37  int e;
38  for (e=0; e<NUM_EVENTS; e++) {
39  retval = PAPI_event_name_to_code((char*)names[e], &Events[e]);
40  if (retval != PAPI_OK) {
41  fprintf(stderr, "Error getting code for %s\n", names[e]);
42  exit(2);
43  }
44  }
45 
46  int bytes = 0;
47  char buf[1024];
48 
49  int sockfd, n_sockfd, sin_size, len;
50  char *host_addr;
51  struct sockaddr_in my_addr;
52  struct sockaddr_in their_addr;
53  my_addr.sin_family = AF_INET;
54  my_addr.sin_port = htons(PORT);
55  my_addr.sin_addr.s_addr = INADDR_ANY;
56 
57  sockfd = socket(AF_INET, SOCK_STREAM, 0);
58  if (sockfd < 0) {
59  perror("socket");
60  exit(1);
61  }
62  if ((bind(sockfd, (struct sockaddr *)&my_addr, sizeof(struct sockaddr))) == -1) {
63  perror("bind");
64  exit(1);
65  }
66  listen(sockfd, 10);
67  if ((n_sockfd = accept(sockfd, (struct sockaddr *)&their_addr, &sin_size)) == -1) {
68  perror("accept");
69  exit(1);
70  }
71  close(sockfd);
72 
73  /* Start counting events */
74  if (PAPI_start_counters(Events, NUM_EVENTS) != PAPI_OK) {
75  fprintf(stderr, "Error in PAPI_start_counters\n");
76  exit(1);
77  }
78 
79  while ((bytes = read(n_sockfd, buf, 1024)) > 0) {
80  write(1, buf, bytes);
81  write(n_sockfd, buf, bytes);
82  }
83 
84  close(n_sockfd);
85 
86  /* Stop counting events */
87  if (PAPI_stop_counters(values, NUM_EVENTS) != PAPI_OK) {
88  fprintf(stderr, "Error in PAPI_stop_counters\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__, NULL, 0 );
97  return 0;
98 }
ssize_t read(int fd, void *buf, size_t count)
Definition: appio.c:225
int close(int fd)
Definition: appio.c:175
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
#define PORT
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
#define NUM_EVENTS
char version[]
Definition: fileop.c:134
int PAPI_event_name_to_code(char *in, int *out)
Definition: papi.c:1010
listen(s, 10)
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
const char * names[NUM_EVENTS]
void exit()

Here is the call graph for this function: