469,600 Members | 2,176 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,600 developers. It's quick & easy.

Current execution frame of another thread?

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

Nov 22 '05 #1
4 2071
sk**@pobox.com wrote:
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
Nov 22 '05 #2
sk**@pobox.com wrote:
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
Nov 22 '05 #3
sk**@pobox.com wrote:
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
Nov 22 '05 #4
sk**@pobox.com wrote:
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
Nov 22 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

4 posts views Thread by Don | last post: by
4 posts views Thread by Vlad | last post: by
1 post views Thread by Stropher | last post: by
10 posts views Thread by greenb | last post: by
reply views Thread by skip | last post: by
1 post views Thread by Selva Chinnasamy | last post: by
42 posts views Thread by smerf | last post: by
10 posts views Thread by Michael B. Trausch | last post: by
4 posts views Thread by guiromero | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.