Skip to main content

A wrapper for some existing python profilers

Project description

coinstac python profiler

Profile your python code (includes code running using coinstac-simulator). This primarily uses pyinstrument profiler, but can also be extended to include other python profilers

Prerequisites

Python 3.6+
Other packages listed in Requirements.txt

Usage

NOTE: The code currently implements profiling based on pyinstrument profiler. Other profilier (such as cprofile) can be included based on requirements.

First way:

Use the following line above the method definition which needs to be profiled.

from coinstac_pyprofiler import custom_profiler as cprof
@cprof.profile(type="pyinstrument", output_file_prefix=output_file_prefix)

Decorator class to profile any method. Note: 'output_file_prefix' should include its (absolute) directory path

Second way:

Create object of Profile class in custom_profiler.py and use start() and stop() methods to control profiling.

from coinstac_pyprofiler import custom_profiler as cprof
@cprof.profile(type="pyinstrument", output_file_prefix=output_file_prefix)
profile = cprof.Profile(type='pyinstrument',  output_file_prefix=<your_dir_path>/<some_file_prefix>")
profile.start()
<your code to profile>
profile.stop()
profile.persist_log()

Merging multiple profile output files

Merges the json profiler output files generated using pyinstrument profiling and saves merged output.

Use-case:

For a computation in coinstac-simulator, some computation has many iterations and every iteration of python call generates a separate profile json output file. All such json files can be merged separately for each client/remote using this call.

Example

An example usage is included in tests/examples/profiler_usage.py which demonstrates the usage of the above mentioned profiling methods and also provides examples to merge multiple profile output files.

Happy profiling!!

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

coinstac_pyprofiler-0.1.0.tar.gz (7.5 kB view hashes)

Uploaded Source

Built Distribution

coinstac_pyprofiler-0.1.0-py3-none-any.whl (11.9 kB view hashes)

Uploaded Python 3

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