This is my 2nd day at OSAF and Katie suggested a good way to get started would be to take on a bug. She gave me Bug:2322
, dealing with the performance of deleting an item from Chandler.
I found some interesting pages such as PerformanceProject
, which addresses some performance issues, and talks a little bit about how to use HotShot
. The docs were sparse so I'm trying to make it really easy to run the profiler and do an analysis.
My first goal was to add Start/Stop profiler menu items to the Test menu. That got me learning all about the Repository
as well as the ParcelManager
To add a menu item, I had to perform the following steps:
- Add some stuff to parcels/osaf/views/main/parcel.xml:
- add MenuItems for StartHotshotItem and StopHotshotItem that generate appropriate events with the event tag
- add two childrenBlocks to the TestMenu menu with itemref="doc:StartHotshotItem"
- add childrenBlocks for each of these MenuItems
- Add some events to parcels/osaf/views/main/Main.py:
- define onStartHotshotEvent to handle the StartHotshotEvent and so forth
- Add a global to application/Globals.py to keep track of the reference to hotshot - so that it can be created when the user starts the profiler, and is still around when the user goes to stop the profiler
The start/stop seemed straightforward enough - just call profiler.start() and profiler.stop(). The problem is that the very next thing that happens after a start() is a return on the callstack, and this is exactly what gets written out to the profile log file. Then if you're later trying to analyze the profile by running hotshot.stats, the loader fails to load it because it tries to pop the most recent call off the stack for analysis and the stack is empty. After some googling, I found this document in this Sourceforge Bug
So my next solution is to be to instantiate the profiler when the user clicks start, and then sometime in the event loop, I can check if the profiler exists. If it does, then it can be started at a really low level. Hopefully it can be stopped at anytime, leaving a half-returned stack in the profile file.