Module: kamailio
Branch: master
Commit: 319d925187149d3fdb373938662dc28a1687d43c
URL:
https://github.com/kamailio/kamailio/commit/319d925187149d3fdb373938662dc28…
Author: Daniel-Constantin Mierla <miconda(a)gmail.com>
Committer: Daniel-Constantin Mierla <miconda(a)gmail.com>
Date: 2020-06-25T09:17:38+02:00
dlgs: update stats on hash table slots
---
Modified: src/modules/dlgs/dlgs_records.c
Modified: src/modules/dlgs/dlgs_records.h
---
Diff:
https://github.com/kamailio/kamailio/commit/319d925187149d3fdb373938662dc28…
Patch:
https://github.com/kamailio/kamailio/commit/319d925187149d3fdb373938662dc28…
---
diff --git a/src/modules/dlgs/dlgs_records.c b/src/modules/dlgs/dlgs_records.c
index 1a21f355db..6fcfa50945 100644
--- a/src/modules/dlgs/dlgs_records.c
+++ b/src/modules/dlgs/dlgs_records.c
@@ -496,11 +496,39 @@ int dlgs_ht_dbg(void)
return 0;
}
+/**
+ *
+ */
+void dlgs_update_stats(dlgs_stats_t *stats, int state, int val)
+{
+ switch(state) {
+ case DLGS_STATE_INIT:
+ stats->c_init += val;
+ return;
+ case DLGS_STATE_PROGRESS:
+ stats->c_progress += val;
+ return;
+ case DLGS_STATE_ANSWERED:
+ stats->c_answered += val;
+ return;
+ case DLGS_STATE_CONFIRMED:
+ stats->c_confirmed += val;
+ return;
+ case DLGS_STATE_TERMINATED:
+ stats->c_terminted += val;
+ return;
+ case DLGS_STATE_NOTANSWERED:
+ stats->c_notanswered += val;
+ return;
+ }
+}
+
/**
*
*/
int dlgs_update_item(sip_msg_t *msg)
{
+ unsigned int idx;
int rtype = 0;
int rmethod = 0;
int rcode = 0;
@@ -534,24 +562,31 @@ int dlgs_update_item(sip_msg_t *msg)
LM_DBG("no matching item found\n");
return 0;
}
+ idx = dlgs_get_index(it->hashid, _dlgs_htb->htsize);
ostate = it->state;
if(rtype == SIP_REQUEST) {
switch(rmethod) {
case METHOD_ACK:
if(it->state==DLGS_STATE_ANSWERED) {
+ dlgs_update_stats(&_dlgs_htb->slots[idx].astats, it->state, -1);
it->state = DLGS_STATE_CONFIRMED;
+ dlgs_update_stats(&_dlgs_htb->slots[idx].astats, it->state, 1);
}
break;
case METHOD_CANCEL:
if(it->state<DLGS_STATE_ANSWERED) {
+ dlgs_update_stats(&_dlgs_htb->slots[idx].astats, it->state, -1);
it->state = DLGS_STATE_NOTANSWERED;
+ dlgs_update_stats(&_dlgs_htb->slots[idx].astats, it->state, 1);
it->ts_finish = tnow;
}
break;
case METHOD_BYE:
if(it->state==DLGS_STATE_ANSWERED
|| it->state==DLGS_STATE_CONFIRMED) {
+ dlgs_update_stats(&_dlgs_htb->slots[idx].astats, it->state, -1);
it->state = DLGS_STATE_TERMINATED;
+ dlgs_update_stats(&_dlgs_htb->slots[idx].astats, it->state, 1);
it->ts_finish = tnow;
}
break;
@@ -563,12 +598,16 @@ int dlgs_update_item(sip_msg_t *msg)
case METHOD_INVITE:
if(rcode>=100 && rcode<200) {
if(it->state==DLGS_STATE_INIT) {
+ dlgs_update_stats(&_dlgs_htb->slots[idx].astats, it->state, -1);
it->state = DLGS_STATE_PROGRESS;
+ dlgs_update_stats(&_dlgs_htb->slots[idx].astats, it->state, 1);
}
} else if(rcode>=200 && rcode<300) {
if(it->state==DLGS_STATE_INIT
|| it->state==DLGS_STATE_PROGRESS) {
+ dlgs_update_stats(&_dlgs_htb->slots[idx].astats, it->state, -1);
it->state = DLGS_STATE_ANSWERED;
+ dlgs_update_stats(&_dlgs_htb->slots[idx].astats, it->state, 1);
it->ts_answer = tnow;
if(it->ttag.len<=0) {
to_body_t *tb;
@@ -583,7 +622,9 @@ int dlgs_update_item(sip_msg_t *msg)
} else if(rcode>=300) {
if(it->state==DLGS_STATE_INIT
|| it->state==DLGS_STATE_PROGRESS) {
+ dlgs_update_stats(&_dlgs_htb->slots[idx].astats, it->state, -1);
it->state = DLGS_STATE_NOTANSWERED;
+ dlgs_update_stats(&_dlgs_htb->slots[idx].astats, it->state, 1);
it->ts_finish = tnow;
}
}
diff --git a/src/modules/dlgs/dlgs_records.h b/src/modules/dlgs/dlgs_records.h
index 6ecd668d76..189f468c85 100644
--- a/src/modules/dlgs/dlgs_records.h
+++ b/src/modules/dlgs/dlgs_records.h
@@ -47,6 +47,8 @@ typedef struct _dlgs_stats {
unsigned int c_notanswered;
} dlgs_stats_t;
+void dlgs_update_stats(dlgs_stats_t *stats, int state, int val);
+
typedef struct _dlgs_item {
unsigned int hashid; /* item hash id */
str callid; /* sip call-id */
@@ -67,7 +69,8 @@ typedef struct _dlgs_item {
typedef struct _dlgs_slot {
unsigned int esize;
dlgs_item_t *first;
- gen_lock_t lock;
+ dlgs_stats_t astats;
+ gen_lock_t lock;
} dlgs_slot_t;
typedef struct _dlgs_ht {
@@ -103,4 +106,4 @@ int dlgs_destroy(void);
int dlgs_rpc_init(void);
int dlgs_update_item(sip_msg_t *msg);
-#endif
\ No newline at end of file
+#endif