Comment 6 for bug 691165

Revision history for this message
Andrew Bennetts (spiv) wrote : Re: [Bug 691165] Re: codehosting connection time is load dependent

John A Meinel wrote:
[...]
> How do you profile the twisted server, though?

It's just Python, which you know how to profile, so I guess you're
specifically asking how to profile something run via twistd(1)? Add
--profile=profile.stats (and maybe --profiler=cprofiler) to the twistd
invocation.

(If you're invoking reactor.run() directly for some reason, then
obviously you can just use the usual profiling APIs.)

Also, you could rig the process to enable/disable profiling when poked
by a signal or similar, regardless of how it was started. I think
something like this would work, but I haven't tested:

import cProfile, signal
profile = cProfile.Profile()
profiling = False
def toggle_profiler(*ignored):
    global profiling
    if not profiling:
       profile.enable()
    else:
       profile.disable()
       profile.dump_stats('/tmp/profile.stats')
signal.signal(signal.SIGUSR1, toggle_profiler)

Also, along the lines of Martin's suggestion, I'd expect “perf record
twistd ...” followed by “perf report” would probably show if a
significant proportion of the time is spent in crypto libraries, generic
Python, or something else entirely. (Conch uses PyCrypto, which should
be doing the hard work in C functions, unless somehow the packaging is
broken, which seems unlikely.)