How to Profile Python Code

by @jehiah on 2008-10-18 05:34UTC
Filed under: All , Python , Web

I have been doing some Google App Engine development, and I happened across this block of code which quite possibly outputs the best per-page load python performance statistics that I’ve ever seen.

http://code.google.com/appengine/kb/commontasks.html#profiling

  • The code to run the performance statistics is simple
  • The output is comprehensive

It doesn’t get better than that. Here is a sample snippet from the output

387856 function calls (383171 primitive calls) in 0.725 CPU seconds

Ordered by: internal time
List reduced from 802 to 120 due to restriction <120>

ncalls  tottime  percall  cumtime  percall filename:lineno(function)
94    0.119    0.001    0.119    0.001 {built-in method __new__ of type object at 0x1f19a0}
28731    0.051    0.000    0.066    0.000 /Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/google/net/proto/ProtocolBuffer.py:295(putVarUint64)
28731    0.040    0.000    0.106    0.000 /Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/google/net/proto/ProtocolBuffer.py:287(putVarInt64)
28053    0.040    0.000    0.138    0.000 /Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/google/net/proto/ProtocolBuffer.py:281(putVarInt32)
5220    0.018    0.000    0.049    0.000 /Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/google/net/proto/ProtocolBuffer.py:328(putPrefixedString)
Subscribe via RSS ı Email
Jehiah Czebotar