Module: kamailio Branch: 5.5 Commit: 5f54afdc829c1325795db7a0a45afb12e9b72103 URL: https://github.com/kamailio/kamailio/commit/5f54afdc829c1325795db7a0a45afb12e9b72103
Author: Daniel-Constantin Mierla <[email protected]> Committer: Victor Seva <[email protected]> Date: 2023-05-08T15:48:13+02:00 app_python3: use new Python 3.10+ API functions for tracking execution - GH #3187 (cherry picked from commit b8bf86eb11a17c853450e5c7f81d2446cf719fbc) (cherry picked from commit 92f15de3d026405c749ce10fb4b11200c9b365b1) --- Modified: src/modules/app_python3/apy_kemi.c --- Diff: https://github.com/kamailio/kamailio/commit/5f54afdc829c1325795db7a0a45afb12e9b72103.diff Patch: https://github.com/kamailio/kamailio/commit/5f54afdc829c1325795db7a0a45afb12e9b72103.patch --- diff --git a/src/modules/app_python3/apy_kemi.c b/src/modules/app_python3/apy_kemi.c index f3463a781fe..48e8233f3c7 100644 --- a/src/modules/app_python3/apy_kemi.c +++ b/src/modules/app_python3/apy_kemi.c @@ -1791,6 +1791,9 @@ PyObject *sr_apy_kemi_exec_func(PyObject *self, PyObject *args, int idx) PyObject *ret = NULL; PyThreadState *pstate = NULL; PyFrameObject *pframe = NULL; +#if PY_VERSION_HEX >= 0x03100000 + PyCodeObject *pcode = NULL; +#endif struct timeval tvb = {0}, tve = {0}; struct timezone tz; unsigned int tdiff; @@ -1813,10 +1816,27 @@ PyObject *sr_apy_kemi_exec_func(PyObject *self, PyObject *args, int idx) + (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) { + if (pstate != NULL) { +#if PY_VERSION_HEX >= 0x03100000 + pframe = PyThreadState_GetFrame(pstate); + if(pframe != NULL) { + pcode = PyFrame_GetCode(pframe); + } +#else pframe = pstate->frame; +#endif } +#if PY_VERSION_HEX >= 0x03100000 + 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, tdiff, + (pcode)?PyBytes_AsString(pcode->co_filename):"", + (pcode)?PyBytes_AsString(pcode->co_name):"", + (pframe)?PyFrame_GetLineNumber(pframe):0); +#else 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", @@ -1825,6 +1845,7 @@ PyObject *sr_apy_kemi_exec_func(PyObject *self, PyObject *args, int idx) (pframe && pframe->f_code)?PyBytes_AsString(pframe->f_code->co_filename):"", (pframe && pframe->f_code)?PyBytes_AsString(pframe->f_code->co_name):"", (pframe && pframe->f_code)?PyCode_Addr2Line(pframe->f_code, pframe->f_lasti):0); +#endif } } _______________________________________________ Kamailio (SER) - Development Mailing List To unsubscribe send an email to [email protected]
