Skip to content

Commit 6eed774

Browse files
authored
Merge branch 'main' into taegyunkim/prof-12244-ub
2 parents 0b6b994 + f0ed225 commit 6eed774

3 files changed

Lines changed: 34 additions & 10 deletions

File tree

echion/coremodule.cc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ static void do_where(std::ostream& stream)
4444
WhereRenderer::get().render_message("\r🐴 Echion reporting for duty");
4545
WhereRenderer::get().render_message("");
4646

47-
for_each_interp([](PyInterpreterState* interp) -> void {
47+
for_each_interp([](InterpreterInfo& interp) -> void {
4848
for_each_thread(interp, [](PyThreadState* tstate, ThreadInfo& thread) -> void {
4949
thread.unwind(tstate);
5050
WhereRenderer::get().render_thread_begin(tstate, thread.name, /*cpu_time*/ 0,
@@ -214,9 +214,9 @@ static inline void _sampler()
214214
{
215215
microsecond_t wall_time = now - last_time;
216216

217-
for_each_interp([=](PyInterpreterState* interp) -> void {
217+
for_each_interp([=](InterpreterInfo& interp) -> void {
218218
for_each_thread(interp, [=](PyThreadState* tstate, ThreadInfo& thread) {
219-
thread.sample(interp->id, tstate, wall_time);
219+
thread.sample(interp.id, tstate, wall_time);
220220
});
221221
});
222222
}

echion/interp.h

Lines changed: 29 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,34 @@
2020
#include <echion/state.h>
2121
#include <echion/vm.h>
2222

23-
static void for_each_interp(std::function<void(PyInterpreterState* interp)> callback)
23+
24+
class InterpreterInfo
25+
{
26+
public:
27+
int64_t id = 0;
28+
void* tstate_head = NULL;
29+
void* next = NULL;
30+
};
31+
32+
static void for_each_interp(std::function<void(InterpreterInfo& interp)> callback)
2433
{
25-
PyInterpreterState interp;
26-
for (PyInterpreterState* interp_addr = runtime->interpreters.head;
27-
!copy_type(interp_addr, interp); interp_addr = interp.next)
28-
callback(&interp);
34+
InterpreterInfo interpreter_info = {0};
35+
36+
for (char* interp_addr = (char*)runtime->interpreters.head; interp_addr != NULL;
37+
interp_addr = (char*)interpreter_info.next)
38+
{
39+
if (copy_type(interp_addr + offsetof(PyInterpreterState, id), interpreter_info.id))
40+
continue;
41+
#if PY_VERSION_HEX >= 0x030b0000
42+
if (copy_type(interp_addr + offsetof(PyInterpreterState, threads.head),
43+
#else
44+
if (copy_type(interp_addr + offsetof(PyInterpreterState, tstate_head),
45+
#endif
46+
interpreter_info.tstate_head))
47+
continue;
48+
if (copy_type(interp_addr + offsetof(PyInterpreterState, next), interpreter_info.next))
49+
continue;
50+
51+
callback(interpreter_info);
52+
};
2953
}

echion/threads.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -472,7 +472,7 @@ void ThreadInfo::sample(int64_t iid, PyThreadState* tstate, microsecond_t delta)
472472
}
473473

474474
// ----------------------------------------------------------------------------
475-
static void for_each_thread(PyInterpreterState* interp,
475+
static void for_each_thread(InterpreterInfo& interp,
476476
std::function<void(PyThreadState*, ThreadInfo&)> callback)
477477
{
478478
std::unordered_set<PyThreadState*> threads;
@@ -482,7 +482,7 @@ static void for_each_thread(PyInterpreterState* interp,
482482
seen_threads.clear();
483483

484484
// Start from the thread list head
485-
threads.insert(PyInterpreterState_ThreadHead(interp));
485+
threads.insert((PyThreadState*)interp.tstate_head);
486486

487487
while (!threads.empty())
488488
{

0 commit comments

Comments
 (0)