Navigation


Changeset 895:fbf77629cb7b in freeDiameter


Ignore:
Timestamp:
Nov 30, 2012, 8:44:10 AM (11 years ago)
Author:
Sebastien Decugis <sdecugis@freediameter.net>
Branch:
default
Phase:
public
Message:

Added received and sent timestamps in the messages; added logs on emission and reception

Files:
5 edited

Legend:

Unmodified
Added
Removed
  • include/freeDiameter/libfdproto.h

    r894 r895  
    203203#define FCTS 6  /* Display entry parameters of most functions */
    204204#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 */
    207205
    208206/* Increment the debug level for a file at compilation time by defining -DTRACE_LEVEL=FULL for example. */
     
    596594          || (((ts1)->tv_sec  == (ts2)->tv_sec ) && ((ts1)->tv_nsec < (ts2)->tv_nsec) ))
    597595
     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
    598607/* This gives a good size for buffered reads */
    599608#ifndef BUFSIZ
     
    22212230        FD_MSG_LOG_RECEIVED,     /* message received from the network */
    22222231        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
    22262236void fd_msg_log( enum fd_msg_log_cause cause, struct msg * msg, const char * prefix_format, ... );
    22272237
     
    23842394int fd_msg_source_set( struct msg * msg, DiamId_t diamid, size_t diamidlen, int add_rr, struct dictionary * dict );
    23852395int 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 */
     2413int fd_msg_ts_set_recv( struct msg * msg, struct timespec * ts );
     2414int fd_msg_ts_get_recv( struct msg * msg, struct timespec * ts );
     2415int fd_msg_ts_set_sent( struct msg * msg, struct timespec * ts );
     2416int fd_msg_ts_get_sent( struct msg * msg, struct timespec * ts );
     2417
    23862418
    23872419/*
  • libfdcore/p_out.c

    r740 r895  
    4545        int ret;
    4646        uint32_t bkp_hbh = 0;
     47        struct timespec senton;
     48        struct msg * cpy_for_logs_only;
    4749       
    4850        TRACE_ENTRY("%p %x %p %p %p", msg, flags, cnx, hbh, srl);
     
    6466        pthread_cleanup_push( free, buf );
    6567       
    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;
    6869       
    6970        /* Save a request before sending so that there is no race condition with the answer */
    7071        if (msg_is_a_req) {
    7172                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                }
    7299        }
    73100       
  • libfdcore/p_psm.c

    r767 r895  
    478478                struct msg * msg = NULL;
    479479                struct msg_hdr * hdr;
     480                struct timespec rcvon;
     481               
     482                /* Retrieve the piggytailed timestamp */
     483                memcpy(&rcvon, ev_data+ev_sz, sizeof(struct timespec));
    480484               
    481485                /* Parse the received buffer */
     
    487491                                goto psm_loop;
    488492                        } );
     493                       
     494                CHECK_FCT_DO( fd_msg_ts_set_recv(msg, &rcvon), /* ... */ );
    489495               
    490496                /* If the current state does not allow receiving messages, just drop it */
     
    515521                        /* Associate */
    516522                        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                        }
    517531                }
    518532               
  • libfdproto/messages.c

    r894 r895  
    128128        DiamId_t                 msg_src_id;            /* Diameter Id of the peer this message was received from. This string is malloc'd and must be freed */
    129129        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 */
    131132       
    132133};
     
    678679{
    679680        int ret = 0;
     681        char buftime[256];
     682        size_t tsoffset = 0;
     683        struct tm tm;
    680684       
    681685        CHECK_FCT( dump_add_str(outstr, offset, outlen, "%*sMSG: %p\n", INOBJHDRVAL, msg) );
     
    684688                CHECK_FCT( dump_add_str(outstr, offset, outlen, INOBJHDR "INVALID!\n", INOBJHDRVAL) );
    685689                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) );
    686701        }
    687702       
     
    734749        if (!avp->avp_model) {
    735750               
    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) );
    737752               
    738753        } else {
     
    826841       
    827842        /* 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);
    829844       
    830845        free(outstr);
     
    838853                                fd_log_debug_fstr(fstr, "Error while dumping %p\n", msg) );
    839854        /* 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);
    841856       
    842857        free(outstr);
     
    11521167        return 0;
    11531168}
     1169
     1170int 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
     1182int 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
     1194int 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
     1206int 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
    11541218
    11551219/* Retrieve the session of the message */
  • libfdproto/msg_log.c

    r765 r895  
    166166        (void)pthread_mutex_lock(&fd_log_lock);
    167167        pthread_cleanup_push(fd_cleanup_mutex_silent, &fd_log_lock);
     168        fprintf( fstr, "\n");
    168169        va_start(ap, prefix_format);
    169170        vfprintf( fstr, prefix_format, ap);
     
    173174        (void)pthread_mutex_unlock(&fd_log_lock);
    174175       
    175         fd_log_debug_fstr(fstr, "\nLogged: %s\n\n", buftime);
     176        fd_log_debug_fstr(fstr, "\n Logged: %s\n", buftime);
    176177       
    177178        /* And now the message itself */
Note: See TracChangeset for help on using the changeset viewer.