-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #13 from msnidal/feature/dot-prof-support
Implement .prof output
- Loading branch information
Showing
5 changed files
with
112 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -127,3 +127,7 @@ dmypy.json | |
|
||
# Pyre type checker | ||
.pyre/ | ||
|
||
# Profiler outputs | ||
*.prof | ||
*.html |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
""" | ||
This example shows how to output the profile | ||
to a .prof file. | ||
""" | ||
import os | ||
import uvicorn | ||
|
||
from fastapi import FastAPI | ||
from fastapi.responses import JSONResponse | ||
|
||
from fastapi_profiler import PyInstrumentProfilerMiddleware | ||
|
||
|
||
app = FastAPI() | ||
app.add_middleware( | ||
PyInstrumentProfilerMiddleware, | ||
server_app=app, # Required to output the profile on server shutdown | ||
profiler_output_type="prof", | ||
is_print_each_request=False, # Set to True to show request profile on | ||
# stdout on each request | ||
prof_file_name="example_profile.prof", # Filename for output | ||
) | ||
|
||
|
||
@app.get("/test") | ||
async def normal_request(): | ||
return JSONResponse({"retMsg": "Hello World!"}) | ||
|
||
|
||
# Or you can use the console with command "uvicorn" to run this example. | ||
# Command: uvicorn fastapi_example:app --host="0.0.0.0" --port=8080 | ||
if __name__ == "__main__": | ||
app_name = os.path.basename(__file__).replace(".py", "") | ||
uvicorn.run(app=f"{app_name}:app", host="0.0.0.0", port=8080, workers=1) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
starlette | ||
uvicorn |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters