Blueprint for pprof profiling endpoints a la GO's that can be added to python Flask applications. flask-pypprof is a wrapper of pypprof and based on django-pypprof ideas.
pip install flask-pypprof
To add the pprof endpoints to your application, simply register the blueprint:
from flask_pypprof import get_pprof_blueprint
app.register_blueprint(get_pprof_blueprint())
Once registered, you will be able to access the following endpoints:
/debug/pprof/profile
: will return a CPU profile/debug/pprof/heap
: will return a heap profile/debug/pprof/thread
: will return a thread profile/debug/pprof/wall
: will return a wall time profile(work in progress)
You can configure the memory sample rate by setting the following environment variable:
MEMORY_PROFILER_ENABLED
: enables the memory profiler (default: false)MEMORY_SAMPLE_RATE
: sets the memory profiling sample rate (default: 128 * 1024)
export MEMORY_PROFILER_ENABLED = false
export MEMORY_SAMPLE_RATE = 128 * 1024
Fetch a 30 seconds CPU profile:
go tool pprof -http=:8088 http://localhost:8081/debug/pprof/profile?seconds=30
Fetch a heap profile:
go tool pprof -http=:8088 http://localhost:8081/debug/pprof/heap
Python 3.8, 3.9, 3.10, 3.11 and Flask >= 2.0.0 and Linux only.
mprofile only works on linux/amd64 or at least linux/arm64 is not supported
. Also see timpalpant/mprofile#3.
This code base is available under the Apache License, version 2.