Python

Supported platforms#

LinuxmacOSWindowsDocker

Profiling Python applications#

First, install pyroscope-io pip package:

pip install pyroscope-io

Basic Configuration#

Add the following code to your application. This code will initialize pyroscope profiler and start profiling:

import pyroscope
pyroscope.configure(  app_name       = "my.python.app", # replace this with some name for your application  server_address = "http://my-pyroscope-server:4040", # replace this with the address of your pyroscope server)

Tags#

Pyroscope python integration provides a number of ways to tag profiling data. For example, you can provide tags when you're initializing the profiler:

import osimport pyroscope
pyroscope.configure(  app_name       = "simple.python.app",  server_address = "http://my-pyroscope-server:4040",
  tags = {    "hostname": os.getenv("HOSTNAME"),  })

or you can dynamically tag certain parts of your code:

# You can use a wrapper:with pyroscope.tag_wrapper({ "controller": "slow_controller_i_want_to_profile" }):  slow_code()
# Or you can add / remove tags manually:pyroscope.tag({ "controller": "slow_controller_i_want_to_profile" })slow_code()pyroscope.remove_tags("controller")

Example#

Check out this example python project in our repository for examples of how you can use these features.