Module: kamailio Branch: master Commit: 9af0f27f664a2514e1b471411a2b8c362763fccf URL: https://github.com/kamailio/kamailio/commit/9af0f27f664a2514e1b471411a2b8c36...
Author: Daniel-Constantin Mierla miconda@gmail.com Committer: Daniel-Constantin Mierla miconda@gmail.com Date: 2019-04-01T12:16:58+02:00
app_python3: use system time to compute execution duration
---
Modified: src/modules/app_python3/apy_kemi.c
---
Diff: https://github.com/kamailio/kamailio/commit/9af0f27f664a2514e1b471411a2b8c36... Patch: https://github.com/kamailio/kamailio/commit/9af0f27f664a2514e1b471411a2b8c36...
---
diff --git a/src/modules/app_python3/apy_kemi.c b/src/modules/app_python3/apy_kemi.c index baa2eccb90..18f9dd6aa6 100755 --- a/src/modules/app_python3/apy_kemi.c +++ b/src/modules/app_python3/apy_kemi.c @@ -728,24 +728,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; @@ -755,7 +760,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);