Module: kamailio
Branch: 5.2
Commit: 3f9d2b733b454ce27e21c3dbddb9953f079f47d4
URL:
https://github.com/kamailio/kamailio/commit/3f9d2b733b454ce27e21c3dbddb9953…
Author: Daniel-Constantin Mierla <miconda(a)gmail.com>
Committer: Daniel-Constantin Mierla <miconda(a)gmail.com>
Date: 2019-03-10T10:56:58+01:00
app_python: execution log message based on core latency_limit_action
(cherry picked from commit a2915a9fc3d974e85829ccb6ea22d655124d4463)
---
Modified: src/modules/app_python/apy_kemi.c
---
Diff:
https://github.com/kamailio/kamailio/commit/3f9d2b733b454ce27e21c3dbddb9953…
Patch:
https://github.com/kamailio/kamailio/commit/3f9d2b733b454ce27e21c3dbddb9953…
---
diff --git a/src/modules/app_python/apy_kemi.c b/src/modules/app_python/apy_kemi.c
index 1de3b3b3fe..2bb60b9948 100644
--- a/src/modules/app_python/apy_kemi.c
+++ b/src/modules/app_python/apy_kemi.c
@@ -23,12 +23,14 @@
#include <stdlib.h>
#include <Python.h>
+#include <frameobject.h>
#include "../../core/dprint.h"
#include "../../core/route.h"
#include "../../core/fmsg.h"
#include "../../core/kemi.h"
#include "../../core/pvar.h"
+#include "../../core/timer.h"
#include "../../core/mem/pkg.h"
#include "../../core/mem/shm.h"
#include "../../core/rpc.h"
@@ -160,15 +162,16 @@ PyObject *sr_apy_kemi_return_str(sr_kemi_t *ket, char *sval, int
slen)
{
return PyString_FromStringAndSize(sval, slen);
}
+
/**
*
*/
-PyObject *sr_apy_kemi_exec_func(PyObject *self, PyObject *args, int idx)
+PyObject *sr_apy_kemi_exec_func_ex(sr_kemi_t *ket, PyObject *self,
+ PyObject *args, int idx)
{
str fname;
int i;
int ret;
- sr_kemi_t *ket = NULL;
sr_kemi_val_t vps[SR_KEMI_PARAMS_MAX];
sr_apy_env_t *env_P;
sip_msg_t *lmsg = NULL;
@@ -185,10 +188,6 @@ PyObject *sr_apy_kemi_exec_func(PyObject *self, PyObject *args, int
idx)
lmsg = env_P->msg;
}
- ket = sr_apy_kemi_export_get(idx);
- if(ket==NULL) {
- return sr_kemi_apy_return_false();
- }
if(ket->mname.len>0) {
LM_DBG("execution of method: %.*s\n", ket->fname.len, ket->fname.s);
} else {
@@ -671,6 +670,50 @@ PyObject *sr_apy_kemi_exec_func(PyObject *self, PyObject *args, int
idx)
}
}
+/**
+ *
+ */
+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;
+
+ 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());
+ }
+
+ 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))) {
+ pstate = PyThreadState_GET();
+ if (pstate != NULL && pstate->frame != NULL) {
+ pframe = pstate->frame;
+ }
+
+ 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",
+ (ket->mname.len>0)?ket->mname.s:"",
+ (ket->mname.len>0)?".":"", ket->fname.s, ms,
+ (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);
+ }
+ }
+
+ return ret;
+}
+
/**
*
*/