|
LayerProfiler
Layer interactive profiler
Layer ProfilerThe Layer Profiler is an interface to profile a running program in real time, and browse and compare profile data later. Download it and see how to use it for your code.
The Layer Profiler can be started as a standalone executable to browse previous profiles, imported into a Pygame, pyglet, or PyGTK program to profile in real time, or used similar to profile.py to present a report after program execution is finished (if the program doesn't have a main loop, for example). DownloadThe latest version of profiler.py is available from the Layer SVN repository. If you are using the whole Layer module, you can run the gprofiler command, or access it directly from the layer.xui.profiler module. This module has no dependencies outside of PyGTK and CPython's standard library. FeaturesMultiple Profiles: The Layer Profiler uses a tabbed interface that allows for opening and recording multiple profiles at the same time. Loading/Saving: You can save profiles to disk, and reimport them for browsing and comparing later. The original program is not required to browse saved profiles. The saved files are in the CPython marshal format. Filtering: Profiles can be filtered, using "foo" to match and "!foo" to exclude. Compare and Highlight: Compare two profiles, highlighting functions with significantly improved or degraded performance. UsagePygamePygame does not have a native main loop, so you will need to pump the GTK one yourself: import profiler
...
# To make a window appear
profiler.GProfiler().show()
...
# In your main loop
while not quit:
for event in pygame.event.get():
... # Do normal stuff here
profiler.update()pygletimport profiler # On startup (only necessary if you are not already running a GTK+ loop) profiler.pyglet() # To make a window appear profiler.GProfiler().show() GTK+# Before or during your GTK+ event loop, import profiler profiler.GProfiler().show() Standalone / Otherprofile.py can be used directly from the command line. # Load an existing profile $ python -mprofiler saved.profile $ python profiler.py saved.profile # Run a program and display a profile afterward (or interactively, # if the program runs a GTK+ main loop) $ python -mprofiler --execute myscript.py arg1 arg2 ... $ python profiler.py --e myscript.py arg1 arg2 ... |