Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python: logging the garbage collector

I have a python application that has some performance hiccups. I want to add the garbage collector's events (especially, when does it get called) to my logs. Is it possible?

thanks.

like image 465
r0u1i Avatar asked Oct 25 '25 07:10

r0u1i


1 Answers

http://docs.python.org/library/gc.html#gc.set_debug

You can set the Flags, but they get written to stderr.

Available flags are

gc.DEBUG_STATS
gc.DEBUG_COLLECTABLE
gc.DEBUG_UNCOLLECTABLE
gc.DEBUG_INSTANCES
gc.DEBUG_OBJECTS
gc.DEBUG_SAVEALL
gc.DEBUG_LEAK

ALSO

When you are dealing with performance, you might wish to profile your code for exhaustive Loops or Function calls. You can use cProfile or hotshot. More here http://docs.python.org/library/profile.html

like image 64
meson10 Avatar answered Oct 27 '25 00:10

meson10