How to Profile Komodo

Introduction

This document describes how to run various profiling services in Komodo. There are currently two ways to profile Komodo, each having strenghts and weakness. These are the javascript profiler, and the pyxpcom trace profiler.

Unfortunately no method to profile all of JavaScript and Python together is available, though generally if your profiling JavaScript, you will inadvertingly be profiling all calls that go through XPCOM (though you won't see the underlying Python/C++ functions).

JavaScript Profiler

Use the ko/profiler JS module. Profiles are dumped to your profile folder. To open them use Cleopatra.

To record named profiles you need to set the profilerEnabledName string pref.

To record unnamed profiles you need to first call require("ko/profiler").enable().

Profiling results are saved to the "profiler" folder within your Komodo profile folder.

Userscripts

For one off profiling you can use the following userscripts instead of the above:

Start JavaScript Profiler

require("ko/profiler").enable();
require("ko/profiler").start();

Stop JavaScript Profiler

require("ko/profiler").save();
require("ko/profiler").stop();

Python Profiler

You can profile python using cProfile

import cProfile
pr = cProfile.Profile()
pr.enable()
# MY CODE
pr.disable()
pr.dump_stats('/tmp/profiledump')

Userscript

This userscript will profile the next 10 seconds of execution, then save the result to /tmp/koprofile

import cProfile, signal
pr = cProfile.Profile()
pr.enable()

def whenDone(signum, frame):
    pr.disable()
    pr.dump_stats('/tmp/koprofile')
    signal.signal(signal.SIGALRM, signal.SIG_DFL)
    signal.setitimer(signal.ITIMER_REAL, 0)

signal.signal(signal.SIGALRM, whenDone)
signal.setitimer(signal.ITIMER_REAL,10)

Python Memory Profiler

  • Compile Meliae using Python 2.7.8 (UCS-2) and Cython (pyenv is a good tool for this).
  • Copy the compiled library to a path that Komodo's internal python process uses (print sys.path inside Komodo to find out)
  • Generate a dump with:
import meliae.scanner
meliae.scanner.dump_all_objects("/tmp/memorydump.json")

PyXPCOM Trace Profiling

To turn on the trace profiling, do::

export KO_PYXPCOM_PROFILE=1

This turns on the code profiler in python, and wraps all python xpcom objects in order to profile calls over xpcom. Upon shutting down Komodo, the profiler will print out a summary of the executed Python/XPCOM code.