Module Debug
[hide private]
[frames] | no frames]

Source Code for Module Debug

  1  ##################################################################### 
  2  # -*- coding: iso-8859-1 -*-                                        # 
  3  #                                                                   # 
  4  # Frets on Fire                                                     # 
  5  # Copyright (C) 2006 Sami Kyöstilä                                  # 
  6  #                                                                   # 
  7  # This program is free software; you can redistribute it and/or     # 
  8  # modify it under the terms of the GNU General Public License       # 
  9  # as published by the Free Software Foundation; either version 2    # 
 10  # of the License, or (at your option) any later version.            # 
 11  #                                                                   # 
 12  # This program is distributed in the hope that it will be useful,   # 
 13  # but WITHOUT ANY WARRANTY; without even the implied warranty of    # 
 14  # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the     # 
 15  # GNU General Public License for more details.                      # 
 16  #                                                                   # 
 17  # You should have received a copy of the GNU General Public License # 
 18  # along with this program; if not, write to the Free Software       # 
 19  # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,        # 
 20  # MA  02110-1301, USA.                                              # 
 21  ##################################################################### 
 22   
 23  from OpenGL.GL import * 
 24  from View import Layer 
 25   
 26  import gc 
 27  import threading 
 28  import Log 
 29   
30 -class DebugLayer(Layer):
31 """A layer for showing some debug information."""
32 - def __init__(self, engine):
33 self.engine = engine
34 #gc.set_debug(gc.DEBUG_LEAK) 35
36 - def className(self, instance):
37 return str(instance.__class__).split(".")[1]
38
39 - def render(self, visibility, topMost):
40 self.engine.view.setOrthogonalProjection(normalize = True) 41 42 try: 43 font = self.engine.data.font 44 scale = 0.0008 45 glColor3f(.25, 1, .25) 46 47 x, y = (.05, .05) 48 h = font.getHeight() * scale 49 50 font.render("Tasks:", (x, y), scale = scale) 51 for task in self.engine.tasks + self.engine.frameTasks: 52 font.render(self.className(task), (x + .1, y), scale = scale) 53 y += h 54 55 x, y = (.5, .05) 56 font.render("Layers:", (x, y), scale = scale) 57 for layer in self.engine.view.layers + self.engine.view.incoming + self.engine.view.outgoing + self.engine.view.visibility.keys(): 58 font.render(self.className(layer), (x + .1, y), scale = scale) 59 y += h 60 61 x, y = (.05, .4) 62 font.render("Scenes:", (x, y), scale = scale) 63 if "world" in dir(self.engine.server): 64 for scene in self.engine.server.world.scenes: 65 font.render(self.className(scene), (x + .1, y), scale = scale) 66 y += h 67 68 x, y = (.5, .4) 69 font.render("Loaders:", (x, y), scale = scale) 70 for loader in self.engine.resource.loaders: 71 font.render(str(loader), (x + .1, y), scale = scale) 72 y += h 73 74 x, y = (.5, .55) 75 font.render("Input:", (x, y), scale = scale) 76 for listener in self.engine.input.mouseListeners + \ 77 self.engine.input.keyListeners + \ 78 self.engine.input.systemListeners + \ 79 self.engine.input.priorityKeyListeners: 80 font.render(self.className(listener), (x + .1, y), scale = scale) 81 y += h 82 83 x, y = (.05, .55) 84 font.render("System:", (x, y), scale = scale) 85 font.render("%d threads" % threading.activeCount(), (x + .1, y), scale = scale) 86 y += h 87 font.render("%.2f fps" % self.engine.timer.fpsEstimate, (x + .1, y), scale = scale) 88 y += h 89 font.render("%d sessions, server %s" % (len(self.engine.sessions), self.engine.server and "on" or "off"), (x + .1, y), scale = scale) 90 #y += h 91 #font.render("%d gc objects" % len(gc.get_objects()), (x + .1, y), scale = scale) 92 #y += h 93 #font.render("%d collected" % gc.collect(), (x + .1, y), scale = scale) 94 95 finally: 96 self.engine.view.resetProjection()
97
98 - def gcDump(self):
99 import World 100 before = len(gc.get_objects()) 101 coll = gc.collect() 102 after = len(gc.get_objects()) 103 Log.debug("%d GC objects collected, total %d -> %d." % (coll, before, after)) 104 fn = "gcdump.txt" 105 f = open(fn, "w") 106 n = 0 107 gc.collect() 108 for obj in gc.garbage: 109 try: 110 print >>f, obj 111 n += 1 112 except: 113 pass 114 f.close() 115 Log.debug("Wrote a dump of %d GC garbage objects to %s." % (n, fn))
116