Development Team/Performance

From Sugar Labs
< Development Team
Revision as of 21:33, 23 February 2010 by Patrol (talk | contribs) (moved Walter is a wanker 12/Performance to Development Team/Performance over redirect: revert)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

Just a quick dump of the snippets I use for profiling:

First use a system-wide profiler like sysprof

Next, profile python code, open the output with kcachegrind:

import os
import cProfile
import lsprofcalltree  #

profiler = cProfile.Profile()

### code to profile ### 


k = lsprofcalltree.KCacheGrind(profiler)
data = open('/tmp/import.kgrind', 'w+')

Check for leaks:

        import gobject
        gobject.timeout_add(10000, self._log_mem_usage) 

    def _log_mem_usage(self): 
        import analysis, os, gc 
        for obj in gc.get_objects():
            if hasattr(obj, '__class__') and 'ChooserListView' in obj.__class__.__name__:

        for i in range(0, 10):
        logging.debug('mem: %i' % analysis.Analysis(os.getpid()).ApproxRealMemoryUsage()) 
        return True 

Rendering time of a widget/window:

    def do_expose_event(self, event):
        import time
        t = time.time()
        hippo.Canvas.do_expose_event(self, event)
        logging.debug('listview expose event: %r' % (time.time() - t))