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

◆ NUM_EVENTS

#define NUM_EVENTS   15

Definition at line 14 of file appio_test_socket.c.

◆ PORT

#define PORT   3490

Definition at line 13 of file appio_test_socket.c.

Function Documentation

◆ main()

main ( int  argc,
char *  argv[] 
)

Definition at line 16 of file appio_test_socket.c.

16 {
17 int EventSet = PAPI_NULL;
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
26 fprintf(stderr, "PAPI_library_init version mismatch\n");
27 exit(1);
28 }
29
30 /* Create the Event Set */
32 fprintf(stderr, "Error creating event set\n");
33 exit(2);
34 }
35
36 if (!TESTS_QUIET)
37 printf("This program will listen on port 3490, and write data received to standard output AND socket\n"
38 "In the output ensure that the following identities hold:\n"
39 "READ_* == SOCK_READ_*\n"
40 "WRITE_{CALLS,BYTES} = 2 * SOCK_WRITE_{CALLS,BYTES}\n"
41 "SOCK_READ_BYTES == SOCK_WRITE_BYTES\n");
42 int retval;
43 int e;
44 int event_code;
45 for (e=0; e<NUM_EVENTS; e++) {
46 retval = PAPI_event_name_to_code((char*)names[e], &event_code);
47 if (retval != PAPI_OK) {
48 fprintf(stderr, "Error getting code for %s\n", names[e]);
49 exit(2);
50 }
51 retval = PAPI_add_event(EventSet, event_code);
52 if (retval != PAPI_OK) {
53 fprintf(stderr, "Error adding %s to event set\n", names[e]);
54 exit(2);
55 }
56 }
57
58 int bytes = 0;
59 char buf[1024];
60
61 int sockfd, n_sockfd, sin_size, len;
62 char *host_addr;
63 struct sockaddr_in my_addr;
64 struct sockaddr_in their_addr;
65 my_addr.sin_family = AF_INET;
66 my_addr.sin_port = htons(PORT);
67 my_addr.sin_addr.s_addr = INADDR_ANY;
68
69 sockfd = socket(AF_INET, SOCK_STREAM, 0);
70 if (sockfd < 0) {
71 perror("socket");
72 exit(1);
73 }
74 if ((bind(sockfd, (struct sockaddr *)&my_addr, sizeof(struct sockaddr))) == -1) {
75 perror("bind");
76 exit(1);
77 }
78 listen(sockfd, 10);
79 if ((n_sockfd = accept(sockfd, (struct sockaddr *)&their_addr, &sin_size)) == -1) {
80 perror("accept");
81 exit(1);
82 }
83 close(sockfd);
84
85 /* Start counting events */
86 if (PAPI_start(EventSet) != PAPI_OK) {
87 fprintf(stderr, "Error in PAPI_start\n");
88 exit(1);
89 }
90
91 while ((bytes = read(n_sockfd, buf, 1024)) > 0) {
92 write(1, buf, bytes);
93 write(n_sockfd, buf, bytes);
94 }
95
96 close(n_sockfd);
97
98 /* Stop counting events */
100 fprintf(stderr, "Error in PAPI_stop\n");
101 }
102
103 if (!TESTS_QUIET) {
104 printf("----\n");
105 for (e=0; e<NUM_EVENTS; e++)
106 printf("%s: %lld\n", names[e], values[e]);
107 }
108 test_pass( __FILE__ );
109 return 0;
110}
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 PORT
#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: