r0u*_*u1i 3 python garbage-collection
我有一个python应用程序有一些性能打嗝.我想将垃圾收集器的事件(特别是何时被调用)添加到我的日志中.可能吗?
谢谢.
http://docs.python.org/library/gc.html#gc.set_debug
你可以设置Flags,但是它们会被写入stderr.
可用的标志是
gc.DEBUG_STATS
gc.DEBUG_COLLECTABLE
gc.DEBUG_UNCOLLECTABLE
gc.DEBUG_INSTANCES
gc.DEBUG_OBJECTS
gc.DEBUG_SAVEALL
gc.DEBUG_LEAK
Run Code Online (Sandbox Code Playgroud)
也
在处理性能时,您可能希望对代码进行详尽的循环或函数调用.你可以使用cProfile或hotshot.更多这里http://docs.python.org/library/profile.html