Skip to main content

A FastAPI Middleware with cProfile to stats your service performance.

Project description

fastapi-cprofile

A FastAPI Middleware with cProfile to help stats your service performance. cProfile is a built-in python module that can perform profiling. It is the most commonly used profiler currently.

Features

  • support custom cprofile param

#Installation

$ pip install fastapi-cprofile

Code Sample

from fastapi_cprofile.profiler import CProfileMiddleware

app = FastAPI()
app.add_middleware(CProfileMiddleware)

add cprofile options

from fastapi_cprofile.profiler import CProfileMiddleware
app = FastAPI()
app.add_middleware(CProfileMiddleware, enable=True, print_each_request = True, strip_dirs = False, sort_by='cumulative')

or dump out file while shutdown your app then you can use gprof2dot gprof2dot to view it.

from fastapi_cprofile.profiler import CProfileMiddleware
app = FastAPI()
app.add_middleware(CProfileMiddleware, enable=True, server_app = app, filename='/tmp/output.pstats', strip_dirs = False, sort_by='cumulative')

License

MIT

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

fastapi_cprofile-0.0.2.tar.gz (3.7 kB view hashes)

Uploaded Source

Built Distribution

fastapi_cprofile-0.0.2-py3-none-any.whl (4.1 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