147
by Ulrik Sverdrup
Add memory analysis in a new module "debug" |
1 |
"""
|
2 |
Debugging routines. To use this, simply import this module
|
|
3 |
"""
|
|
4 |
||
5 |
import atexit |
|
6 |
||
7 |
def mem_stats(): |
|
8 |
import gc |
|
148
by Ulrik Sverdrup
Move icon stats to debug module |
9 |
print "DEBUG: OBJ STATS" |
10 |
||
147
by Ulrik Sverdrup
Add memory analysis in a new module "debug" |
11 |
print "enabled:", gc.isenabled() |
12 |
print "objs", len(gc.get_objects()) |
|
13 |
print "collected (now)", gc.collect() |
|
14 |
||
15 |
# after collection
|
|
16 |
hist = {} |
|
17 |
for obj in gc.get_objects(): |
|
18 |
key = str(type(obj)) |
|
19 |
if key not in hist: |
|
20 |
hist[key] =1 |
|
21 |
else: |
|
22 |
hist[key] += 1 |
|
23 |
||
24 |
best = hist.items() |
|
25 |
best.sort(key=lambda x:x[1], reverse=True) |
|
26 |
print "\n".join("%s: %d" % (k,v) for k,v in best[:10]) |
|
27 |
||
28 |
our = [] |
|
151
by Ulrik Sverdrup
print gtk objects in debug output too |
29 |
gtk = [] |
147
by Ulrik Sverdrup
Add memory analysis in a new module "debug" |
30 |
for item in best: |
31 |
if "objects." in item[0] or "kupfer." in item[0]: |
|
32 |
our.append(item) |
|
151
by Ulrik Sverdrup
print gtk objects in debug output too |
33 |
if "gtk" in item[0]: |
34 |
gtk.append(item) |
|
147
by Ulrik Sverdrup
Add memory analysis in a new module "debug" |
35 |
|
151
by Ulrik Sverdrup
print gtk objects in debug output too |
36 |
print "---just gtk (top)" |
37 |
print "\n".join("%s: %d" % (k,v) for k,v in gtk[:10]) |
|
38 |
print "---Just our objects (all)" |
|
147
by Ulrik Sverdrup
Add memory analysis in a new module "debug" |
39 |
print "\n".join("%s: %d" % (k,v) for k,v in our) |
40 |
||
148
by Ulrik Sverdrup
Move icon stats to debug module |
41 |
def icon_stats(): |
227
by Ulrik Sverdrup
debug: correct kupfer import path |
42 |
from kupfer.icons import icon_cache |
148
by Ulrik Sverdrup
Move icon stats to debug module |
43 |
print "DEBUG: ICON STATS" |
44 |
||
45 |
c = 0 |
|
46 |
tot_acc = 0 |
|
47 |
tot_pix = 0 |
|
150
by Ulrik Sverdrup
Move icon functions to new module icons |
48 |
for k in icon_cache: |
49 |
rec = icon_cache[k] |
|
148
by Ulrik Sverdrup
Move icon stats to debug module |
50 |
acc = rec["accesses"] |
51 |
if not acc: |
|
52 |
c += 1 |
|
53 |
tot_acc += acc |
|
54 |
icon = rec["icon"] |
|
55 |
tot_pix += icon.get_height() * icon.get_width() |
|
150
by Ulrik Sverdrup
Move icon functions to new module icons |
56 |
print "Cached icons:", len(icon_cache) |
57 |
print "Unused cache entries", len(icon_cache) -c |
|
148
by Ulrik Sverdrup
Move icon stats to debug module |
58 |
print "Total accesses", tot_acc |
59 |
print "Sum pixels", tot_pix |
|
147
by Ulrik Sverdrup
Add memory analysis in a new module "debug" |
60 |
|
61 |
atexit.register(mem_stats) |
|
148
by Ulrik Sverdrup
Move icon stats to debug module |
62 |
atexit.register(icon_stats) |