comparison libfdcore/p_out.c @ 895:fbf77629cb7b

Added received and sent timestamps in the messages; added logs on emission and reception
author Sebastien Decugis <sdecugis@freediameter.net>
date Fri, 30 Nov 2012 00:44:10 +0100
parents 4a9f08d6b6ba
children 5053f1abcf5d
comparison
equal deleted inserted replaced
894:43fb27a9037f 895:fbf77629cb7b
42 int msg_is_a_req; 42 int msg_is_a_req;
43 uint8_t * buf; 43 uint8_t * buf;
44 size_t sz; 44 size_t sz;
45 int ret; 45 int ret;
46 uint32_t bkp_hbh = 0; 46 uint32_t bkp_hbh = 0;
47 struct timespec senton;
48 struct msg * cpy_for_logs_only;
47 49
48 TRACE_ENTRY("%p %x %p %p %p", msg, flags, cnx, hbh, srl); 50 TRACE_ENTRY("%p %x %p %p %p", msg, flags, cnx, hbh, srl);
49 51
50 /* Retrieve the message header */ 52 /* Retrieve the message header */
51 CHECK_FCT( fd_msg_hdr(*msg, &hdr) ); 53 CHECK_FCT( fd_msg_hdr(*msg, &hdr) );
61 63
62 /* Create the message buffer */ 64 /* Create the message buffer */
63 CHECK_FCT(fd_msg_bufferize( *msg, &buf, &sz )); 65 CHECK_FCT(fd_msg_bufferize( *msg, &buf, &sz ));
64 pthread_cleanup_push( free, buf ); 66 pthread_cleanup_push( free, buf );
65 67
66 /* Log the message */ 68 cpy_for_logs_only = *msg;
67 fd_msg_log( FD_MSG_LOG_SENT, *msg, "Sent to '%s'", fd_cnx_getid(cnx));
68 69
69 /* Save a request before sending so that there is no race condition with the answer */ 70 /* Save a request before sending so that there is no race condition with the answer */
70 if (msg_is_a_req) { 71 if (msg_is_a_req) {
71 CHECK_FCT_DO( ret = fd_p_sr_store(srl, msg, &hdr->msg_hbhid, bkp_hbh), goto out ); 72 CHECK_FCT_DO( ret = fd_p_sr_store(srl, msg, &hdr->msg_hbhid, bkp_hbh), goto out );
73 }
74
75 CHECK_SYS_DO( clock_gettime(CLOCK_REALTIME, &senton), /* ... */ );
76 CHECK_FCT_DO( fd_msg_ts_set_sent(cpy_for_logs_only, &senton), /* ... */ );
77
78 /* Log the message */
79 fd_msg_log( FD_MSG_LOG_SENT, cpy_for_logs_only, "Sent to '%s'", fd_cnx_getid(cnx));
80
81 {
82 struct timespec rcvon, delay;
83
84 (void) fd_msg_ts_get_recv(cpy_for_logs_only, &rcvon);
85 if (rcvon.tv_sec != 0 || rcvon.tv_nsec != 0) {
86 TS_DIFFERENCE( &delay, &rcvon, &senton);
87 fd_msg_log( FD_MSG_LOG_TIMING, cpy_for_logs_only, "Forwarded in %d.%06.6d sec", delay.tv_sec, delay.tv_nsec/1000);
88 } else { /* We log the answer time only for answers generated locally */
89 if (!msg_is_a_req) {
90 /* get the matching request */
91 struct msg * req;
92 struct timespec reqrcvon;
93 (void) fd_msg_answ_getq(cpy_for_logs_only, &req);
94 (void) fd_msg_ts_get_recv(req, &reqrcvon);
95 TS_DIFFERENCE( &delay, &reqrcvon, &senton);
96 fd_msg_log( FD_MSG_LOG_TIMING, cpy_for_logs_only, "Answered in %d.%06.6d sec", delay.tv_sec, delay.tv_nsec/1000);
97 }
98 }
72 } 99 }
73 100
74 /* Send the message */ 101 /* Send the message */
75 CHECK_FCT_DO( ret = fd_cnx_send(cnx, buf, sz, flags), ); 102 CHECK_FCT_DO( ret = fd_cnx_send(cnx, buf, sz, flags), );
76 out: 103 out:
"Welcome to our mercurial repository"