[sr-dev] git:5.2:a2de8372: lib/srdb1: use system time to compute db query execution duration

Daniel-Constantin Mierla miconda at gmail.com
Wed Apr 3 11:46:13 CEST 2019


Module: kamailio
Branch: 5.2
Commit: a2de837273c84c42233dd12829a8aca57257ce9f
URL: https://github.com/kamailio/kamailio/commit/a2de837273c84c42233dd12829a8aca57257ce9f

Author: Daniel-Constantin Mierla <miconda at gmail.com>
Committer: Daniel-Constantin Mierla <miconda at gmail.com>
Date: 2019-04-03T11:45:25+02:00

lib/srdb1: use system time to compute db query execution duration

(cherry picked from commit ce8d36f301d7688255597a67693e47dc14448650)

---

Modified: src/lib/srdb1/db_query.c

---

Diff:  https://github.com/kamailio/kamailio/commit/a2de837273c84c42233dd12829a8aca57257ce9f.diff
Patch: https://github.com/kamailio/kamailio/commit/a2de837273c84c42233dd12829a8aca57257ce9f.patch

---

diff --git a/src/lib/srdb1/db_query.c b/src/lib/srdb1/db_query.c
index b1900e4c2e..b2cd9056dc 100644
--- a/src/lib/srdb1/db_query.c
+++ b/src/lib/srdb1/db_query.c
@@ -32,6 +32,7 @@
 
 #include <stdio.h>
 #include <stdlib.h>
+#include <time.h>
 #include "../../core/dprint.h"
 #include "db_ut.h"
 #include "db_query.h"
@@ -45,19 +46,26 @@ static inline int db_do_submit_query(const db1_con_t* _h, const str *_query,
 		int (*submit_query)(const db1_con_t*, const str*))
 {
 	int ret;
-	unsigned int ms = 0;
+	struct timeval tvb, tve;
+	struct timezone tz;
+	unsigned int tdiff;
 
-	if(unlikely(cfg_get(core, core_cfg, latency_limit_db)>0))
-		ms = TICKS_TO_MS(get_ticks_raw());
+	if(unlikely(cfg_get(core, core_cfg, latency_limit_db)>0)
+			&& is_printable(cfg_get(core, core_cfg, latency_log))) {
+		gettimeofday(&tvb, &tz);
+	}
 
 	ret = submit_query(_h, _query);
 
-	if(unlikely(cfg_get(core, core_cfg, latency_limit_db)>0)) {
-		ms = TICKS_TO_MS(get_ticks_raw()) - ms;
-		if(ms >= cfg_get(core, core_cfg, latency_limit_db)) {
-				LOG(cfg_get(core, core_cfg, latency_log),
-					"alert - query execution too long [%u ms] for [%.*s]\n",
-				   ms, _query->len<50?_query->len:50, _query->s);
+	if(unlikely(cfg_get(core, core_cfg, latency_limit_db)>0)
+			&& is_printable(cfg_get(core, core_cfg, latency_log))) {
+		gettimeofday(&tve, &tz);
+		tdiff = (tve.tv_sec - tvb.tv_sec) * 1000000
+					   + (tve.tv_usec - tvb.tv_usec);
+		if(tdiff >= cfg_get(core, core_cfg, latency_limit_db)) {
+			LOG(cfg_get(core, core_cfg, latency_log),
+					"alert - query execution too long [%u us] for [%.*s]\n",
+				   tdiff, _query->len<100?_query->len:100, _query->s);
 		}
 	}
 




More information about the sr-dev mailing list