@Leonel you should make a PR of this. We have a program profiler, a memory profiler would be great!
@niplhod do you know if is there a way to integrate memory profiling in travis-ci?? Il giorno lunedì 2 febbraio 2015 00:35:50 UTC+1, Leonel Câmara ha scritto: > > If you have pool_size defined can you tell me if putting pool_size=0 in > your DAL solves this problem? > > Anyway I got really interested in this, for some unknown to me reason, and > decided to create a *VERY CRUDE* decorator to memory check your > controller functions for leaks, I guess with time we could refine this if > there's a desire to have a memory leak checker for controller functions in > web2py. I hope it helps, if it doesn't at least it was fun to code. > > > def memcheck(f): > """ > A crude decorator to memory check your web2py controller's functions. > > > False positives are possible if your controller function returns less > than > common stuff. > > > Put it in your models and then decorate your controller functions. > > > example: > > > @memcheck > def index(): > response.flash = T("Welcome to web2py!") > return dict(message=T('Hello World')) > > > BEERWARE - You should try to buy Leonel Câmara beers! > """ > from functools import wraps > from collections import Counter, Mapping, Iterable > from gluon.languages import lazyT > from gc import get_objects > > > def get_value_objects(v): > """ > Generate an object for each value in a value including itself. > """ > if isinstance(v, basestring): > yield v > elif isinstance(v, lazyT): > yield v > yield v.s # Check lazyT symbols dict > for i in v.s: > for new_v in get_value_objects(i): > yield new_v > elif isinstance(v, Mapping): > yield v > for i in v.values(): > for new_v in get_value_objects(i): > yield new_v > elif isinstance(v, Iterable): > yield v > for i in v: > for new_v in get_value_objects(i): > yield new_v > else: > yield v > > > @wraps(f) > def wrapper(*args, **kwargs): > before = Counter(type(obj) for obj in get_objects()) > result = f(*args, **kwargs) > after = Counter(type(obj) for obj in get_objects()) > result_objs = Counter(type(obj) for obj in get_value_objects( > result)) > count = after - before - result_objs - Counter([Counter]) > # This and other stuff put in the response or session is not a > memory > # leak. > # So false positives may appear for what's not accounted here. > if response.flash: > count -= Counter(type(obj) for obj in get_value_objects( > response.flash)) > if response.js: > count -= Counter(type(obj) for obj in get_value_objects( > response.js)) > > # Finally we are ready to report what we have found. > for k in count: > print 'LEAKED: %d of type %s' % (count[k], k) > return result > > > return wrapper > > > > -- 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 web2py+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.