Skip to content

Commit

Permalink
Improve meminfo debug formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
vkbo committed Jun 8, 2024
1 parent a48fde9 commit ca91e6a
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 18 deletions.
4 changes: 2 additions & 2 deletions novelwriter/dialogs/preferences.py
Original file line number Diff line number Diff line change
Expand Up @@ -895,8 +895,8 @@ def _saveValues(self) -> None:
refreshTree = False

# Appearance
guiLocale = self.guiLocale.currentData()
guiTheme = self.guiTheme.currentData()
guiLocale = self.guiLocale.currentData()
guiTheme = self.guiTheme.currentData()

updateTheme |= CONFIG.guiTheme != guiTheme
needsRestart |= CONFIG.guiLocale != guiLocale
Expand Down
25 changes: 9 additions & 16 deletions novelwriter/gui/statusbar.py
Original file line number Diff line number Diff line change
Expand Up @@ -239,29 +239,22 @@ def memInfo(self) -> None: # pragma: no cover
"""
import tracemalloc

from collections import Counter

widgets = QApplication.allWidgets()
count = len(QApplication.allWidgets())
if not self._debugInfo:
if tracemalloc.is_tracing():
self._traceMallocRef = "Total"
else:
self._traceMallocRef = "Relative"
tracemalloc.start()
self._debugInfo = True
self._wCounts = Counter([type(x).__name__ for x in widgets])

if hasattr(self, "_wCounts"):
diff = Counter([type(x).__name__ for x in widgets]) - self._wCounts
for name, count in diff.items():
logger.debug("Widget '%s': +%d", name, count)

mem = tracemalloc.get_traced_memory()
current, peak = tracemalloc.get_traced_memory()
stamp = datetime.now().strftime("%H:%M:%S")
self.showMessage((
f"Debug [{stamp}]"
f" \u2013 Widgets: {len(widgets)}"
f" \u2013 {self._traceMallocRef} Memory: {mem[0]:n}"
f" \u2013 Peak: {mem[1]:n}"
), 6000)
message = (
f"Widgets: {count} \u2013 "
f"{self._traceMallocRef} Memory: {current/1024:,.2f} kiB \u2013 "
f"Peak: {peak/1024:,.2f} kiB"
)
self.showMessage(f"Debug [{stamp}] {message}", 6000)
logger.debug("[MEMINFO] %s", message)
return

0 comments on commit ca91e6a

Please sign in to comment.