Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/jijun/fastapi-cprofile
A FastAPI Middleware with cProfile to help stats your service performance
https://github.com/jijun/fastapi-cprofile
cprofile fastapi
Last synced: 3 months ago
JSON representation
A FastAPI Middleware with cProfile to help stats your service performance
- Host: GitHub
- URL: https://github.com/jijun/fastapi-cprofile
- Owner: Jijun
- License: mit
- Created: 2020-12-25T08:32:41.000Z (about 4 years ago)
- Default Branch: main
- Last Pushed: 2023-08-21T13:48:05.000Z (over 1 year ago)
- Last Synced: 2024-01-30T13:51:12.518Z (about 1 year ago)
- Topics: cprofile, fastapi
- Language: Python
- Homepage:
- Size: 4.88 KB
- Stars: 32
- Watchers: 2
- Forks: 5
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# 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
- [x] support custom cprofile param
#Installation
```buildoutcfg
$ pip install fastapi-cprofile
```# Code Sample
```python
from fastapi_cprofile.profiler import CProfileMiddlewareapp = FastAPI()
app.add_middleware(CProfileMiddleware)
```
add cprofile options```python
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](https://github.com/jrfonseca/gprof2dot) to view it.```python
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