Merge pull request #4704 from BerriAI/litellm_debug_mem

[Debug-Utils] Add some useful memory usage debugging utils
This commit is contained in:
Ishaan Jaff 2024-07-13 18:44:40 -07:00 committed by GitHub
commit 4d7d6504b6
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -9,6 +9,19 @@ from litellm._logging import verbose_proxy_logger
router = APIRouter()
if os.environ.get("LITELLM_PROFILE", "false").lower() == "true":
try:
import objgraph
print("growth of objects") # noqa
objgraph.show_growth()
print("\n\nMost common types") # noqa
objgraph.show_most_common_types()
roots = objgraph.get_leaking_objects()
print("\n\nLeaking objects") # noqa
objgraph.show_most_common_types(objects=roots)
except:
pass
tracemalloc.start(10)
@router.get("/memory-usage", include_in_schema=False)