Blame SOURCES/0005-Use-_PyEval_SetProfile-instead-of-manually-updating-.patch

rdobuilder 0a9e34
From 4d9c0667a24ead349333c47752747e51baa02d42 Mon Sep 17 00:00:00 2001
rdobuilder 0a9e34
From: =?UTF-8?q?S=C3=BCmer=20Cip?= <sumer.cip@platform.sh>
rdobuilder 0a9e34
Date: Thu, 18 Aug 2022 12:15:59 +0300
rdobuilder 0a9e34
Subject: [PATCH 05/11] Use _PyEval_SetProfile instead of manually updating
rdobuilder 0a9e34
 internal structures to enable per profiler per threadstate
rdobuilder 0a9e34
rdobuilder 0a9e34
---
rdobuilder 0a9e34
 yappi/_yappi.c | 29 +++++++++++++++++------------
rdobuilder 0a9e34
 1 file changed, 17 insertions(+), 12 deletions(-)
rdobuilder 0a9e34
rdobuilder 0a9e34
diff --git a/yappi/_yappi.c b/yappi/_yappi.c
rdobuilder 0a9e34
index d2f0af4..5a3f78a 100644
rdobuilder 0a9e34
--- a/yappi/_yappi.c
rdobuilder 0a9e34
+++ b/yappi/_yappi.c
rdobuilder 0a9e34
@@ -25,6 +25,10 @@
rdobuilder 0a9e34
 #include "mem.h"
rdobuilder 0a9e34
 #include "tls.h"
rdobuilder 0a9e34
 
rdobuilder 0a9e34
+#if PY_VERSION_HEX > 0x030b0000
rdobuilder 0a9e34
+#include "internal/pycore_code.h"
rdobuilder 0a9e34
+#endif
rdobuilder 0a9e34
+
rdobuilder 0a9e34
 #define SUPPRESS_WARNING(a) (void)a
rdobuilder 0a9e34
 
rdobuilder 0a9e34
 #ifdef IS_PY3K
rdobuilder 0a9e34
@@ -683,9 +687,8 @@ _code2pit(PyFrameObject *fobj, uintptr_t current_tag)
rdobuilder 0a9e34
     Py_INCREF(cobj);
rdobuilder 0a9e34
 
rdobuilder 0a9e34
     if (cobj->co_argcount) {
rdobuilder 0a9e34
-        // todo: this is said to be slower. Maybe there is a better alternative 
rdobuilder 0a9e34
-        // like _PyCode_GetVarnames(..). See https://discuss.python.org/t/python-3-11-frame-structure-and-various-changes/17895
rdobuilder 0a9e34
-        PyObject *co_varnames = PyObject_GetAttrString((PyObject *)cobj, "co_varnames");
rdobuilder 0a9e34
+        // todo: 3.12 this might be a public API
rdobuilder 0a9e34
+        PyObject *co_varnames = _PyCode_GetVarnames(cobj);
rdobuilder 0a9e34
         const char *firstarg = PyStr_AS_CSTRING(PyTuple_GET_ITEM(co_varnames, 0));
rdobuilder 0a9e34
 
rdobuilder 0a9e34
         if (!strcmp(firstarg, "self")) {
rdobuilder 0a9e34
@@ -1295,28 +1298,30 @@ _resume_greenlet_ctx(_ctx *ctx)
rdobuilder 0a9e34
 static void 
rdobuilder 0a9e34
 _eval_setprofile(PyThreadState *ts)
rdobuilder 0a9e34
 {
rdobuilder 0a9e34
-#if PY_VERSION_HEX < 0x030a00b1
rdobuilder 0a9e34
+#if PY_VERSION_HEX > 0x030b0000
rdobuilder 0a9e34
+    _PyEval_SetProfile(ts, _yapp_callback, NULL);
rdobuilder 0a9e34
+    //    ts->cframe->use_tracing = 255;
rdobuilder 0a9e34
+#elif PY_VERSION_HEX < 0x030a00b1
rdobuilder 0a9e34
     ts->use_tracing = 1;
rdobuilder 0a9e34
+    ts->c_profilefunc = _yapp_callback;
rdobuilder 0a9e34
 #else
rdobuilder 0a9e34
     ts->cframe->use_tracing = 1;
rdobuilder 0a9e34
-#endif
rdobuilder 0a9e34
     ts->c_profilefunc = _yapp_callback;
rdobuilder 0a9e34
-
rdobuilder 0a9e34
-    //_update_tracing_state()
rdobuilder 0a9e34
-
rdobuilder 0a9e34
-//  todo: do this only for 3.11
rdobuilder 0a9e34
-    ts->cframe->use_tracing = 255;
rdobuilder 0a9e34
+#endif
rdobuilder 0a9e34
 }
rdobuilder 0a9e34
 
rdobuilder 0a9e34
 static void
rdobuilder 0a9e34
 _eval_unsetprofile(PyThreadState *ts)
rdobuilder 0a9e34
 {
rdobuilder 0a9e34
-#if PY_VERSION_HEX < 0x030a00b1
rdobuilder 0a9e34
+#if PY_VERSION_HEX > 0x030b0000
rdobuilder 0a9e34
+    _PyEval_SetProfile(ts, NULL, NULL);
rdobuilder 0a9e34
+#elif PY_VERSION_HEX < 0x030a00b1
rdobuilder 0a9e34
     ts->use_tracing = 0;
rdobuilder 0a9e34
+    ts->c_profilefunc = NULL;
rdobuilder 0a9e34
 #else
rdobuilder 0a9e34
     ts->cframe->use_tracing = 0;
rdobuilder 0a9e34
-#endif
rdobuilder 0a9e34
     ts->c_profilefunc = NULL;
rdobuilder 0a9e34
+#endif
rdobuilder 0a9e34
 }
rdobuilder 0a9e34
 
rdobuilder 0a9e34
 static _ctx *
rdobuilder 0a9e34
-- 
rdobuilder 0a9e34
2.34.1
rdobuilder 0a9e34