Current execution frame of another thread?

S

skip

I would like to try a sampling approach to profiling. My thought is to have
a profiling thread that samples the execution frame of all the other
started threads. I don't see any path from the threads returned by
threading.enumerate() to their current frames. Am I missing something?

Thx,

Skip
 
D

Diez B. Roggisch

I would like to try a sampling approach to profiling. My thought is to have
a profiling thread that samples the execution frame of all the other
started threads. I don't see any path from the threads returned by
threading.enumerate() to their current frames. Am I missing something?

I doubt that works. As python uses the OS underlying threading model, it
doesnn't know about the internal management structures - and even it
knew, these had to be carefully designed for that exact purposes of
yours, as the stack frame can only be safely inspected by the thread
_running_ in it.

An external thread could be interrupted at all times while traversing
other threads management structures, and then find a corrupted memory
location when it is re-scheduled.

Maybe one could write a threading model that allwos for hooks in the
scheduler (which has all the time in the world for such stuff) - but I'm
not aware that that's possible under e.g. pthreads, so there is unlikely
a python-way to do so.

Regards,

Diez
 
D

Diez B. Roggisch

I would like to try a sampling approach to profiling. My thought is to have
a profiling thread that samples the execution frame of all the other
started threads. I don't see any path from the threads returned by
threading.enumerate() to their current frames. Am I missing something?


Just another thought: Maybe stackless python can be of use here - as it
epxlicits the stack frame, you might be able to inspect it. But I
_think_ basically the same limitations apply as in my other post - you'd
need to be able to stop a thread, scan its frame, and reschedule it.

Diez
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,537
Members
45,021
Latest member
AkilahJaim

Latest Threads

Top