[Python-ideas] setprofile and settrace inconsistency
ironfroggy at gmail.com
Sat Jun 2 19:17:49 CEST 2012
On Fri, Jun 1, 2012 at 6:07 AM, Alon Horev <alon at horev.net> wrote:
> When setting a trace function with settrace, the trace function when called
> with a new scope can return another trace function or None, indicating the
> inner scope should not be traced.
> I used settrace for some time but calling the trace function for every line
> of code is a performance killer.
> So I moved on to setprofile, which calls a trace function every function
> entry/exit. now here's the problem: the return value from the trace function
> is ignored (intentionally), denying the possibility to skip tracing of 'hot'
> or 'not interesting' code.
> I would like to propose two alternatives:
> 1. setprofile will not ignore the return value and mimic settrace's
> 2. setprofile is just a wrapper around settrace that limits
> it's functionality, lets make settrace more flexible so setprofile will be
> redundant. here's how: settrace will recieve an argument called 'events',
> the trace function will fire only on events contained in that list. for
> example: setprofile = partial(settrace, events=['call', 'return'])
I particularly like the additional parameter for settrace().
> I personally prefer the second.
> Some context to this issue:
> I'm building a python tracer - a logger that records each and every function
> call. In order for it to run in production systems, the overhead should be
> minimal. I would like to allow the user to say which function/module/classes
> to trace or skip, for example: the user will skip all math/cpu intensive
> operations. another example: the user will want to trace his django app code
> but not the django framework.
> your thoughts?
> Thanks, Alon Horev
> Python-ideas mailing list
> Python-ideas at python.org
Read my blog! I depend on your acceptance of my opinion! I am interesting!
Follow me if you're into that sort of thing: http://www.twitter.com/ironfroggy
More information about the Python-ideas