Manual Profiling

Profiling Functions

See the Quick Start for instructions on installing and configuring the Graphsignal SDK.

The Graphsignal Python SDK allows profiling of specific functions to understand where time is being spent inside traced spans. Profiling can be enabled either by registering the function directly or by specifying the function via its import path.

Profiling is available in Python 3.12+.

Python

To profile a function, register it using profile_function() before the function is called:

def slow_transform(x):
    ...

graphsignal.profile_function(slow_transform, category='transform', event_name='data-transform')

slow_transform(data)

You can also profile methods and async functions:

class Worker:
    async def process(self):
        ...

graphsignal.profile_function(Worker.process)

You can also profile methods and async functions:

class Worker:
    async def process(self):
        ...

graphsignal.profile_function(Worker.process)

To avoid importing the function being profiled directly, or when applying profiling across modules, use profile_function_path():

graphsignal.profile_function_path('myapp.tasks.prepare_data', category='preprocessing')

The function referenced by the import path will be resolved at runtime and profiled whenever executed within a traced span.