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: about 1 year 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 (over 5 years ago)
- Default Branch: main
- Last Pushed: 2023-08-21T13:48:05.000Z (almost 3 years ago)
- Last Synced: 2025-04-30T18:19:27.090Z (about 1 year ago)
- Topics: cprofile, fastapi
- Language: Python
- Homepage:
- Size: 4.88 KB
- Stars: 42
- Watchers: 1
- Forks: 7
- 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 CProfileMiddleware
app = 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