Skip to content

Commit

Permalink
Merge pull request #355 from Lujeni/docs/guide_fastapi
Browse files Browse the repository at this point in the history
docs(guide): complete FastAPI example
  • Loading branch information
joerick authored Jan 1, 2025
2 parents bb015ba + 862b9ad commit 1ca0962
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions docs/guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,8 @@ app is the name of your FastAPI application instance.
Make sure you configure a setting to only make this available when required.

```python
from fastapi import Request
from fastapi.responses import HTMLResponse
from pyinstrument import Profiler


Expand All @@ -239,7 +241,7 @@ if PROFILING:
async def profile_request(request: Request, call_next):
profiling = request.query_params.get("profile", False)
if profiling:
profiler = Profiler(interval=settings.profiling_interval, async_mode="enabled")
profiler = Profiler()
profiler.start()
await call_next(request)
profiler.stop()
Expand Down Expand Up @@ -345,7 +347,6 @@ app = Litestar(

To invoke, make any request to your application and it will return the HTML result from pyinstrument instead of your application's response.


## Profile Pytest tests

Pyinstrument can be invoked via the command-line to run pytest, giving you a
Expand Down

0 comments on commit 1ca0962

Please sign in to comment.