No, as is, that will only wrap the function itself. However, you can 
explicitly execute the view and return the rendered HTML instead of the 
dictionary from the function:

def statsd(f):
    blah.start()
    result = f()
    if isinstance(result, dict):
        result = response.render(result)
    blah.stop()
    return result

response._caller = statsd

Only actions that return dictionaries have associated views executed, so 
the above checks whether the action returns a dictionary before attempting 
to render a view.

Anthony

On Thursday, December 17, 2015 at 4:31:49 AM UTC-5, Octavian G wrote:
>
> It works great ! Thanks. One question tho: it should include the time 
> spent rendering the html view, right ?
>
> On Wednesday, December 16, 2015 at 11:10:11 PM UTC+2, Anthony wrote:
>>
>> response._caller is a function that wraps all controller actions, so 
>> something like this might work:
>>
>> def statsd(f):
>>     blah.start()
>>     result = f()
>>     blah.stop()
>>     return result
>>
>> response._caller = statsd
>>
>> Anthony
>>
>> On Wednesday, December 16, 2015 at 2:49:25 PM UTC-5, Octavian G wrote:
>>>
>>> Hello,
>>>
>>>      I'd like to use statsd with my app. I'd like to time the execution 
>>> of a web2py function and various smaller pieces of code. The statsd doc (
>>> http://statsd.readthedocs.org/en/v3.2.1/reference.html#timer) says 
>>> their timer decorators are not threadsafe. This means I have to run a 
>>> bla.start() before the function and a bla.stop() after it.
>>>
>>>      So my questions are:
>>>
>>> 1. Are there any hooks for this ?
>>> 2. Are there any db query hooks for before and after the execution ?
>>> 3. Alternatively, what would be a proper way to time code execution in 
>>> web2py ?
>>>
>>

-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to