Browse code

app_python3: use new Python 3.10+ API functions for tracking execution

- GH #3187

Daniel-Constantin Mierla authored on 21/07/2022 18:15:29
Showing 1 changed files
... ...
@@ -1810,6 +1810,9 @@ PyObject *sr_apy_kemi_exec_func(PyObject *self, PyObject *args, int idx)
1810 1810
 	PyObject *ret = NULL;
1811 1811
 	PyThreadState *pstate = NULL;
1812 1812
 	PyFrameObject *pframe = NULL;
1813
+#if PY_VERSION_HEX >= 0x03100000
1814
+	PyCodeObject *pcode = NULL;
1815
+#endif
1813 1816
 	struct timeval tvb = {0}, tve = {0};
1814 1817
 	struct timezone tz;
1815 1818
 	unsigned int tdiff;
... ...
@@ -1832,10 +1835,27 @@ PyObject *sr_apy_kemi_exec_func(PyObject *self, PyObject *args, int idx)
1832 1835
 				   + (tve.tv_usec - tvb.tv_usec);
1833 1836
 		if(tdiff >= cfg_get(core, core_cfg, latency_limit_action)) {
1834 1837
 			pstate = PyThreadState_GET();
1835
-			if (pstate != NULL && pstate->frame != NULL) {
1838
+			if (pstate != NULL) {
1839
+#if PY_VERSION_HEX >= 0x03100000
1840
+				pframe = PyThreadState_GetFrame(pstate);
1841
+				if(pframe != NULL) {
1842
+					pcode = PyFrame_GetCode(pframe);
1843
+				}
1844
+#else
1836 1845
 				pframe = pstate->frame;
1846
+#endif
1837 1847
 			}
1838 1848
 
1849
+#if PY_VERSION_HEX >= 0x03100000
1850
+			LOG(cfg_get(core, core_cfg, latency_log),
1851
+					"alert - action KSR.%s%s%s(...)"
1852
+					" took too long [%u ms] (file:%s func:%s line:%d)\n",
1853
+					(ket->mname.len>0)?ket->mname.s:"",
1854
+					(ket->mname.len>0)?".":"", ket->fname.s, tdiff,
1855
+					(pcode)?PyBytes_AsString(pcode->co_filename):"",
1856
+					(pcode)?PyBytes_AsString(pcode->co_name):"",
1857
+					(pframe)?PyFrame_GetLineNumber(pframe):0);
1858
+#else
1839 1859
 			LOG(cfg_get(core, core_cfg, latency_log),
1840 1860
 					"alert - action KSR.%s%s%s(...)"
1841 1861
 					" took too long [%u ms] (file:%s func:%s line:%d)\n",
... ...
@@ -1844,6 +1864,7 @@ PyObject *sr_apy_kemi_exec_func(PyObject *self, PyObject *args, int idx)
1844 1864
 					(pframe && pframe->f_code)?PyBytes_AsString(pframe->f_code->co_filename):"",
1845 1865
 					(pframe && pframe->f_code)?PyBytes_AsString(pframe->f_code->co_name):"",
1846 1866
 					(pframe && pframe->f_code)?PyCode_Addr2Line(pframe->f_code, pframe->f_lasti):0);
1867
+#endif
1847 1868
 		}
1848 1869
 	}
1849 1870