Merge pull request #4682 from BerriAI/litellm_mem_leak_debug

show stack trace of 10 files taking up memory
This commit is contained in:
Ishaan Jaff 2024-07-12 18:31:41 -07:00 • committed by GitHub
commit 24918c5041
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -9,7 +9,7 @@ from litellm._logging import verbose_proxy_logger
router = APIRouter()
if os.environ.get("LITELLM_PROFILE", "false").lower() == "true":
tracemalloc.start()
tracemalloc.start(10)
@router.get("/memory-usage", include_in_schema=False)
async def memory_usage():
@ -22,7 +22,7 @@ if os.environ.get("LITELLM_PROFILE", "false").lower() == "true":
top_50 = top_stats[:50]
result = []
for stat in top_50:
result.append(f"{stat.traceback.format()}: {stat.size / 1024} KiB")
result.append(f"{stat.traceback.format(limit=10)}: {stat.size / 1024} KiB")
return {"top_50_memory_usage": result}