Pyroscope Python Package
Pyroscope integration for Python
What is Pyroscope
Pyroscope is a tool that lets you continuously profile your applications to prevent and debug performance issues in your code. It consists of a low-overhead agent which sends data to the Pyroscope server which includes a custom-built storage engine. This allows for you to store and query any applications profiling data in an extremely efficient and cost effective way.
How to install Pyroscope for Python Applications
pip install pyroscope-io
Minimal Configuration
Add the following code to your application. This code will initialize pyroscope profiler and start profiling:
import pyroscope
pyroscope.configure(
application_name = "my.python.app",
server_address = "http://my-pyroscope-server:4040",
)
Full Configuration
Optionally, you can configure several parameters:
import pyroscope
pyroscope.configure(
application_name = "my.python.app",
server_address = "http://my-pyroscope-server:4040",
auth_token = "{YOUR_API_KEY}",
sample_rate = 100,
detect_subprocesses = False,
oncpu = True
gil_only = True
log_level = "info"
tags = {
"region": '{os.getenv("REGION")}',
}
)
Tags
You can add tags to certain parts of your code:
with pyroscope.tag_wrapper({ "controller": "slow_controller_i_want_to_profile" }):
slow_code()
Example
Check out this example python project in our repository for examples of how you can use these features.