[sr-dev] git:5.2:76908b45: app_python3: use system time to compute execution duration

Daniel-Constantin Mierla miconda at gmail.com
Fri May 3 09:15:33 CEST 2019


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

Author: Daniel-Constantin Mierla <miconda at gmail.com>
Committer: Daniel-Constantin Mierla <miconda at gmail.com>
Date: 2019-05-03T09:11:22+02:00

app_python3: use system time to compute execution duration

(cherry picked from commit 9af0f27f664a2514e1b471411a2b8c362763fccf)

---

Modified: src/modules/app_python3/apy_kemi.c

---

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

---

diff --git a/src/modules/app_python3/apy_kemi.c b/src/modules/app_python3/apy_kemi.c
index b3812a6237..32d99913a4 100755
--- a/src/modules/app_python3/apy_kemi.c
+++ b/src/modules/app_python3/apy_kemi.c
@@ -699,24 +699,29 @@ PyObject *sr_apy_kemi_exec_func(PyObject *self, PyObject *args, int idx)
 {
 	sr_kemi_t *ket = NULL;
 	PyObject *ret = NULL;
-	unsigned int ms = 0;
 	PyThreadState *pstate = NULL;
 	PyFrameObject *pframe = NULL;
+	struct timeval tvb, tve;
+	struct timezone tz;
+	unsigned int tdiff;
 
 	ket = sr_apy_kemi_export_get(idx);
 	if(ket==NULL) {
 		return sr_kemi_apy_return_false();
 	}
-	if(unlikely(cfg_get(core, core_cfg, latency_limit_action)>0)) {
-		ms = TICKS_TO_MS(get_ticks_raw());
+	if(unlikely(cfg_get(core, core_cfg, latency_limit_action)>0)
+			&& is_printable(cfg_get(core, core_cfg, latency_log))) {
+		gettimeofday(&tvb, &tz);
 	}
 
 	ret = sr_apy_kemi_exec_func_ex(ket, self, args, idx);
 
-	if(unlikely(cfg_get(core, core_cfg, latency_limit_action)>0)) {
-		ms = TICKS_TO_MS(get_ticks_raw()) - ms;
-		if(ms >= cfg_get(core, core_cfg, latency_limit_action)
-				&& is_printable(cfg_get(core, core_cfg, latency_log))) {
+	if(unlikely(cfg_get(core, core_cfg, latency_limit_action)>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_action)) {
 			pstate = PyThreadState_GET();
 			if (pstate != NULL && pstate->frame != NULL) {
 				pframe = pstate->frame;
@@ -726,7 +731,7 @@ PyObject *sr_apy_kemi_exec_func(PyObject *self, PyObject *args, int idx)
 					"alert - action KSR.%s%s%s(...)"
 					" took too long [%u ms] (file:%s func:%s line:%d)\n",
 					(ket->mname.len>0)?ket->mname.s:"",
-					(ket->mname.len>0)?".":"", ket->fname.s, ms,
+					(ket->mname.len>0)?".":"", ket->fname.s, tdiff,
 					(pframe)?PyString_AsString(pframe->f_code->co_filename):"",
 					(pframe)?PyString_AsString(pframe->f_code->co_name):"",
 					(pframe)?PyCode_Addr2Line(pframe->f_code, pframe->f_lasti):0);




More information about the sr-dev mailing list