ProfilerMiddleware
Warning
You need to install dependencies to use The Profiler.
$ pip install authx_extra[profiler]
ProfilerMiddleware(app, *, server_app=None, profiler_interval=0.0001, profiler_output_type='text', is_print_each_request=True, **profiler_kwargs)
PARAMETER | DESCRIPTION |
app | TYPE: ASGIApp |
server_app | TYPE: Optional[Router] DEFAULT: None |
profiler_interval | TYPE: float DEFAULT: 0.0001 |
profiler_output_type | TYPE: str DEFAULT: 'text' |
is_print_each_request | TYPE: bool DEFAULT: True |
**profiler_kwargs | DEFAULT: {} |
Source code in authx_extra/profiler.py
| def __init__(
self,
app: ASGIApp,
*,
server_app: Optional[Router] = None,
profiler_interval: float = 0.0001,
profiler_output_type: str = "text",
is_print_each_request: bool = True,
**profiler_kwargs,
):
self.app = app
self._profiler = Profiler(interval=profiler_interval)
self._server_app = server_app
self._output_type = profiler_output_type
self._print_each_request = is_print_each_request
self._profiler_kwargs: dict = profiler_kwargs
|
Source code in authx_extra/profiler.py
| async def get_result(self):
if self._output_type == "text":
print(self._profiler.output_text(**self._profiler_kwargs))
elif self._output_type == "html":
html_name = self._profiler_kwargs.get("html_file_name")
if html_name is None:
html_name = "authx_profiling_results.html"
html_code = renderers.HTMLRenderer().render(
session=self._profiler.last_session
)
with codecs.open(html_name, "w", "utf-8") as f:
f.write(html_code)
elif self._output_type == "json":
json_name = self._profiler_kwargs.get("json_file_name")
if json_name is None:
json_name = "authx_profiling_results.json"
json_code = renderers.JSONRenderer().render(
session=self._profiler.last_session
)
with codecs.open(json_name, "w", "utf-8") as f:
f.write(json_code)
|