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 #11 from rgeoghegan/fix-html-mode
Fix html mode; move PyInstrumentProfilerMiddleware to top-level module
- Loading branch information
Showing
7 changed files
with
87 additions
and
44 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
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,36 @@ | ||
""" | ||
This example shows how to output the profile | ||
to an html 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="html", | ||
is_print_each_request=False, # Set to True to show request profile on | ||
# stdout on each request | ||
open_in_browser=False, # Set to true to open your web-browser automatically | ||
# when the server shuts down | ||
html_file_name="example_profile.html" # 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 |
---|---|---|
@@ -1,2 +1,2 @@ | ||
from fastapi_profiler import profiler_middleware | ||
from fastapi_profiler._version import __author__, __version__ | ||
from ._version import __version__, __author__ | ||
from .profiler import PyInstrumentProfilerMiddleware |
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 |
---|---|---|
@@ -1,2 +1,2 @@ | ||
__version__ = "1.0.0" | ||
__version__ = "2.0.0" | ||
__author__ = "sunhailin-Leo" |
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 was deleted.
Oops, something went wrong.
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