[MERGE] lsprof branch

John Arbash Meinel john at arbash-meinel.com
Tue Jun 20 05:15:15 BST 2006


Robey Pointer wrote:
> 
> On 18 Jun 2006, at 16:02, John Arbash Meinel wrote:
> 
>> Robey Pointer wrote:
>>> With all the profiling and performance work being done, I thought it'd
>>> be a good time to point out the lsprof branch again.  Since I haven't
>>> needed to change it in a long time (except to merge bzr.dev), it'd be
>>> nice to have it merged and not have to keep it up to date anymore.
>>>
>>> The branch lives here:
>>>     http://www.lag.net/~robey/code/bzr.dev.lsprof
>>>
>>> robey
>>
>> Can you give us a reminder about what the major changes are? I see
>> something about doing threaded profiling, and something about Calltree
>> and various filtering.
> 
> I don't remember offhand, but I think I can piece it together from the
> log entries (wow, this stuff dates from February!).
> 
> Btw, the 'bzr status' display of pending merges kicks ass.  I never
> noticed that before.
> 
> It looks like some of the patches have already made it in.  All that's
> left is:
> 
> * patch from ddaa to add kcachegrind output-format support to lsprof 
> [this is the _CallTreeFilter stuff]
> * add threading support -- each thread created during an lsprof session
> gets its own profile object, and the Stats objects are attached to a
> 'threads' member of the final Stats object

So how do you actually generate Calltree style output? I don't see any
options to bzr to actually generate it.
So I figured I would use '--lsprof-file' to generate a pickle, and then
read that back in.

But with the latest bzr.dev I have the problem that cPickle fails,
because it can't serialize a 'code'.

bzr: ERROR: cPickle.PicklingError: Can't pickle <type 'code'>: attribute
lookup __builtin__.code failed
  at /home/jameinel/dev/bzr/bzr.dev/bzrlib/commands.py line 537
  in apply_lsprofiled

Now, I can see in 'Stats' that the method 'freeze()' claims to convert
'code' entries into string descriptions.

This patch seems to fix it for me:
=== modified file 'bzrlib/lsprof.py'
--- bzrlib/lsprof.py    2006-06-18 23:57:22 +0000
+++ bzrlib/lsprof.py    2006-06-20 04:07:53 +0000
@@ -92,11 +92,11 @@
             e = self.data[i]
             if not isinstance(e.code, str):
                 self.data[i] = type(e)((label(e.code),) + e[1:])
-                if e.calls:
-                    for j in range(len(e.calls)):
-                        se = e.calls[j]
-                        if not isinstance(se.code, str):
-                            e.calls[j] = type(se)((label(se.code),) +
se[1:])
+            if e.calls:
+                for j in range(len(e.calls)):
+                    se = e.calls[j]
+                    if not isinstance(se.code, str):
+                        e.calls[j] = type(se)((label(se.code),) + se[1:])
         for s in self.threads.values():
             s.freeze()

(Sorry about the inline patch line wrapping, but basically it is just
fixing the indentation for if e.calls:).

However, even after fixing that bug, if I serialized out the Stats
object, and then read it back in with cPickle, I get:

>>> s.calltree(open(',,calltree', 'wb'))
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
  File "bzrlib/lsprof.py", line 105, in calltree
    _CallTreeFilter(self.data).output(file)
  File "bzrlib/lsprof.py", line 119, in output
    self._entry(entry)
  File "bzrlib/lsprof.py", line 133, in _entry
    print >> out_file, 'fi=%s' % (code.co_filename,)
AttributeError: 'str' object has no attribute 'co_filename'

So because everything was frozen so that you could pickle it, you can't
read it back in and create the call tree.

Also, why doesn't running './bzr --lsprof-file foo root' actually run
lsprof. It would seem like giving it an output file should be sufficient
for enabling the profiling.

So, there are a few things for you to do in your branch:

1) Clean up lsprof so that we can pickle again
2) Enable opt_lsprof if opt_lsprof_file is set.
3) Figure out a way to enable cachegrind output. Perhaps with an env
flag, perhaps with another command line argument (I don't really like this).

I wanted to see what KCachegrind has to say, but so far its all broken.

John
=:->


-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 254 bytes
Desc: OpenPGP digital signature
Url : https://lists.ubuntu.com/archives/bazaar/attachments/20060619/5fef3e39/attachment.pgp 


More information about the bazaar mailing list