Changeset 895:fbf77629cb7b in freeDiameter
- Timestamp:
- Nov 30, 2012, 8:44:10 AM (11 years ago)
- Branch:
- default
- Phase:
- public
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
include/freeDiameter/libfdproto.h
r894 r895 203 203 #define FCTS 6 /* Display entry parameters of most functions */ 204 204 #define CALL 9 /* Display calls to most functions (with CHECK macros) */ 205 206 #define TIMING INFO /* Display the message handing time information with this level */207 205 208 206 /* Increment the debug level for a file at compilation time by defining -DTRACE_LEVEL=FULL for example. */ … … 596 594 || (((ts1)->tv_sec == (ts2)->tv_sec ) && ((ts1)->tv_nsec < (ts2)->tv_nsec) )) 597 595 596 /* Compute diff between two timespecs (pointers) */ 597 #define TS_DIFFERENCE( tsdiff, tsstart, tsend ) { \ 598 if ((tsend)->tv_nsec < (tsstart)->tv_nsec ) { \ 599 (tsdiff)->tv_sec = (tsend)->tv_sec - (tsstart)->tv_sec - 1; \ 600 (tsdiff)->tv_nsec = (tsend)->tv_nsec + 1000000000 - (tsstart)->tv_nsec; \ 601 } else { \ 602 (tsdiff)->tv_sec = (tsend)->tv_sec - (tsstart)->tv_sec; \ 603 (tsdiff)->tv_nsec = (tsend)->tv_nsec - (tsstart)->tv_nsec; \ 604 }} 605 606 598 607 /* This gives a good size for buffered reads */ 599 608 #ifndef BUFSIZ … … 2221 2230 FD_MSG_LOG_RECEIVED, /* message received from the network */ 2222 2231 FD_MSG_LOG_SENT, /* message sent to another peer */ 2223 FD_MSG_LOG_NODELIVER /* message could not be delivered to any peer */ 2224 }; 2225 #define FD_MSG_LOG_MAX FD_MSG_LOG_NODELIVER 2232 FD_MSG_LOG_NODELIVER, /* message could not be delivered to any peer */ 2233 FD_MSG_LOG_TIMING /* profiling messages */ 2234 }; 2235 #define FD_MSG_LOG_MAX FD_MSG_LOG_TIMING 2226 2236 void fd_msg_log( enum fd_msg_log_cause cause, struct msg * msg, const char * prefix_format, ... ); 2227 2237 … … 2384 2394 int fd_msg_source_set( struct msg * msg, DiamId_t diamid, size_t diamidlen, int add_rr, struct dictionary * dict ); 2385 2395 int fd_msg_source_get( struct msg * msg, DiamId_t *diamid, size_t * diamidlen ); 2396 2397 /* 2398 * FUNCTION: fd_msg_ts_* 2399 * 2400 * PARAMETERS: 2401 * msg : A msg object. 2402 * ts : A struct timespec pointer, indexed on CLOCK_REALTIME 2403 * 2404 * DESCRIPTION: 2405 * Associate or retrieve timestamps meaningful for the message. 2406 * A timestamp with a value of { 0, 0 } means: not set. 2407 * 2408 * RETURN VALUE: 2409 * 0 : Operation complete. 2410 * !0 : an error occurred. 2411 */ 2412 /* when msg was received from network */ 2413 int fd_msg_ts_set_recv( struct msg * msg, struct timespec * ts ); 2414 int fd_msg_ts_get_recv( struct msg * msg, struct timespec * ts ); 2415 int fd_msg_ts_set_sent( struct msg * msg, struct timespec * ts ); 2416 int fd_msg_ts_get_sent( struct msg * msg, struct timespec * ts ); 2417 2386 2418 2387 2419 /* -
libfdcore/p_out.c
r740 r895 45 45 int ret; 46 46 uint32_t bkp_hbh = 0; 47 struct timespec senton; 48 struct msg * cpy_for_logs_only; 47 49 48 50 TRACE_ENTRY("%p %x %p %p %p", msg, flags, cnx, hbh, srl); … … 64 66 pthread_cleanup_push( free, buf ); 65 67 66 /* Log the message */ 67 fd_msg_log( FD_MSG_LOG_SENT, *msg, "Sent to '%s'", fd_cnx_getid(cnx)); 68 cpy_for_logs_only = *msg; 68 69 69 70 /* Save a request before sending so that there is no race condition with the answer */ 70 71 if (msg_is_a_req) { 71 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 -
libfdcore/p_psm.c
r767 r895 478 478 struct msg * msg = NULL; 479 479 struct msg_hdr * hdr; 480 struct timespec rcvon; 481 482 /* Retrieve the piggytailed timestamp */ 483 memcpy(&rcvon, ev_data+ev_sz, sizeof(struct timespec)); 480 484 481 485 /* Parse the received buffer */ … … 487 491 goto psm_loop; 488 492 } ); 493 494 CHECK_FCT_DO( fd_msg_ts_set_recv(msg, &rcvon), /* ... */ ); 489 495 490 496 /* If the current state does not allow receiving messages, just drop it */ … … 515 521 /* Associate */ 516 522 CHECK_FCT_DO( fd_msg_answ_associate( msg, req ), goto psm_end ); 523 524 /* Display the delay to receive the answer */ 525 { 526 struct timespec reqsent, delay; 527 (void) fd_msg_ts_get_sent(req, &reqsent); 528 TS_DIFFERENCE( &delay, &reqsent, &rcvon ); 529 fd_msg_log( FD_MSG_LOG_TIMING, msg, "Answer received in %d.%06.6d sec.", delay.tv_sec, delay.tv_nsec / 1000 ); 530 } 517 531 } 518 532 -
libfdproto/messages.c
r894 r895 128 128 DiamId_t msg_src_id; /* Diameter Id of the peer this message was received from. This string is malloc'd and must be freed */ 129 129 size_t msg_src_id_len; /* cached length of this string */ 130 struct timespec msg_ts; /* Timestamp associated with the message */ 130 struct timespec msg_ts_rcv; /* Timestamp when this message was received from the network */ 131 struct timespec msg_ts_sent; /* Timestamp when this message was sent to the network */ 131 132 132 133 }; … … 678 679 { 679 680 int ret = 0; 681 char buftime[256]; 682 size_t tsoffset = 0; 683 struct tm tm; 680 684 681 685 CHECK_FCT( dump_add_str(outstr, offset, outlen, "%*sMSG: %p\n", INOBJHDRVAL, msg) ); … … 684 688 CHECK_FCT( dump_add_str(outstr, offset, outlen, INOBJHDR "INVALID!\n", INOBJHDRVAL) ); 685 689 return 0; 690 } 691 692 if ((msg->msg_ts_rcv.tv_sec != 0) || (msg->msg_ts_rcv.tv_nsec != 0)) { 693 tsoffset += strftime(buftime + tsoffset, sizeof(buftime) - tsoffset, "%D,%T", localtime_r( &msg->msg_ts_rcv.tv_sec , &tm )); 694 tsoffset += snprintf(buftime + tsoffset, sizeof(buftime) - tsoffset, ".%6.6ld", msg->msg_ts_rcv.tv_nsec / 1000); 695 CHECK_FCT( dump_add_str(outstr, offset, outlen, INOBJHDR "Received: %s\n", INOBJHDRVAL, buftime) ); 696 } 697 if ((msg->msg_ts_sent.tv_sec != 0) || (msg->msg_ts_sent.tv_nsec != 0)) { 698 tsoffset += strftime(buftime + tsoffset, sizeof(buftime) - tsoffset, "%D,%T", localtime_r( &msg->msg_ts_sent.tv_sec , &tm )); 699 tsoffset += snprintf(buftime + tsoffset, sizeof(buftime) - tsoffset, ".%6.6ld", msg->msg_ts_sent.tv_nsec / 1000); 700 CHECK_FCT( dump_add_str(outstr, offset, outlen, INOBJHDR "Sent : %s\n", INOBJHDRVAL, buftime) ); 686 701 } 687 702 … … 734 749 if (!avp->avp_model) { 735 750 736 CHECK_FCT( dump_add_str(outstr, offset, outlen, INOBJHDR "(no model )\n", INOBJHDRVAL) );751 CHECK_FCT( dump_add_str(outstr, offset, outlen, INOBJHDR "(no model resolved)\n", INOBJHDRVAL) ); 737 752 738 753 } else { … … 826 841 827 842 /* now really output this in one shot, so it is not interrupted */ 828 fd_log_debug_fstr(fstr, "%s ", outstr);843 fd_log_debug_fstr(fstr, "%s\n", outstr); 829 844 830 845 free(outstr); … … 838 853 fd_log_debug_fstr(fstr, "Error while dumping %p\n", msg) ); 839 854 /* now really output this in one shot, so it is not interrupted */ 840 fd_log_debug_fstr(fstr, "%s ", outstr);855 fd_log_debug_fstr(fstr, "%s\n", outstr); 841 856 842 857 free(outstr); … … 1152 1167 return 0; 1153 1168 } 1169 1170 int fd_msg_ts_set_recv( struct msg * msg, struct timespec * ts ) 1171 { 1172 TRACE_ENTRY("%p %p", msg, ts); 1173 1174 /* Check we received valid parameters */ 1175 CHECK_PARAMS( CHECK_MSG(msg) ); 1176 CHECK_PARAMS( ts ); 1177 1178 memcpy(&msg->msg_ts_rcv, ts, sizeof(struct timespec)); 1179 return 0; 1180 } 1181 1182 int fd_msg_ts_get_recv( struct msg * msg, struct timespec * ts ) 1183 { 1184 TRACE_ENTRY("%p %p", msg, ts); 1185 1186 /* Check we received valid parameters */ 1187 CHECK_PARAMS( CHECK_MSG(msg) ); 1188 CHECK_PARAMS( ts ); 1189 1190 memcpy(ts, &msg->msg_ts_rcv, sizeof(struct timespec)); 1191 return 0; 1192 } 1193 1194 int fd_msg_ts_set_sent( struct msg * msg, struct timespec * ts ) 1195 { 1196 TRACE_ENTRY("%p %p", msg, ts); 1197 1198 /* Check we received valid parameters */ 1199 CHECK_PARAMS( CHECK_MSG(msg) ); 1200 CHECK_PARAMS( ts ); 1201 1202 memcpy(&msg->msg_ts_sent, ts, sizeof(struct timespec)); 1203 return 0; 1204 } 1205 1206 int fd_msg_ts_get_sent( struct msg * msg, struct timespec * ts ) 1207 { 1208 TRACE_ENTRY("%p %p", msg, ts); 1209 1210 /* Check we received valid parameters */ 1211 CHECK_PARAMS( CHECK_MSG(msg) ); 1212 CHECK_PARAMS( ts ); 1213 1214 memcpy(ts, &msg->msg_ts_sent, sizeof(struct timespec)); 1215 return 0; 1216 } 1217 1154 1218 1155 1219 /* Retrieve the session of the message */ -
libfdproto/msg_log.c
r765 r895 166 166 (void)pthread_mutex_lock(&fd_log_lock); 167 167 pthread_cleanup_push(fd_cleanup_mutex_silent, &fd_log_lock); 168 fprintf( fstr, "\n"); 168 169 va_start(ap, prefix_format); 169 170 vfprintf( fstr, prefix_format, ap); … … 173 174 (void)pthread_mutex_unlock(&fd_log_lock); 174 175 175 fd_log_debug_fstr(fstr, "\n Logged: %s\n\n", buftime);176 fd_log_debug_fstr(fstr, "\n Logged: %s\n", buftime); 176 177 177 178 /* And now the message itself */
Note: See TracChangeset
for help on using the changeset viewer.