[Zope] ZopeProfiler and Kcachegrind, how to convert statistics files ?
Jean-Michel FRANCOIS
jeanmichel.francois at makina-corpus.com
Thu Jan 29 11:20:26 EST 2009
It's done, i m now able to use KCachegrind with ZopeProfiler. I have
patched pyprof2calltree to work with python2.4:
diff -U 3 -H -d -r -N --
pyprof2calltree-1.1.0-py2.4.egg/pyprof2calltree.py
pyprof2calltree-1.1.0-py2.4.egg.NEW//pyprof2calltree.py
--- pyprof2calltree-1.1.0-py2.4.egg/pyprof2calltree.py 2008-12-21
19:14:42.000000000 +0100
+++ pyprof2calltree-1.1.0-py2.4.egg.NEW//pyprof2calltree.py
2009-01-29 17:15:05.000000000 +0100
@@ -26,7 +26,18 @@
take a previously recorded instance of the pstats.Stats class.
"""
-import cProfile
+try:
+ import cProfile
+except ImportError:
+ #BBB for python2.4
+ import profile as cProfile
+ def label(code):
+ if isinstance(code, str):
+ return ('~', 0, code) # built-in functions ('~' sorts at
the end)
+ else:
+ return (code.co_filename, code.co_firstlineno, code.co_name)
+ cProfile.label = label
+
import pstats
import optparse
import os
But something don't work : the call_info variable is not a sequence but
a integer, so i have fixed it like that:
@@ -175,9 +186,9 @@
print >> out_file, 'cfn=%s %s:%d' % (
co_name, co_filename, co_firstlineno)
print >> out_file, 'cfi=%s' % (co_filename,)
- print >> out_file, 'calls=%d %d' % (call_info[0], co_firstlineno)
+ print >> out_file, 'calls=%d %d' % (call_info, co_firstlineno)
- totaltime = int(call_info[3] * 1000)
+ totaltime = int(call_info * 1000)
print >> out_file, '%d %d' % (lineno, totaltime)
def main():
Jean-Michel FRANCOIS a écrit :
> Dieter Maurer a écrit :
>
>> Jean-Michel FRANCOIS wrote at 2009-1-28 16:56 +0100:
>>
>>
>>> Is someone has try to use ZopeProfiler with KCacheGrind ? I would like
>>> to try KCachegrind because i found xdot very slow.
>>>
>>> I have started to read the code of ZopeProfiler and i have discovered
>>> the world of profiling file format. It seems that ZopeProfiler save it's
>>> file in pstats format. So i need to convert those file to calltree
>>> format. But all scripts i have tryed has failed:
>>>
>>> * pyprof2calltree
>>> * lsprofcalltree.py
>>> * hotshot2calltree
>>>
>>> So am i on the wrong way ? Do i need to fix one of these script ? Are
>>> you using on of them ?
>>>
>>>
>> You could try "pyprof2calltree" from the Python interpreter in
>> the following way:
>>
>> from marshal import load
>> from pyprof2calltree import visualize # or convert
>> stats = load(open(name_of_saved_file, 'rb'))
>> visualize(stats)
>>
>>
>> Not sure whether it will work (it probably will when "pyprof2calltree" does
>> not expect a more modern 'pstats' format).
>>
>>
>>
>>
>>
> I have try this one. First issue, it assume you are using a Python2.5
> (cProfile is new in Python2.5 but assume the same API) so i have change
> the import
>
> import profile as cProfile
>
> Now got a new problem when trying visualize:
>
>
>>>> visualize(stats)
>>>>
> Traceback (most recent call last):
> File "<stdin>", line 1, in ?
> File
> "/home/toutpt/temp/profiling/lib/python2.4/site-packages/pyprof2calltree-1.1.0-py2.4.egg/pyprof2calltree.py",
> line 256, in visualize
> converter = CalltreeConverter(profiling_data)
> File
> "/home/toutpt/temp/profiling/lib/python2.4/site-packages/pyprof2calltree-1.1.0-py2.4.egg/pyprof2calltree.py",
> line 117, in visualize
> self.output(f)
> File
> "/home/toutpt/temp/profiling/lib/python2.4/site-packages/pyprof2calltree-1.1.0-py2.4.egg/pyprof2calltree.py",
> line 104, in output
> self._print_summary()
> File
> "/home/toutpt/temp/profiling/lib/python2.4/site-packages/pyprof2calltree-1.1.0-py2.4.egg/pyprof2calltree.py",
> line 134, in _print_summary
> print entry
> AttributeError: 'tuple' object has no attribute 'totaltime'
>
>
> _______________________________________________
> Zope maillist - Zope at zope.org
> http://mail.zope.org/mailman/listinfo/zope
> ** No cross posts or HTML encoding! **
> (Related lists -
> http://mail.zope.org/mailman/listinfo/zope-announce
> http://mail.zope.org/mailman/listinfo/zope-dev )
>
More information about the Zope
mailing list