Package coro :: Module profiler
[hide private]
[frames] | no frames]

Module profiler

source code

Coro code profiler.

Introduction

This profiler is coro-aware. It produces output to a binary file on disk. You then use the coro.print_profile module to convert it to an HTML file.

Using The Profiler

There are two ways to run the profiler. One is to use the go function where you give it a python function to run. Profiling will start and call the function, and then the profiler will automatically stop when the function exits.

The other method is to call start to start the profiler and stop when you want to stop profiling. This can be conveniently done from the backdoor.

Rendering Output

Once you have profiler output, you must use the print_profile module to convert it to HTML. The typical method for doing this is:

python -m coro.print_profile /tmp/coro_profile.bin > my_profile.html

Then view the profile output in your web browser.

Profiler Types

The profiler supports different ways of gathering statistics. This is done by specifying the "bench" object to use (see go and start). They default to the "rusage" method of gathering statistics about every function call (see the getrusage man page for more detail). If you want a higher performance profile, you can use the coro.bench object instead which simply records TSC values for every function call. If you want to define your own method of gathering statistics, subclass coro.bench and implement your own techniques.

Functions [hide private]
 
_dump(p, filename) source code
 
go(fun, *args, **kwargs)
Start the profiler on a function.
source code
 
start(profile_bench=<type 'coro._coro.rusage_bench'>)
Start the profiler.
source code
 
stop(filename='/tmp/coro_profile.bin')
Stop the profiler.
source code
 
tak1(x, y, z) source code
 
tak2(x, y, z) source code
Variables [hide private]
  MAGIC = 'SHRAP_PROF1'
  __package__ = 'coro'
Function Details [hide private]

go(fun, *args, **kwargs)

source code 

Start the profiler on a function.

This will start the profiler, and then call the provided function. The profiler will shut down once the function returns.

Additional arguments provided are passed to the function.

This will display the results to stdout after the function is finished.

Parameters:
  • fun - : The function to call.
  • profile_filename - : The name of the file to save the profile data. Defaults to '/tmp/coro_profile.bin'.
  • profile_bench - : The bench object type to use. Defaults to coro.rusage_bench.

start(profile_bench=<type 'coro._coro.rusage_bench'>)

source code 
Start the profiler.
Parameters:
  • profile_bench - : The profiler type to use.

stop(filename='/tmp/coro_profile.bin')

source code 
Stop the profiler.
Parameters:
  • filename - : The filename to use for the profile output.