3dcd857
From 09f738ced164b3b347cd4865c11a4e7c45de25e3 Mon Sep 17 00:00:00 2001
3dcd857
From: =?UTF-8?q?S=C3=BCmer=20Cip?= <sumer.cip@platform.sh>
3dcd857
Date: Thu, 4 Aug 2022 14:04:47 +0300
3dcd857
Subject: [PATCH 04/11] 6 failures in TCs
3dcd857
3dcd857
---
3dcd857
 yappi/_yappi.c | 57 ++++++++++++++++++++++++++------------------------
3dcd857
 1 file changed, 30 insertions(+), 27 deletions(-)
3dcd857
3dcd857
diff --git a/yappi/_yappi.c b/yappi/_yappi.c
3dcd857
index 00fdbd4..d2f0af4 100644
3dcd857
--- a/yappi/_yappi.c
3dcd857
+++ b/yappi/_yappi.c
3dcd857
@@ -1292,17 +1292,37 @@ _resume_greenlet_ctx(_ctx *ctx)
3dcd857
     ydprintf("resuming context: %ld, shift: %lld", ctx->id, shift);
3dcd857
 }
3dcd857
 
3dcd857
+static void 
3dcd857
+_eval_setprofile(PyThreadState *ts)
3dcd857
+{
3dcd857
+#if PY_VERSION_HEX < 0x030a00b1
3dcd857
+    ts->use_tracing = 1;
3dcd857
+#else
3dcd857
+    ts->cframe->use_tracing = 1;
3dcd857
+#endif
3dcd857
+    ts->c_profilefunc = _yapp_callback;
3dcd857
+
3dcd857
+    //_update_tracing_state()
3dcd857
+
3dcd857
+//  todo: do this only for 3.11
3dcd857
+    ts->cframe->use_tracing = 255;
3dcd857
+}
3dcd857
+
3dcd857
+static void
3dcd857
+_eval_unsetprofile(PyThreadState *ts)
3dcd857
+{
3dcd857
+#if PY_VERSION_HEX < 0x030a00b1
3dcd857
+    ts->use_tracing = 0;
3dcd857
+#else
3dcd857
+    ts->cframe->use_tracing = 0;
3dcd857
+#endif
3dcd857
+    ts->c_profilefunc = NULL;
3dcd857
+}
3dcd857
+
3dcd857
 static _ctx *
3dcd857
 _bootstrap_thread(PyThreadState *ts)
3dcd857
 {
3dcd857
-// #if PY_VERSION_HEX < 0x030a00b1
3dcd857
-//     ts->use_tracing = 1;
3dcd857
-// #else
3dcd857
-//     ts->cframe->use_tracing = 1;
3dcd857
-// #endif
3dcd857
-//     ts->c_profilefunc = _yapp_callback;
3dcd857
-    PyEval_SetProfile(_yapp_callback, NULL);
3dcd857
-
3dcd857
+    _eval_setprofile(ts);
3dcd857
     return NULL;
3dcd857
 }
3dcd857
 
3dcd857
@@ -1331,16 +1351,7 @@ _profile_thread(PyThreadState *ts)
3dcd857
     } else {
3dcd857
         ctx = (_ctx *)it->val;
3dcd857
     }
3dcd857
-    
3dcd857
-// #if PY_VERSION_HEX < 0x030a00b1
3dcd857
-//     ts->use_tracing = 1;
3dcd857
-// #else
3dcd857
-//     ts->cframe->use_tracing = 1;
3dcd857
-// #endif
3dcd857
-//     ts->c_profilefunc = _yapp_callback;
3dcd857
-    // TODO: How to do this for all threads?
3dcd857
-    PyEval_SetProfile(_yapp_callback, NULL);
3dcd857
-
3dcd857
+    _eval_setprofile(ts);
3dcd857
     ctx->id = ctx_id;
3dcd857
     ctx->tid = ts->thread_id;
3dcd857
     ctx->ts_ptr = ts;
3dcd857
@@ -1356,15 +1367,7 @@ _profile_thread(PyThreadState *ts)
3dcd857
 static _ctx*
3dcd857
 _unprofile_thread(PyThreadState *ts)
3dcd857
 {
3dcd857
-// #if PY_VERSION_HEX < 0x030a00b1
3dcd857
-//     ts->use_tracing = 0;
3dcd857
-// #else
3dcd857
-//     ts->cframe->use_tracing = 0;
3dcd857
-// #endif
3dcd857
-//     ts->c_profilefunc = NULL;
3dcd857
-
3dcd857
-    // TODO: How to do this for all threads?
3dcd857
-    PyEval_SetProfile(NULL, NULL);
3dcd857
+    _eval_unsetprofile(ts);
3dcd857
 
3dcd857
     return NULL; //dummy return for enum_threads() func. prototype
3dcd857
 }
3dcd857
-- 
3dcd857
2.34.1
3dcd857