Merge lp://staging/~gary/launchpad/profiler into lp://staging/launchpad

Proposed by Gary Poster
Status: Merged
Approved by: Gary Poster
Approved revision: no longer in the source branch.
Merged at revision: 13672
Proposed branch: lp://staging/~gary/launchpad/profiler
Merge into: lp://staging/launchpad
Diff against target: 1007 lines (+385/-209)
4 files modified
lib/lp/services/profile/__init__.py (+15/-2)
lib/lp/services/profile/profile.pt (+45/-14)
lib/lp/services/profile/profile.py (+162/-82)
lib/lp/services/profile/tests.py (+163/-111)
To merge this branch: bzr merge lp://staging/~gary/launchpad/profiler
Reviewer Review Type Date Requested Status
Robert Collins (community) Needs Information
Gavin Panella (community) Approve
Review via email: mp+71192@code.staging.launchpad.net

Commit message

[r=allenap][bug=824632] Add ability to profile parts of a request, aggregated if they repeat.

Description of the change

In the course of trying to figure out how best to fix bug 724025 (a timeout bug involving Python rather than SQL) I made more tweaks to the ++profile++ tool. These changes do three things.

1) Make it possible to insert profile requests within the code, using the "profiling" context manager or the "start"/"stop" calls. Multiple calls within a request are aggregated.
2) Make it possible to ask for both callgrind and pstats simultaneously. This was not that important to me, but fell out of the refactoring I was doing.
3) Make the in-browser "show" functionality use the pstats rendering, because I liked it better (it gave aggregate time, for one thing).

Along the way, I simplified some tests by abstracting out assertion helpers, and I removed some hacks to use the BzrProfiler itself and simplified the code by using only the Bzr Stats class when we need to write callgrind files.

lint is happy except for its usual confusion with profile.pt.

./lib/lp/services/profile/profile.pt
       6: junk after document element

I'm sorry for the extra size of the branch.

Thank you!

Gary

To post a comment you must log in.
Revision history for this message
Gavin Panella (allenap) wrote :

I'd never played with this before, and now I'm very glad I have.

[1]

+ self.__class__.profiler_lock.acquire(True) # Blocks.

Is there a reason you chose to refer to profiler_lock via
self.__class__ rather than self?

[2]

+ actions = getattr(_profilers, 'actions', None)
+ profiler = getattr(_profilers, 'profiler', None)

Btw, instead of lots of guard code around using _profilers, it's
possible to subclass and get a ordinary looking object:

    class Profilers(threading.local):

        def __init__(self):
            self.profiling = False
            self.actions = None
            self.profiler = None
            self.profiling = False
            # ...

    _profilers = Profilers()

__init__() gets called once for each new thread the instance is used
in, and the class can have methods and properties as usual. Might be
interesting.

Fwiw, I verified this to myself with http://paste.ubuntu.com/663456/

review: Approve
Revision history for this message
Gary Poster (gary) wrote :

I made all changes Gavin suggested.

QA: simply make sure that https://qastaging.launchpad.net/++profile++show still seems to work, as a smoke test.

Revision history for this message
Robert Collins (lifeless) wrote :

Uhm so the reason I used the bzr profiler was *precisely* the threading behaviour - we have stuff that runs off in threads (like the google search calls), and relatedly I wanted to lock other threads out to ensure we got a good read - only one request active - when profiling.

Could we not just fix bzr to do what you need, given the closeness of the projects?

review: Needs Information
Revision history for this message
Gary Poster (gary) wrote :

On Aug 11, 2011, at 11:02 PM, Robert Collins wrote:

> Review: Needs Information
> Uhm so the reason I used the bzr profiler was *precisely* the threading behaviour - we have stuff that runs off in threads (like the google search calls), and relatedly I wanted to lock other threads out to ensure we got a good read - only one request active - when profiling.

This is maintained: I kept the blocking behavior.

> Could we not just fix bzr to do what you need, given the closeness of the projects?

It would be possible. I don't see an advantage at all until we are happy with the profiler work; and even then, upstream inclusion, no matter how friendly, takes time and involves a different perspective.

If for some reason you want to use the exact lock from the bzr profiler, that would be easy enough to maintain, as I did in a previous branch. However, it is simpler to understand the code if we define the lock locally, as I did here.

Revision history for this message
Robert Collins (lifeless) wrote :

On Wed, Aug 17, 2011 at 12:19 AM, Gary Poster <email address hidden> wrote:
>
> On Aug 11, 2011, at 11:02 PM, Robert Collins wrote:
>
>> Review: Needs Information
>> Uhm so the reason I used the bzr profiler was *precisely* the threading behaviour - we have stuff that runs off in threads (like the google search calls), and relatedly I wanted to lock other threads out to ensure we got a good read - only one request active - when profiling.
>
> This is maintained: I kept the blocking behavior.

Cool, thanks, and thanks for explaining.

>> Could we not just fix bzr to do what you need, given the closeness of the projects?
>
> It would be possible.  I don't see an advantage at all until we are happy with the profiler work; and even then, upstream inclusion, no matter how friendly, takes time and involves a different perspective.
>
> If for some reason you want to use the exact lock from the bzr profiler, that would be easy enough to maintain, as I did in a previous branch.  However, it is simpler to understand the code if we define the lock locally, as I did here.

Well, its a little sad to have two different implementations floating
around, is all.

-Rob

Revision history for this message
Gary Poster (gary) wrote :

On Aug 16, 2011, at 8:31 AM, Robert Collins wrote:

> On Wed, Aug 17, 2011 at 12:19 AM, Gary Poster <email address hidden> wrote:
>>
>> On Aug 11, 2011, at 11:02 PM, Robert Collins wrote:

...

>>> Could we not just fix bzr to do what you need, given the closeness of the projects?
>>
>> It would be possible. I don't see an advantage at all until we are happy with the profiler work; and even then, upstream inclusion, no matter how friendly, takes time and involves a different perspective.
>>
>> If for some reason you want to use the exact lock from the bzr profiler, that would be easy enough to maintain, as I did in a previous branch. However, it is simpler to understand the code if we define the lock locally, as I did here.
>
> Well, its a little sad to have two different implementations floating
> around, is all.

True. It would be fun to contribute to bzr. Maybe I'll get around to it. I'd want to try to change things around a bit if it were going upstream: reuse often leads me to different designs than refactoring.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
The diff is not available at this time. You can reload the page or download it.