Skip to content

A FastAPI Middleware with cProfile to help stats your service performance

License

Notifications You must be signed in to change notification settings

Jijun/fastapi-cprofile

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

About

A FastAPI Middleware with cProfile to help stats your service performance

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages