PAPI 7.1.0.0
Loading...
Searching...
No Matches
appio_test_recv.c File Reference
Include dependency graph for appio_test_recv.c:

Go to the source code of this file.

Macros

#define PORT   3490
 
#define NUM_EVENTS   6
 

Functions

 main (int argc, char *argv[])
 

Macro Definition Documentation

◆ NUM_EVENTS

#define NUM_EVENTS   6

Definition at line 14 of file appio_test_recv.c.

◆ PORT

#define PORT   3490

Definition at line 13 of file appio_test_recv.c.

Function Documentation

◆ main()

main ( int  argc,
char *  argv[] 
)

Definition at line 16 of file appio_test_recv.c.

16 {
17 int EventSet = PAPI_NULL;
18 const char* names[NUM_EVENTS] = {"RECV_CALLS", "RECV_BYTES", "RECV_USEC", "RECV_ERR", "RECV_INTERRUPTED", "RECV_WOULD_BLOCK"};
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) printf("This program will listen on port 3490, and write data received to standard output\n");
37 int retval;
38 int e;
39 int event_code;
40 for (e=0; e<NUM_EVENTS; e++) {
41 retval = PAPI_event_name_to_code((char*)names[e], &event_code);
42 if (retval != PAPI_OK) {
43 fprintf(stderr, "Error getting code for %s\n", names[e]);
44 exit(2);
45 }
46 retval = PAPI_add_event(EventSet, event_code);
47 if (retval != PAPI_OK) {
48 fprintf(stderr, "Error adding %s to event set\n", names[e]);
49 exit(2);
50 }
51 }
52
53 int bytes = 0;
54 char buf[1024];
55
56 int sockfd, n_sockfd, sin_size, len;
57 char *host_addr, *recv_msg;
58 struct sockaddr_in my_addr;
59 struct sockaddr_in their_addr;
60 my_addr.sin_family = AF_INET;
61 my_addr.sin_port = htons(PORT);
62 my_addr.sin_addr.s_addr = INADDR_ANY;
63
64 sockfd = socket(AF_INET, SOCK_STREAM, 0);
65 if (sockfd < 0) {
66 perror("socket");
67 exit(1);
68 }
69 if ((bind(sockfd, (struct sockaddr *)&my_addr, sizeof(struct sockaddr))) == -1) {
70 perror("bind");
71 exit(1);
72 }
73 listen(sockfd, 10);
74 if ((n_sockfd = accept(sockfd, (struct sockaddr *)&their_addr, &sin_size)) == -1) {
75 perror("accept");
76 exit(1);
77 }
78 close(sockfd);
79
80 /* Start counting events */
81 if (PAPI_start(EventSet) != PAPI_OK) {
82 fprintf(stderr, "Error in PAPI_start\n");
83 exit(1);
84 }
85
86 while ((bytes = recv(n_sockfd, buf, 1024, 0)) > 0) {
87 write(1, buf, bytes);
88 }
89
90 close(n_sockfd);
91
92 /* Stop counting events */
94 fprintf(stderr, "Error in PAPI_stop\n");
95 }
96
97 if (!TESTS_QUIET) {
98 printf("----\n");
99 for (e=0; e<NUM_EVENTS; e++)
100 printf("%s: %lld\n", names[e], values[e]);
101 }
102 test_pass( __FILE__ );
103 return 0;
104}
int close(int fd)
Definition: appio.c:179
ssize_t write(int fd, const void *buf, size_t count)
Definition: appio.c:302
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: