From aeb3e18527b565f22bd05f6c6989b2ae86968b71 Mon Sep 17 00:00:00 2001 From: Stefan Mititelu Date: Fri, 27 Nov 2015 18:18:14 +0200 Subject: [PATCH] tmx: refactor counters Focus on: - received_replies - received_replies_absorbed (in cfX cases) - relayed_locally - relayed_received - relayed_total --- modules/tm/t_reply.c | 15 +++++++++------ modules/tm/t_stats.c | 9 ++++++--- modules/tm/t_stats.h | 17 +++++++++++------ modules/tmx/tmx_mod.c | 38 +++++++++++++++++++++++++------------- 4 files changed, 51 insertions(+), 28 deletions(-) diff --git a/modules/tm/t_reply.c b/modules/tm/t_reply.c index f4e4dcdbf04..3b8e16b348c 100644 --- a/modules/tm/t_reply.c +++ b/modules/tm/t_reply.c @@ -554,8 +554,8 @@ static int _reply_light( struct cell *trans, char* buf, unsigned int len, /* t_update_timers_after_sending_reply( rb ); */ update_reply_stats( code ); trans->relayed_reply_branch=-2; - t_stats_replied_locally(); - t_stats_replied_total(); + t_stats_relayed_locally(); + t_stats_relayed_total(); if (lock) UNLOCK_REPLIES( trans ); /* do UAC cleanup procedures in case we generated @@ -1867,7 +1867,7 @@ enum rps relay_reply( struct cell *t, struct sip_msg *p_msg, int branch, } } update_reply_stats( relayed_code ); - t_stats_replied_total(); + t_stats_relayed_total(); if (!buf) { LOG(L_ERR, "ERROR: relay_reply: " "no mem for outbound reply buffer\n"); @@ -1890,7 +1890,7 @@ enum rps relay_reply( struct cell *t, struct sip_msg *p_msg, int branch, memcpy( uas_rb->buffer, buf, res_len ); if (relayed_msg==FAKED_REPLY) { /* to-tags for local replies */ update_local_tags(t, &bm, uas_rb->buffer, buf); - t_stats_replied_locally(); + t_stats_relayed_locally(); } /* update the status ... */ @@ -2041,7 +2041,7 @@ enum rps local_reply( struct cell *t, struct sip_msg *p_msg, int branch, winning_msg= branch==local_winner ? p_msg : t->uac[local_winner].reply; if (winning_msg==FAKED_REPLY) { - t_stats_replied_locally(); + t_stats_relayed_locally(); winning_code = branch==local_winner ? msg_status : t->uac[local_winner].last_received; } else { @@ -2049,7 +2049,7 @@ enum rps local_reply( struct cell *t, struct sip_msg *p_msg, int branch, } t->uas.status = winning_code; update_reply_stats( winning_code ); - t_stats_replied_total(); + t_stats_relayed_total(); if (unlikely(is_invite(t) && winning_msg!=FAKED_REPLY && winning_code>=200 && winning_code <300 && has_tran_tmcbs(t, TMCB_LOCAL_COMPLETED) )) { @@ -2143,6 +2143,9 @@ int reply_received( struct sip_msg *p_msg ) if ( (t==0)||(t==T_UNDEFINED)) goto trans_not_found; + /* if transaction found, increment the received_replies counter */ + t_stats_received_replies(); + if (unlikely(branch==T_BR_UNDEFINED)) BUG("invalid branch, please report to sr-dev@sip-router.org\n"); tm_ctx_set_branch_index(branch); diff --git a/modules/tm/t_stats.c b/modules/tm/t_stats.c index 8187568a3f0..28fe04e0997 100644 --- a/modules/tm/t_stats.c +++ b/modules/tm/t_stats.c @@ -93,8 +93,9 @@ void free_tm_stats() (res)->completed_5xx=(s1)->completed_5xx+(s2)->completed_5xx; \ (res)->completed_6xx=(s1)->completed_6xx+(s2)->completed_6xx; \ (res)->completed_2xx=(s1)->completed_2xx+(s2)->completed_2xx; \ - (res)->replied_locally=(s1)->replied_locally+(s2)->replied_locally; \ - (res)->replied_total=(s1)->replied_total+(s2)->replied_total; \ + (res)->received_replies=(s1)->received_replies+(s2)->received_replies; \ + (res)->relayed_locally=(s1)->relayed_locally+(s2)->relayed_locally; \ + (res)->relayed_total=(s1)->relayed_total+(s2)->relayed_total; \ (res)->deleted=(s1)->deleted+(s2)->deleted; \ }while(0) @@ -137,7 +138,9 @@ void tm_rpc_stats(rpc_t* rpc, void* c) (unsigned) waiting); rpc->struct_add(st, "d", "total", (unsigned) all.transactions); rpc->struct_add(st, "d", "total_local", (unsigned)all.client_transactions); - rpc->struct_add(st, "d", "replied_locally", (unsigned)all.replied_locally); + rpc->struct_add(st, "d", "received_replies", (unsigned)all.received_replies); + rpc->struct_add(st, "d", "relayed_locally", (unsigned)all.relayed_locally); + rpc->struct_add(st, "d", "relayed_total", (unsigned)all.relayed_total); rpc->struct_add(st, "ddddd", "6xx", (unsigned int)all.completed_6xx, "5xx", (unsigned int)all.completed_5xx, diff --git a/modules/tm/t_stats.h b/modules/tm/t_stats.h index dcb0be7660f..5be3c701d9c 100644 --- a/modules/tm/t_stats.h +++ b/modules/tm/t_stats.h @@ -43,8 +43,9 @@ struct t_proc_stats { /* number of transactions which completed with this status */ stat_counter completed_3xx, completed_4xx, completed_5xx, completed_6xx, completed_2xx; - stat_counter replied_locally; - stat_counter replied_total; + stat_counter received_replies; + stat_counter relayed_locally; + stat_counter relayed_total; stat_counter deleted; #ifdef TM_MORE_STATS /* number of created transactions */ @@ -121,15 +122,19 @@ inline static void update_reply_stats( int code ) { } } +inline void static t_stats_received_replies(void) +{ + tm_stats[process_no].s.received_replies++; +} -inline void static t_stats_replied_locally(void) +inline void static t_stats_relayed_locally(void) { - tm_stats[process_no].s.replied_locally++; + tm_stats[process_no].s.relayed_locally++; } -inline void static t_stats_replied_total(void) +inline void static t_stats_relayed_total(void) { - tm_stats[process_no].s.replied_total++; + tm_stats[process_no].s.relayed_total++; } diff --git a/modules/tmx/tmx_mod.c b/modules/tmx/tmx_mod.c index 10e509d0520..38a73ff2d0b 100644 --- a/modules/tmx/tmx_mod.c +++ b/modules/tmx/tmx_mod.c @@ -108,8 +108,10 @@ unsigned long tmx_stats_trans_6xx(void); unsigned long tmx_stats_trans_inuse(void); unsigned long tmx_stats_trans_active(void); unsigned long tmx_stats_rcv_rpls(void); -unsigned long tmx_stats_rld_rpls(void); -unsigned long tmx_stats_loc_rpls(void); +unsigned long tmx_stats_abs_rpls(void); +unsigned long tmx_stats_rld_rcv_rpls(void); +unsigned long tmx_stats_rld_loc_rpls(void); +unsigned long tmx_stats_rld_tot_rpls(void); static stat_export_t mod_stats[] = { {"UAS_transactions" , STAT_IS_FUNC, (stat_var**)tmx_stats_uas_trans }, @@ -122,8 +124,10 @@ static stat_export_t mod_stats[] = { {"inuse_transactions" , STAT_IS_FUNC, (stat_var**)tmx_stats_trans_inuse }, {"active_transactions" , STAT_IS_FUNC, (stat_var**)tmx_stats_trans_active}, {"received_replies" , STAT_IS_FUNC, (stat_var**)tmx_stats_rcv_rpls }, - {"relayed_replies" , STAT_IS_FUNC, (stat_var**)tmx_stats_rld_rpls }, - {"local_replies" , STAT_IS_FUNC, (stat_var**)tmx_stats_loc_rpls }, + {"received_replies_absorbed", STAT_IS_FUNC, (stat_var**)tmx_stats_abs_rpls }, + {"relayed_locally" , STAT_IS_FUNC, (stat_var**)tmx_stats_rld_loc_rpls}, + {"relayed_received" , STAT_IS_FUNC, (stat_var**)tmx_stats_rld_rcv_rpls}, + {"relayed_total" , STAT_IS_FUNC, (stat_var**)tmx_stats_rld_tot_rpls}, {0,0,0} }; #endif @@ -810,23 +814,31 @@ unsigned long tmx_stats_trans_active(void) unsigned long tmx_stats_rcv_rpls(void) { tmx_stats_update(); - return _tmx_stats_all.completed_6xx - + _tmx_stats_all.completed_5xx - + _tmx_stats_all.completed_4xx - + _tmx_stats_all.completed_3xx - + _tmx_stats_all.completed_2xx; + return _tmx_stats_all.received_replies; } -unsigned long tmx_stats_rld_rpls(void) +unsigned long tmx_stats_abs_rpls(void) { tmx_stats_update(); - return _tmx_stats_all.replied_total - _tmx_stats_all.replied_locally; + return _tmx_stats_all.received_replies - tmx_stats_rld_rcv_rpls(); } -unsigned long tmx_stats_loc_rpls(void) +unsigned long tmx_stats_rld_loc_rpls(void) { tmx_stats_update(); - return _tmx_stats_all.replied_locally; + return _tmx_stats_all.relayed_locally; +} + +unsigned long tmx_stats_rld_tot_rpls(void) +{ + tmx_stats_update(); + return _tmx_stats_all.relayed_total; +} + +unsigned long tmx_stats_rld_rcv_rpls(void) +{ + tmx_stats_update(); + return _tmx_stats_all.relayed_total - _tmx_stats_all.relayed_locally; } #endif