Skip to content

Commit

Permalink
fix error and new version for 1.4.1
Browse files Browse the repository at this point in the history
  • Loading branch information
sunhailin committed May 17, 2024
1 parent 49fa67d commit 1a343ea
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 14 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# ChangeLog

### version 1.4.1
* fix `AttributeError`[issue#17](https://github.com/sunhailin-Leo/fastapi_profiler/issues/17)

### version 1.4.0
* add support for speedscope

Expand Down
2 changes: 1 addition & 1 deletion fastapi_profiler/_version.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
__version__ = "1.4.0"
__version__ = "1.4.1"
__author__ = "sunhailin-Leo"
28 changes: 15 additions & 13 deletions fastapi_profiler/profiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,11 +128,11 @@ async def get_profiler_result(self):
output_filename=os.path.abspath(html_file_name),
)
else:
html_code = renderer.render(session=self._profiler.last_session)
with codecs.open(html_file_name, "w", "utf-8") as f:
f.write(html_code)

logger.info("Done writing profile to %r", html_file_name)
if self._profiler.last_session:
html_code = renderer.render(session=self._profiler.last_session)
with codecs.open(html_file_name, "w", "utf-8") as f:
f.write(html_code)
logger.info("Done writing profile to %r", html_file_name)
elif self._output_type == "prof":
prof_file_name = self.DEFAULT_PROF_FILENAME
if self._prof_file_name is not None:
Expand All @@ -155,10 +155,11 @@ async def get_profiler_result(self):
prof_file_name,
)

renderer = JSONRenderer()
with codecs.open(prof_file_name, "w", "utf-8") as f:
f.write(renderer.render(session=self._profiler.last_session))
logger.info("Done writing profile to %r", prof_file_name)
if self._profiler.last_session:
renderer = JSONRenderer()
with codecs.open(prof_file_name, "w", "utf-8") as f:
f.write(renderer.render(session=self._profiler.last_session))
logger.info("Done writing profile to %r", prof_file_name)
elif self._output_type == "speedscope":
prof_file_name = self.DEFAULT_SPEEDSCOPE_FILENAME
if self._prof_file_name is not None:
Expand All @@ -169,7 +170,8 @@ async def get_profiler_result(self):
prof_file_name,
)

renderer = SpeedscopeRenderer()
with codecs.open(prof_file_name, "w", "utf-8") as f:
f.write(renderer.render(session=self._profiler.last_session))
logger.info("Done writing profile to %r", prof_file_name)
if self._profiler.last_session:
renderer = SpeedscopeRenderer()
with codecs.open(prof_file_name, "w", "utf-8") as f:
f.write(renderer.render(session=self._profiler.last_session))
logger.info("Done writing profile to %r", prof_file_name)

0 comments on commit 1a343ea

Please sign in to comment.