Skip to content

Commit

Permalink
Fix ram tracer
Browse files Browse the repository at this point in the history
  • Loading branch information
melianmiko committed Sep 18, 2024
1 parent f7a8033 commit 0b863ea
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 10 deletions.
11 changes: 9 additions & 2 deletions openfreebuds_qt/utils/ram_trace/ram_trace_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,18 +28,25 @@ def start(self):
if self._task is None:
self._task = asyncio.create_task(self._mainloop())

def _write_trace(self):
data = [""]
for item in self.tracker.format_diff():
data.append(item)
log.warn("\n".join(data))

async def _mainloop(self):
process = psutil.Process()
await asyncio.sleep(15)
log.info("Start up RAM usage trace")
self.tracker.print_diff()
self._write_trace()

with suppress(asyncio.CancelledError):
log.info("Started")
while True:
current_usage = process.memory_info().rss
if current_usage > ram_exit:
log.error("RAM usage exceeded")
self._write_trace()
async with asyncio.Timeout(5):
await OfbQtReportTool(self.ctx).create_and_show()
log.error("Force exiting...")
Expand All @@ -49,6 +56,6 @@ async def _mainloop(self):
os.kill(os.getpid(), signal.SIGKILL)
elif current_usage > ram_warn and datetime.now() > self.last_print + timedelta(minutes=5):
log.warn(f"Too high ram usage, print trace info")
self.tracker.print_diff()
self._write_trace()
self.last_print = datetime.now()
await asyncio.sleep(10)
16 changes: 8 additions & 8 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 0b863ea

Please sign in to comment.