wrappers push/pull stats
"Samuele Pedroni" <[email protected]>
| Newsgroups | gmane.comp.python.anygui.devel |
|---|---|
| Message-ID | <01ac01c25933$3700d200$6d94fea9@newmexico> |
[playing with the code]
With the following patch it is possible to get statistics about the arguments
to wrapper.push/pull
(to get the results a anygui.Wrappers._end_stats(outfile/sys.stdout) should be
put at the end of program after app.run())
I have tried it with test_textfield after the wrapper attribute fix (results
attached; before wrapper was the most pulled
attribute <wink>). The counts are for display construction plus a resize.
Maybe Frame.contents should be made (if possible) a plain attribute like
proxy.wrapper.
Apart from profiling things (which is not what this patch do), I would say just
from looking at the code that memoizing the wrapper.getSetters and
wrapper.getGetters results could improve things. Apart from obviously reducing
if possible the pull/push numbers.
Anyway considering that (Am I correct ?) the code tries to be direct/natural vs
avoiding avoidable push/pull calls, the numbers
seem already quite OK.
Index: Wrappers.py
===================================================================
RCS file: /cvsroot/anygui/anygui/lib/anygui/Wrappers.py,v
retrieving revision 1.35
diff -u -r1.35 Wrappers.py
--- Wrappers.py 10 Sep 2002 20:17:20 -0000 1.35
+++ Wrappers.py 11 Sep 2002 00:58:52 -0000
@@ -43,6 +43,41 @@
## # perhaps def __nonzero__(self): return 0
##
+
+_stats_data = {}
+
+_sort = lambda x,y: cmp(y[1],x[1])
+
+def _per_op(op,data,f):
+ print >>f,"**",op
+ single,aggr = data[op]
+ aggr = aggr.items()
+ single = single.items()
+ aggr.sort(_sort)
+ single.sort(_sort)
+ print >>f,"* aggr stats, %s distinct" % len(aggr)
+ print >>f,aggr
+ print >>f,"* single totals"
+ print >>f,single
+
+def _end_stats(f):
+ for cl in _stats_data.keys():
+ data = _stats_data[cl]
+ print >>f,"***",cl.__name__,"***"
+ _per_op('PUSH',data,f)
+ _per_op('PULL',data,f)
+ f.flush()
+
+def _stats(op,obj,names):
+ cl = obj.__class__
+ names = tuple(names)
+ data = _stats_data.setdefault(cl,{})
+ single,aggr = data.setdefault(op,({},{}))
+ aggr[names] = aggr.get(names,0) + 1
+ for name in names:
+ single[name] = single.get(name,0) + 1
+
+
class AbstractWrapper:
"""
@@ -214,6 +249,9 @@
method are ignored.
"""
# Use self.dependencies -- document it
+
+ _stats('PUSH',self,state.keys()) # @@@ debug/stats
+
setters, unhandled = self.getSetters(state.keys())
for setter, params in setters:
kwds = {}
@@ -287,6 +325,9 @@
methods. We may not, however, add keys to state, as that
could lead to unexpected changes to the proxy's state.
"""
+
+ _stats('PULL',self,state.keys()) # @@@ debug/stats
+
getters,unhandled = self.getGetters(state.keys())
lstate = {}
STATS
(application/octet-stream, 3.2 KB) - not displayed