handy way to spot-profile a python program (watch+pstat+tac)

M

Mike

Someone (forget who) mentioned recently that you could get some "poor
man's" profiling info by attaching to a running python with gdb, and
periodically grabbing a stack trace.

I figured out that there's a handy way to do this with this command:

watch -n 1 'pstack 30154 | tac'

which will show a full-screen stack dump once per second on the python
with pid 30154. (It works with non-Python, too--the 'p' is apparently
for "process", not "python".)

If the interesting part runs off the bottom of your screen, you can
always leave off the tac, though that makes it a bit jumpier.

(pstack uses the ptrace interface, which may annoy the parents of this
process if they're paying attention (which is not usually the case).)

Have fun,
Mike
 

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
474,297
Messages
2,571,536
Members
48,283
Latest member
SherriP988

Latest Threads

Top