10. Profiling

Coro code profiler.

10.1. 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.

10.2. Using The Profiler

There are two ways to run the profiler. One is to use the coro.profiler.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 coro.profiler.start() to start the profiler and coro.profiler.stop() when you want to stop profiling. This can be conveniently done from the backdoor.

10.3. 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.

10.4. 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.

coro.profiler.go(fun, *args, **kwargs)

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.
coro.profiler.start(profile_bench=<type 'coro._coro.rusage_bench'>)

Start the profiler.

Parameters :
  • profile_bench: The profiler type to use.
coro.profiler.stop(filename='/tmp/coro_profile.bin')

Stop the profiler.

Parameters :
  • filename: The filename to use for the profile output.

Table Of Contents

This Page