Module: kamailio
Branch: 5.2
Commit: cbef48a15d023ae602bb88bafdcf69d4e1b42e27
URL:
https://github.com/kamailio/kamailio/commit/cbef48a15d023ae602bb88bafdcf69d…
Author: Daniel-Constantin Mierla <miconda(a)gmail.com>
Committer: Daniel-Constantin Mierla <miconda(a)gmail.com>
Date: 2019-04-03T11:44:11+02:00
app_python: use system time to compute execution duration
(cherry picked from commit a300cf008b86dec22a1006328ab73c3ce399c6c3)
---
Modified: src/modules/app_python/apy_kemi.c
---
Diff:
https://github.com/kamailio/kamailio/commit/cbef48a15d023ae602bb88bafdcf69d…
Patch:
https://github.com/kamailio/kamailio/commit/cbef48a15d023ae602bb88bafdcf69d…
---
diff --git a/src/modules/app_python/apy_kemi.c b/src/modules/app_python/apy_kemi.c
index 2bb60b9948..5f2b4b3f8f 100644
--- a/src/modules/app_python/apy_kemi.c
+++ b/src/modules/app_python/apy_kemi.c
@@ -677,24 +677,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;
@@ -702,9 +707,9 @@ PyObject *sr_apy_kemi_exec_func(PyObject *self, PyObject *args, int
idx)
LOG(cfg_get(core, core_cfg, latency_log),
"alert - action KSR.%s%s%s(...)"
- " took too long [%u ms] (file:%s func:%s line:%d)\n",
+ " took too long [%u us] (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);