Skip to main content

a Deferred profiler

Project description

https://travis-ci.org/habnabit/twisted-theseus.png

twisted-theseus

A Deferred-aware profiler for Python code.

While cProfile is a very useful utility, it is limited to recording synchronous execution time. A function that returns a Deferred will typically return very quickly, while the Deferred it returns might not fire for seconds or even minutes. This is where theseus comes in: any function that returns a Deferred will be tracked by theseus. The time from when the Deferred was returned to when it fired will be measured, and recorded along with the function’s call stack.

Usage

The public interface of theseus is a class called Tracer. To get started:

from theseus import Tracer
t = Tracer()
t.install()

This is enough to start tracing execution. Eventually, the statistics will have to be written to disk:

with open('callgrind.theseus', 'wb') as outfile:
  t.write_data(outfile)

The output is written in callgrind format, which means that standard tools can be used to interpret the results, such as kcachegrind.

Additionally, theseus is aware of inlineCallbacks, and will rewrite call stacks to make them look “correct”. For example, given this code:

from twisted.internet import defer, task

@defer.inlineCallbacks
def func(reactor):
  yield task.deferLater(reactor, 1, lambda: None)

task.react(func)

The call stack according to theseus will look like this (most recent call last):

__main__ in <module>
twisted.internet.task in react
__main__ in func

Because theseus uses a trace hook instead of a profile hook, it’s possible to have both cProfile and theseus enabled at the same time.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

twisted-theseus-0.14.0.0.tar.gz (5.9 kB view details)

Uploaded Source

File details

Details for the file twisted-theseus-0.14.0.0.tar.gz.

File metadata

File hashes

Hashes for twisted-theseus-0.14.0.0.tar.gz
Algorithm Hash digest
SHA256 4b40397aced1d81d9401083753a648355f81bcbab6ac1e32b129f50f34b13bb6
MD5 b43d60d9e5111b54b1edca62fc5b063c
BLAKE2b-256 2703d681ec2d98cddb2176afbae7231b7496b3e01d73e8deb23317ab0f0bcd40

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page